class Wright::Provider::User

User provider. Used as a base class for {Resource::User} providers.

Public Instance Methods

create() click to toggle source

Creates or updates the user.

@return [void]

# File lib/wright/provider/user.rb, line 13
def create
  unless_uptodate(:create, "user already created: '#{user_name}'") do
    unless_dry_run("create user: '#{user_name}'") do
      if user_exists?
        update_user
      else
        create_user
      end
    end
  end
end
remove() click to toggle source

Removes the user.

@return [void]

# File lib/wright/provider/user.rb, line 28
def remove
  unless_uptodate(:remove, "user already removed: '#{user_name}'") do
    unless_dry_run("remove user: '#{user_name}'") do
      remove_user
    end
  end
end

Private Instance Methods

attributes_uptodate?() click to toggle source
# File lib/wright/provider/user.rb, line 90
def attributes_uptodate?
  uid_uptodate? &&
    full_name_uptodate? &&
    groups_uptodate? &&
    shell_uptodate? &&
    home_uptodate? &&
    primary_group_uptodate?
end
create_user() click to toggle source
# File lib/wright/provider/user.rb, line 135
def create_user
  fail NotImplementedError
end
full_name() click to toggle source
# File lib/wright/provider/user.rb, line 50
def full_name
  resource.full_name
end
full_name_uptodate?() click to toggle source
# File lib/wright/provider/user.rb, line 107
def full_name_uptodate?
  full_name.nil? || user_data.gecos.split(',').first == full_name
end
groups() click to toggle source
# File lib/wright/provider/user.rb, line 54
def groups
  resource.groups
end
groups_uptodate?() click to toggle source
# File lib/wright/provider/user.rb, line 111
def groups_uptodate?
  return true if groups.nil?
  target_groups = []
  Etc.group { |g| target_groups << g.name if g.mem.include?(user_name) }
  target_groups.sort.uniq == groups.sort.uniq
end
home() click to toggle source
# File lib/wright/provider/user.rb, line 62
def home
  resource.home
end
home_uptodate?() click to toggle source
# File lib/wright/provider/user.rb, line 122
def home_uptodate?
  home.nil? || user_data.dir == home
end
primary_group() click to toggle source
# File lib/wright/provider/user.rb, line 46
def primary_group
  resource.primary_group
end
primary_group_uptodate?() click to toggle source
# File lib/wright/provider/user.rb, line 126
def primary_group_uptodate?
  return true if primary_group.nil?
  user_data.gid == Wright::Util::User.group_to_gid(primary_group)
end
remove_user() click to toggle source
# File lib/wright/provider/user.rb, line 143
def remove_user
  fail NotImplementedError
end
shell() click to toggle source
# File lib/wright/provider/user.rb, line 58
def shell
  resource.shell
end
shell_uptodate?() click to toggle source
# File lib/wright/provider/user.rb, line 118
def shell_uptodate?
  shell.nil? || user_data.shell == shell
end
system_user?() click to toggle source
# File lib/wright/provider/user.rb, line 66
def system_user?
  resource.system
end
uid() click to toggle source
# File lib/wright/provider/user.rb, line 42
def uid
  resource.uid
end
uid_uptodate?() click to toggle source
# File lib/wright/provider/user.rb, line 103
def uid_uptodate?
  uid.nil? || user_data.uid == uid
end
update_user() click to toggle source
# File lib/wright/provider/user.rb, line 139
def update_user
  fail NotImplementedError
end
uptodate?(action) click to toggle source

@api public Checks if the user is up-to-date for a given action.

@param action [Symbol] the action. Currently supports

+:create+ and +:remove+.

@return [Bool] true if the user is up-to-date and false

otherwise

@raise [ArgumentError] if the action is invalid

# File lib/wright/provider/user.rb, line 79
def uptodate?(action)
  case action
  when :create
    user_exists? && attributes_uptodate?
  when :remove
    !user_exists?
  else
    fail ArgumentError, "invalid action '#{action}'"
  end
end
user_data() click to toggle source
# File lib/wright/provider/user.rb, line 99
def user_data
  Wright::Util::User.safe_getpwnam(user_name)
end
user_exists?() click to toggle source
# File lib/wright/provider/user.rb, line 131
def user_exists?
  !user_data.nil?
end
user_name() click to toggle source
# File lib/wright/provider/user.rb, line 38
def user_name
  resource.name
end