Class: Bixby::Provision::Base

Inherits:
Object
  • Object
show all
Extended by:
Log
Includes:
Log, Util::File, ScriptUtil
Defined in:
lib/bixby/provision/dsl/base.rb

Constant Summary collapse

PATH =
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::File

#chmod, #chown, #sha256sum, #which

Constructor Details

#initialize(obj = nil) ⇒ Base

Returns a new instance of Base.



18
19
20
21
22
23
# File 'lib/bixby/provision/dsl/base.rb', line 18

def initialize(obj=nil)
  if obj.kind_of? Base then
    @manifest = obj.manifest
    @proxy    = obj.proxy
  end
end

Instance Attribute Details

#manifestObject

Returns the value of attribute manifest.



16
17
18
# File 'lib/bixby/provision/dsl/base.rb', line 16

def manifest
  @manifest
end

#proxyObject

Returns the value of attribute proxy.



16
17
18
# File 'lib/bixby/provision/dsl/base.rb', line 16

def proxy
  @proxy
end

Instance Method Details

#get_gid(group) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/bixby/provision/dsl/base.rb', line 51

def get_gid(group)
  return group if group.nil? or group.kind_of? Fixnum
  return group.to_i if group =~ /^[0-9]+$/ # convert to int, e.g. "500"
  begin
    return Etc.getgrnam(group).gid
  rescue ArgumentError => ex
    # TODO raise
    logger.warn("Group '#{group}' was invalid: #{ex.message}")
  end
  nil
end

#get_group(gid) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/bixby/provision/dsl/base.rb', line 63

def get_group(gid)
  begin
    return Etc.getgrgid(gid).name
  rescue ArgumentError => ex
    # TODO raise
    logger.warn("Group '#{group}' was invalid: #{ex.message}")
  end
  nil
end

#get_uid(user) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/bixby/provision/dsl/base.rb', line 29

def get_uid(user)
  return user if user.nil? or user.kind_of? Fixnum
  return user.to_i if user =~ /^[0-9]+$/ # convert to int, e.g. "500"
  begin
    return Etc.getpwnam(user).uid
  rescue ArgumentError => ex
    # TODO raise
    logger.warn("Username '#{user}' was invalid: #{ex.message}")
  end
  nil
end

#get_user(uid) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/bixby/provision/dsl/base.rb', line 41

def get_user(uid)
  begin
    return Etc.getpwuid(uid).name
  rescue ArgumentError => ex
    # TODO raise
    logger.warn("Username '#{user}' was invalid: #{ex.message}")
  end
  nil
end

#tap(&block) ⇒ Object



25
26
27
# File 'lib/bixby/provision/dsl/base.rb', line 25

def tap(&block)
  self.instance_eval(&block)
end