Class: Wright::Provider::User::GnuPasswd

Inherits:
Wright::Provider::User show all
Defined in:
lib/wright/provider/user/gnu_passwd.rb

Overview

GNU passwd user provider. Used as a provider for Resource::User on GNU systems.

Constant Summary

Constants inherited from Wright::Provider

PROVIDER_DIR

Instance Method Summary collapse

Methods inherited from Wright::Provider::User

#attributes_uptodate?, #create, #full_name, #full_name_uptodate?, #groups, #groups_uptodate?, #home, #home_uptodate?, #primary_group, #primary_group_uptodate?, #remove, #shell, #shell_uptodate?, #system_user?, #uid, #uid_uptodate?, #uptodate?, #user_data, #user_exists?, #user_name

Methods inherited from Wright::Provider

#env, #exec_or_fail, #initialize, #unless_dry_run, #unless_uptodate, #updated?

Constructor Details

This class inherits a constructor from Wright::Provider

Instance Method Details

#commentObject (private)


43
44
45
# File 'lib/wright/provider/user/gnu_passwd.rb', line 43

def comment
  full_name.nil? ? nil : "#{full_name},,,"
end

#create_userObject (private)


12
13
14
15
16
# File 'lib/wright/provider/user/gnu_passwd.rb', line 12

def create_user
  exec_or_fail('useradd',
               [*user_options, user_name],
               "cannot create user '#{user_name}'")
end

#group_listObject (private)


47
48
49
# File 'lib/wright/provider/user/gnu_passwd.rb', line 47

def group_list
  groups.nil? ? nil : groups.join(',')
end

#remove_userObject (private)


24
25
26
27
28
# File 'lib/wright/provider/user/gnu_passwd.rb', line 24

def remove_user
  exec_or_fail('userdel',
               [user_name],
               "cannot remove user '#{user_name}'")
end

#update_userObject (private)


18
19
20
21
22
# File 'lib/wright/provider/user/gnu_passwd.rb', line 18

def update_user
  exec_or_fail('usermod',
               [*user_options, user_name],
               "cannot create user '#{user_name}'")
end

#user_optionsObject (private)


30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/wright/provider/user/gnu_passwd.rb', line 30

def user_options
  options = {
    '-u' => uid,
    '-g' => primary_group,
    '-c' => comment,
    '-G' => group_list,
    '-s' => shell,
    '-d' => home
  }.reject { |_k, v| v.nil? }.flatten
  options << '-r' if system_user?
  options.map(&:to_s)
end