Class: Vagabund::Squatter::User

Inherits:
Object
  • Object
show all
Defined in:
lib/vagabund/squatter/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#groupObject

Returns the value of attribute group.



4
5
6
# File 'lib/vagabund/squatter/user.rb', line 4

def group
  @group
end

#groupsObject

Returns the value of attribute groups.



4
5
6
# File 'lib/vagabund/squatter/user.rb', line 4

def groups
  @groups
end

#homeObject

Returns the value of attribute home.



4
5
6
# File 'lib/vagabund/squatter/user.rb', line 4

def home
  @home
end

#passwordObject

Returns the value of attribute password.



4
5
6
# File 'lib/vagabund/squatter/user.rb', line 4

def password
  @password
end

#public_keyObject

Returns the value of attribute public_key.



4
5
6
# File 'lib/vagabund/squatter/user.rb', line 4

def public_key
  @public_key
end

#shellObject

Returns the value of attribute shell.



4
5
6
# File 'lib/vagabund/squatter/user.rb', line 4

def shell
  @shell
end

#ssh_configObject

Returns the value of attribute ssh_config.



4
5
6
# File 'lib/vagabund/squatter/user.rb', line 4

def ssh_config
  @ssh_config
end

#sudoObject

Returns the value of attribute sudo.



4
5
6
# File 'lib/vagabund/squatter/user.rb', line 4

def sudo
  @sudo
end

#usernameObject

Returns the value of attribute username.



4
5
6
# File 'lib/vagabund/squatter/user.rb', line 4

def username
  @username
end

Instance Method Details

#create?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/vagabund/squatter/user.rb', line 44

def create?
  !username.nil?
end

#pubkeysObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/vagabund/squatter/user.rb', line 14

def pubkeys
  unless @public_key.nil?
    [@public_key].flatten.map do |pubkey|
      begin
        File.read(File.expand_path(pubkey)).chomp
      rescue Exception => e
        pubkey
      end
    end.join($/)
  end
end

#ssh_conf_strObject



26
27
28
29
30
31
32
33
34
# File 'lib/vagabund/squatter/user.rb', line 26

def ssh_conf_str
  unless @ssh_config.nil?
    begin
      File.read(File.expand_path(@ssh_config)).chomp
    rescue Exception => e
      @ssh_config
    end
  end
end

#to_sObject



36
37
38
39
40
41
42
# File 'lib/vagabund/squatter/user.rb', line 36

def to_s
  cmd_str = "useradd -m -s #{shell}"
  cmd_str += " -d #{home}"
  cmd_str += " -g #{group}" unless group.nil?
  cmd_str += " -G #{[groups].flatten.join(',')}" unless groups.nil?
  cmd_str += " #{username}"
end