Module: NexusSW::LXD::Transport::Mixins::Helpers::UsersMixin

Included in:
CLI, Rest
Defined in:
lib/nexussw/lxd/transport/mixins/helpers/users.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#file_modeObject

Returns the value of attribute file_mode.



23
24
25
# File 'lib/nexussw/lxd/transport/mixins/helpers/users.rb', line 23

def file_mode
  @file_mode
end

#gidObject

Returns the value of attribute gid.



23
24
25
# File 'lib/nexussw/lxd/transport/mixins/helpers/users.rb', line 23

def gid
  @gid
end

#uidObject (readonly)

Returns the value of attribute uid.



24
25
26
# File 'lib/nexussw/lxd/transport/mixins/helpers/users.rb', line 24

def uid
  @uid
end

#usernameObject (readonly)

Returns the value of attribute username.



24
25
26
# File 'lib/nexussw/lxd/transport/mixins/helpers/users.rb', line 24

def username
  @username
end

Instance Method Details

#reset_userObject



26
27
28
# File 'lib/nexussw/lxd/transport/mixins/helpers/users.rb', line 26

def reset_user
  @username = @uid = @gid = nil
end

#user(user_nameorid, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/nexussw/lxd/transport/mixins/helpers/users.rb', line 9

def user(user_nameorid, options = {})
  return unless user_nameorid
  passwd = read_file options[:passwd_file] || "/etc/passwd"

  # rework into .split(':') if this gets more complicated
  @uid = user_nameorid.is_a?(String) ? passwd[/^#{user_nameorid}:[^:]*:([^:]*):/, 1] : user_nameorid
  @username = user_nameorid.is_a?(String) ? user_nameorid : passwd[/^([^:]*):[^:]*:#{user_nameorid}:/, 1]
  raise "User not found (#{user_nameorid}) while attempting to set transport identity" unless @uid && @username

  # gotcha: we're always setting the default group here, but it's changeable by the user, afterwards
  # so if `user` gets called again, and the caller wants an alternative gid, the caller will need to re-set the gid
  @gid = passwd[/^[^:]*:[^:]*:#{uid}:([^:]*):/, 1]
end