Class: Chef::Provider::User::Pw
- Inherits:
-
Chef::Provider::User
- Object
- Chef::Provider
- Chef::Provider::User
- Chef::Provider::User::Pw
- Defined in:
- lib/chef/provider/user/pw.rb
Instance Attribute Summary
Attributes inherited from Chef::Provider::User
Attributes inherited from Chef::Provider
#action, #current_resource, #new_resource, #run_context
Instance Method Summary collapse
- #check_lock ⇒ Object
- #create_user ⇒ Object
- #load_current_resource ⇒ Object
- #lock_user ⇒ Object
- #manage_user ⇒ Object
- #modify_password ⇒ Object
- #remove_user ⇒ Object
- #set_options ⇒ Object
- #unlock_user ⇒ Object
Methods inherited from Chef::Provider::User
#action_create, #action_lock, #action_manage, #action_modify, #action_remove, #action_unlock, #compare_user, #convert_group_name, #define_resource_requirements, #initialize, #whyrun_supported?
Methods included from Mixin::Command
#chdir_or_tmpdir, #handle_command_failures, #output_of_command, #run_command, #run_command_with_systems_locale
Methods included from Mixin::Command::Windows
Methods included from Mixin::Command::Unix
Methods inherited from Chef::Provider
#action_nothing, build_from_file, #cleanup_after_converge, #converge, #cookbook_name, #define_resource_requirements, #events, #initialize, #node, #process_resource_requirements, #requirements, #resource_collection, #run_action, #whyrun_mode?, #whyrun_supported?
Methods included from Mixin::ConvertToClassName
#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename
Methods included from Mixin::EnforceOwnershipAndPermissions
#access_controls, #enforce_ownership_and_permissions
Methods included from Mixin::RecipeDefinitionDSLCore
Methods included from Mixin::Language
#data_bag, #data_bag_item, #platform?, #platform_family?, #search, #value_for_platform, #value_for_platform_family
Constructor Details
This class inherits a constructor from Chef::Provider::User
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Chef::Mixin::RecipeDefinitionDSLCore
Instance Method Details
#check_lock ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/chef/provider/user/pw.rb', line 51 def check_lock case @current_resource.password when /^\*LOCKED\*/ @locked = true else @locked = false end @locked end |
#create_user ⇒ Object
31 32 33 34 35 36 |
# File 'lib/chef/provider/user/pw.rb', line 31 def create_user command = "pw useradd" command << run_command(:command => command) modify_password end |
#load_current_resource ⇒ Object
26 27 28 29 |
# File 'lib/chef/provider/user/pw.rb', line 26 def load_current_resource super raise Chef::Exceptions::User, "Could not find binary /usr/sbin/pw for #{@new_resource}" unless ::File.exists?("/usr/sbin/pw") end |
#lock_user ⇒ Object
61 62 63 |
# File 'lib/chef/provider/user/pw.rb', line 61 def lock_user run_command(:command => "pw lock #{@new_resource.username}") end |
#manage_user ⇒ Object
38 39 40 41 42 43 |
# File 'lib/chef/provider/user/pw.rb', line 38 def manage_user command = "pw usermod" command << run_command(:command => command) modify_password end |
#modify_password ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/chef/provider/user/pw.rb', line 95 def modify_password if @current_resource.password != @new_resource.password Chef::Log.debug("#{new_resource} updating password") command = "pw usermod #{@new_resource.username} -H 0" status = popen4(command, :waitlast => true) do |pid, stdin, stdout, stderr| stdin.puts "#{@new_resource.password}" end unless status.exitstatus == 0 raise Chef::Exceptions::User, "pw failed - #{status.inspect}!" end else Chef::Log.debug("#{new_resource} no change needed to password") end end |
#remove_user ⇒ Object
45 46 47 48 49 |
# File 'lib/chef/provider/user/pw.rb', line 45 def remove_user command = "pw userdel #{@new_resource.username}" command << " -r" if @new_resource.supports[:manage_home] run_command(:command => command) end |
#set_options ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/chef/provider/user/pw.rb', line 69 def opts = " #{@new_resource.username}" field_list = { 'comment' => "-c", 'home' => "-d", 'gid' => "-g", 'uid' => "-u", 'shell' => "-s" } field_list.sort{ |a,b| a[0] <=> b[0] }.each do |field, option| field_symbol = field.to_sym if @current_resource.send(field_symbol) != @new_resource.send(field_symbol) if @new_resource.send(field_symbol) Chef::Log.debug("#{@new_resource} setting #{field} to #{@new_resource.send(field_symbol)}") opts << " #{option} '#{@new_resource.send(field_symbol)}'" end end end if @new_resource.supports[:manage_home] Chef::Log.debug("#{@new_resource} is managing the users home directory") opts << " -m" end opts end |
#unlock_user ⇒ Object
65 66 67 |
# File 'lib/chef/provider/user/pw.rb', line 65 def unlock_user run_command(:command => "pw unlock #{@new_resource.username}") end |