Module: NexusSW::LXD::Transport::Mixins::Helpers::UsersMixin
Instance Attribute Summary collapse
-
#file_mode ⇒ Object
Returns the value of attribute file_mode.
-
#gid ⇒ Object
Returns the value of attribute gid.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
Instance Attribute Details
#file_mode ⇒ Object
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 |
#gid ⇒ Object
Returns the value of attribute gid.
23 24 25 |
# File 'lib/nexussw/lxd/transport/mixins/helpers/users.rb', line 23 def gid @gid end |
#uid ⇒ Object (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 |
#username ⇒ Object (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_user ⇒ Object
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, = {}) return unless user_nameorid passwd = read_file [: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 |