Class: OSC::Machete::User Deprecated

Inherits:
Object
  • Object
show all
Defined in:
lib/osc/machete/user.rb

Overview

Deprecated.

Please use OodSupport::User instead.

Class that maintains the name and home identifiers of a User. Helper methods provided use the Etc module underneath.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username = Etc.getpwuid.name) ⇒ User

default user is the username of the current process

FIXME: is this true? Etc.getpwuid claims to use the default value from the Passwd struct: docs.ruby-lang.org/en/2.0.0/Etc.html#Passwd could this ever be different from Process.gid? Should we provide constructors for a User object for the given uid instead of username, or in Process do OSC::Machete::User.new(Etc.getpwuid.name(Process.gid)) Or should the default be OSC::Machete::User.from_uid(Process.uid) Is there ever a difference between the two?



21
22
23
24
25
# File 'lib/osc/machete/user.rb', line 21

def initialize(username = Etc.getpwuid.name)
  @name = username

  warn "[DEPRECATION] `OSC::Machete::User` is deprecated. Please use `OodSupport::User` instead (see ood_support gem)."
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/osc/machete/user.rb', line 7

def name
  @name
end

Class Method Details

.from_uid(uid) ⇒ User

factory method to produce a User from specified uid

Returns:

  • (User)

    user for the specified uid



30
31
32
# File 'lib/osc/machete/user.rb', line 30

def self.from_uid(uid)
  self.new Etc.getpwuid(uid).name
end

Instance Method Details

#groupsArray

get sorted list of group ids that user is part of by inspecting the /etc/group file there is also a ruby impl of this

Returns:

  • (Array)

    ids of groups that the user is a member of



47
48
49
# File 'lib/osc/machete/user.rb', line 47

def groups
  `id -G $USER`.strip.split.map(&:to_i).uniq.sort
end

#homeString

The home directory path of the user.

Returns:

  • (String)

    path to the home directory.



72
73
74
# File 'lib/osc/machete/user.rb', line 72

def home
  Dir.home(@name)
end

#member_of_group?(group) ⇒ Boolean

Determine if user is member of specified group

Parameters:

  • group (String)

    name

Returns:

  • (Boolean)

    true if user is a member of the specified group



38
39
40
# File 'lib/osc/machete/user.rb', line 38

def member_of_group?(group)
  Etc.getgrnam(group).mem.include?(@name) rescue false
end

#projectsArray<String>

get list of projects the user is part of FIXME: OSC specific

Returns:

  • (Array<String>)

    of projects the user is part of



55
56
57
# File 'lib/osc/machete/user.rb', line 55

def projects
  `id -Gn`.split.grep(/^P./)
end