chef 18.9.4 → 18.11.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +16 -12
  3. data/README.md +0 -1
  4. data/Rakefile +21 -5
  5. data/chef-universal-mingw-ucrt.gemspec +4 -2
  6. data/chef.gemspec +17 -14
  7. data/lib/chef/application/apply.rb +1 -1
  8. data/lib/chef/application/base.rb +4 -4
  9. data/lib/chef/application/exit_code.rb +1 -1
  10. data/lib/chef/chef_fs/command_line.rb +4 -4
  11. data/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb +1 -1
  12. data/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb +2 -3
  13. data/lib/chef/client.rb +2 -3
  14. data/lib/chef/compliance/fetcher/chef_server.rb +1 -1
  15. data/lib/chef/compliance/reporter/cli.rb +2 -2
  16. data/lib/chef/compliance/runner.rb +19 -1
  17. data/lib/chef/dsl/chef_vault.rb +1 -1
  18. data/lib/chef/dsl/rest_resource.rb +223 -16
  19. data/lib/chef/encrypted_data_bag_item/decryptor.rb +1 -5
  20. data/lib/chef/environment.rb +1 -1
  21. data/lib/chef/exceptions.rb +1 -1
  22. data/lib/chef/file_cache.rb +1 -5
  23. data/lib/chef/formatters/error_description.rb +8 -1
  24. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +1 -1
  25. data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +1 -1
  26. data/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb +1 -1
  27. data/lib/chef/group.rb +1 -1
  28. data/lib/chef/handler/slow_report.rb +1 -1
  29. data/lib/chef/http/authenticator.rb +25 -12
  30. data/lib/chef/mixin/api_version_request_handling.rb +1 -1
  31. data/lib/chef/mixin/powershell_type_coercions.rb +2 -2
  32. data/lib/chef/mixin/securable.rb +2 -2
  33. data/lib/chef/mixin/template.rb +25 -3
  34. data/lib/chef/mixin/versioned_api.rb +1 -1
  35. data/lib/chef/monkey_patches/net-http.rb +8 -8
  36. data/lib/chef/monkey_patches/reline-windows.rb +116 -0
  37. data/lib/chef/property.rb +1 -1
  38. data/lib/chef/provider/cron.rb +1 -1
  39. data/lib/chef/provider/directory.rb +11 -0
  40. data/lib/chef/provider/dsc_resource.rb +2 -2
  41. data/lib/chef/provider/file/content.rb +3 -2
  42. data/lib/chef/provider/file.rb +1 -1
  43. data/lib/chef/provider/git.rb +1 -1
  44. data/lib/chef/provider/ifconfig/debian.rb +1 -1
  45. data/lib/chef/provider/ifconfig/redhat.rb +1 -1
  46. data/lib/chef/provider/mount/linux.rb +1 -1
  47. data/lib/chef/provider/mount/windows.rb +4 -4
  48. data/lib/chef/provider/package/chocolatey.rb +78 -19
  49. data/lib/chef/provider/package/dnf/dnf_helper.py +355 -65
  50. data/lib/chef/provider/package/dnf/python_helper.rb +7 -4
  51. data/lib/chef/provider/package/dnf.rb +25 -6
  52. data/lib/chef/provider/package/homebrew.rb +3 -3
  53. data/lib/chef/provider/package/rubygems.rb +25 -2
  54. data/lib/chef/provider/package/snap.rb +1 -1
  55. data/lib/chef/provider/package/windows/exe.rb +1 -1
  56. data/lib/chef/provider/package/windows/msi.rb +1 -1
  57. data/lib/chef/provider/package/yum/rpm_utils.rb +2 -2
  58. data/lib/chef/provider/package/yum.rb +1 -1
  59. data/lib/chef/provider/powershell_script.rb +84 -84
  60. data/lib/chef/provider/service/debian.rb +2 -4
  61. data/lib/chef/provider/user/dscl.rb +1 -1
  62. data/lib/chef/provider/user/mac.rb +1 -1
  63. data/lib/chef/provider/windows_script.rb +1 -1
  64. data/lib/chef/resource/_rest_resource.rb +9 -7
  65. data/lib/chef/resource/alternatives.rb +41 -41
  66. data/lib/chef/resource/apt_package.rb +31 -31
  67. data/lib/chef/resource/apt_preference.rb +22 -22
  68. data/lib/chef/resource/apt_repository.rb +2 -2
  69. data/lib/chef/resource/archive_file.rb +52 -18
  70. data/lib/chef/resource/bash.rb +129 -129
  71. data/lib/chef/resource/bff_package.rb +15 -15
  72. data/lib/chef/resource/breakpoint.rb +44 -44
  73. data/lib/chef/resource/cab_package.rb +22 -22
  74. data/lib/chef/resource/chef_client_config.rb +251 -89
  75. data/lib/chef/resource/chef_client_cron.rb +18 -18
  76. data/lib/chef/resource/chef_client_launchd.rb +1 -1
  77. data/lib/chef/resource/chef_client_scheduled_task.rb +31 -31
  78. data/lib/chef/resource/chef_client_systemd_timer.rb +16 -16
  79. data/lib/chef/resource/chef_client_trusted_certificate.rb +28 -28
  80. data/lib/chef/resource/chef_handler.rb +107 -107
  81. data/lib/chef/resource/chef_vault_secret.rb +1 -1
  82. data/lib/chef/resource/chocolatey_config.rb +14 -14
  83. data/lib/chef/resource/chocolatey_feature.rb +1 -1
  84. data/lib/chef/resource/chocolatey_installer.rb +60 -42
  85. data/lib/chef/resource/chocolatey_package.rb +1 -1
  86. data/lib/chef/resource/chocolatey_source.rb +15 -15
  87. data/lib/chef/resource/cron/_cron_shared.rb +0 -2
  88. data/lib/chef/resource/cron/cron.rb +70 -70
  89. data/lib/chef/resource/csh.rb +5 -5
  90. data/lib/chef/resource/directory.rb +6 -6
  91. data/lib/chef/resource/dpkg_package.rb +3 -3
  92. data/lib/chef/resource/group.rb +28 -28
  93. data/lib/chef/resource/habitat/habitat_package.rb +80 -80
  94. data/lib/chef/resource/habitat/habitat_sup.rb +93 -95
  95. data/lib/chef/resource/habitat/habitat_sup_systemd.rb +10 -10
  96. data/lib/chef/resource/habitat/habitat_sup_windows.rb +3 -3
  97. data/lib/chef/resource/habitat_config.rb +13 -13
  98. data/lib/chef/resource/habitat_install.rb +17 -17
  99. data/lib/chef/resource/habitat_service.rb +1 -1
  100. data/lib/chef/resource/habitat_user_toml.rb +12 -12
  101. data/lib/chef/resource/helpers/cron_validations.rb +2 -2
  102. data/lib/chef/resource/homebrew_cask.rb +1 -1
  103. data/lib/chef/resource/homebrew_package.rb +20 -20
  104. data/lib/chef/resource/homebrew_tap.rb +1 -1
  105. data/lib/chef/resource/hostname.rb +2 -2
  106. data/lib/chef/resource/http_request.rb +2 -2
  107. data/lib/chef/resource/ifconfig.rb +34 -34
  108. data/lib/chef/resource/inspec_input.rb +37 -37
  109. data/lib/chef/resource/inspec_waiver.rb +63 -63
  110. data/lib/chef/resource/inspec_waiver_file_entry.rb +25 -25
  111. data/lib/chef/resource/ksh.rb +5 -5
  112. data/lib/chef/resource/launchd.rb +2 -2
  113. data/lib/chef/resource/link.rb +8 -8
  114. data/lib/chef/resource/locale.rb +6 -6
  115. data/lib/chef/resource/log.rb +4 -4
  116. data/lib/chef/resource/mdadm.rb +36 -36
  117. data/lib/chef/resource/mount.rb +3 -3
  118. data/lib/chef/resource/msu_package.rb +1 -1
  119. data/lib/chef/resource/ohai.rb +32 -32
  120. data/lib/chef/resource/ohai_hint.rb +24 -24
  121. data/lib/chef/resource/openssl_ec_private_key.rb +2 -2
  122. data/lib/chef/resource/openssl_ec_public_key.rb +2 -2
  123. data/lib/chef/resource/openssl_rsa_private_key.rb +1 -1
  124. data/lib/chef/resource/openssl_rsa_public_key.rb +2 -2
  125. data/lib/chef/resource/openssl_x509_certificate.rb +1 -1
  126. data/lib/chef/resource/openssl_x509_crl.rb +15 -15
  127. data/lib/chef/resource/openssl_x509_request.rb +2 -2
  128. data/lib/chef/resource/osx_profile.rb +54 -54
  129. data/lib/chef/resource/package.rb +6 -6
  130. data/lib/chef/resource/perl.rb +5 -5
  131. data/lib/chef/resource/plist.rb +4 -4
  132. data/lib/chef/resource/powershell_package_source.rb +12 -12
  133. data/lib/chef/resource/python.rb +4 -4
  134. data/lib/chef/resource/reboot.rb +5 -5
  135. data/lib/chef/resource/registry_key.rb +81 -81
  136. data/lib/chef/resource/remote_file.rb +72 -72
  137. data/lib/chef/resource/resource_notification.rb +4 -4
  138. data/lib/chef/resource/rhsm_errata_level.rb +1 -1
  139. data/lib/chef/resource/rhsm_register.rb +2 -2
  140. data/lib/chef/resource/scm/git.rb +79 -79
  141. data/lib/chef/resource/scm/subversion.rb +9 -9
  142. data/lib/chef/resource/script.rb +3 -3
  143. data/lib/chef/resource/selinux_boolean.rb +12 -12
  144. data/lib/chef/resource/selinux_fcontext.rb +21 -21
  145. data/lib/chef/resource/selinux_install.rb +18 -18
  146. data/lib/chef/resource/selinux_login.rb +11 -11
  147. data/lib/chef/resource/selinux_module.rb +16 -16
  148. data/lib/chef/resource/selinux_permissive.rb +9 -9
  149. data/lib/chef/resource/selinux_port.rb +16 -16
  150. data/lib/chef/resource/selinux_state.rb +28 -28
  151. data/lib/chef/resource/selinux_user.rb +14 -14
  152. data/lib/chef/resource/service.rb +5 -5
  153. data/lib/chef/resource/snap_package.rb +16 -16
  154. data/lib/chef/resource/ssh_known_hosts_entry.rb +10 -10
  155. data/lib/chef/resource/sudo.rb +68 -68
  156. data/lib/chef/resource/swap_file.rb +12 -12
  157. data/lib/chef/resource/sysctl.rb +42 -42
  158. data/lib/chef/resource/systemd_unit.rb +38 -38
  159. data/lib/chef/resource/timezone.rb +16 -16
  160. data/lib/chef/resource/user/mac_user.rb +3 -3
  161. data/lib/chef/resource/user.rb +6 -6
  162. data/lib/chef/resource/user_ulimit.rb +22 -22
  163. data/lib/chef/resource/windows_ad_join.rb +25 -25
  164. data/lib/chef/resource/windows_audit_policy.rb +34 -34
  165. data/lib/chef/resource/windows_auto_run.rb +8 -8
  166. data/lib/chef/resource/windows_certificate.rb +20 -20
  167. data/lib/chef/resource/windows_defender.rb +22 -22
  168. data/lib/chef/resource/windows_defender_exclusion.rb +17 -17
  169. data/lib/chef/resource/windows_env.rb +6 -6
  170. data/lib/chef/resource/windows_feature.rb +42 -42
  171. data/lib/chef/resource/windows_feature_dism.rb +8 -8
  172. data/lib/chef/resource/windows_feature_powershell.rb +20 -20
  173. data/lib/chef/resource/windows_firewall_profile.rb +28 -28
  174. data/lib/chef/resource/windows_firewall_rule.rb +47 -47
  175. data/lib/chef/resource/windows_font.rb +7 -7
  176. data/lib/chef/resource/windows_package.rb +59 -59
  177. data/lib/chef/resource/windows_pagefile.rb +29 -29
  178. data/lib/chef/resource/windows_path.rb +12 -12
  179. data/lib/chef/resource/windows_printer.rb +28 -28
  180. data/lib/chef/resource/windows_printer_port.rb +21 -21
  181. data/lib/chef/resource/windows_security_policy.rb +23 -23
  182. data/lib/chef/resource/windows_service.rb +108 -108
  183. data/lib/chef/resource/windows_share.rb +19 -19
  184. data/lib/chef/resource/windows_shortcut.rb +7 -7
  185. data/lib/chef/resource/windows_task.rb +105 -105
  186. data/lib/chef/resource/windows_uac.rb +14 -14
  187. data/lib/chef/resource/windows_update_settings.rb +27 -27
  188. data/lib/chef/resource/windows_user_privilege.rb +59 -59
  189. data/lib/chef/resource/windows_workgroup.rb +12 -12
  190. data/lib/chef/resource/yum_package.rb +1 -1
  191. data/lib/chef/resource/yum_repository.rb +36 -36
  192. data/lib/chef/resource.rb +1 -1
  193. data/lib/chef/resource_collection/resource_set.rb +2 -3
  194. data/lib/chef/resource_inspector.rb +1 -2
  195. data/lib/chef/run_context.rb +2 -2
  196. data/lib/chef/runner.rb +1 -1
  197. data/lib/chef/secret_fetcher/akeyless_vault.rb +0 -1
  198. data/lib/chef/secret_fetcher/hashi_vault.rb +0 -1
  199. data/lib/chef/shell/ext.rb +20 -20
  200. data/lib/chef/shell/shell_session.rb +1 -1
  201. data/lib/chef/shell.rb +7 -0
  202. data/lib/chef/version.rb +1 -1
  203. data/lib/chef/version_constraint.rb +1 -1
  204. data/lib/chef/win32/file/version_info.rb +1 -1
  205. metadata +63 -38
@@ -29,26 +29,26 @@ class Chef
29
29
  description "Use the **windows_update_settings** resource to manage the various Windows Update patching options."
30
30
  introduced "17.3"
31
31
  examples <<~DOC
32
- **Set Windows Update settings**:
33
-
34
- ```ruby
35
- windows_update_settings 'Settings to Configure Windows Nodes to automatically receive updates' do
36
- disable_os_upgrades true
37
- elevate_non_admins true
38
- block_windows_update_website true
39
- automatically_install_minor_updates true
40
- scheduled_install_day 'Friday'
41
- scheduled_install_hour 18
42
- update_other_ms_products true
43
- action :enable
44
- end
45
- ```
32
+ **Set Windows Update settings**:
33
+
34
+ ```ruby
35
+ windows_update_settings 'Settings to Configure Windows Nodes to automatically receive updates' do
36
+ disable_os_upgrades true
37
+ elevate_non_admins true
38
+ block_windows_update_website true
39
+ automatically_install_minor_updates true
40
+ scheduled_install_day 'Friday'
41
+ scheduled_install_hour 18
42
+ update_other_ms_products true
43
+ action :enable
44
+ end
45
+ ```
46
46
  DOC
47
47
 
48
48
  # required for the alias to pass validation
49
49
  allowed_actions :set, :enable
50
50
 
51
- DAYS = %W{Everyday Monday Tuesday Wednesday Thursday Friday Saturday Sunday}.freeze
51
+ DAYS = %w{Everyday Monday Tuesday Wednesday Thursday Friday Saturday Sunday}.freeze
52
52
  UPDATE_OPTIONS = {
53
53
  notify: 2,
54
54
  download_and_notify: 3,
@@ -87,8 +87,8 @@ class Chef
87
87
  # HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate\AU
88
88
 
89
89
  property :automatic_update_option, [Integer, Symbol], equal_to: UPDATE_OPTIONS.keys, coerce: proc { |x| UPDATE_OPTIONS.key(x) || x },
90
- default: :download_and_schedule,
91
- description: "Control what to do when updates are found. This allows you to notify, automatically download and notify to install, automatically download and schedule the install, or let the local admin decide what action to take."
90
+ default: :download_and_schedule,
91
+ description: "Control what to do when updates are found. This allows you to notify, automatically download and notify to install, automatically download and schedule the install, or let the local admin decide what action to take."
92
92
  # options: 2 - notify before download
93
93
  # 3 - auto download and notify
94
94
  # 4 - auto download and schedule - must also set day and time (below)
@@ -104,11 +104,11 @@ class Chef
104
104
  # 1 - yeah, buddy, i want to set my own interval for checking for updates - true
105
105
 
106
106
  property :custom_detection_frequency, Integer, default: 22, description: "If you decided to override the OS default detection frequency, specify your choice here. Valid choices are 0 - 22",
107
- callbacks: {
108
- "should be a valid detection frequency (0-22)" => lambda { |p|
109
- p >= 0 && p <= 22
110
- },
111
- }
107
+ callbacks: {
108
+ "should be a valid detection frequency (0-22)" => lambda { |p|
109
+ p.between?(0, 22)
110
+ },
111
+ }
112
112
  # a time period of between 0 and 22 hours to check for new updates
113
113
  # this is a hex value - convert it from dec to hex
114
114
 
@@ -125,11 +125,11 @@ class Chef
125
125
  # Sunday - Saturday day of the week to install, 1 == sunday
126
126
 
127
127
  property :scheduled_install_hour, Integer, description: "If you chose a scheduled day to install, then choose an hour on that day for you installation",
128
- callbacks: {
129
- "should be a valid hour in a 24 hour clock" => lambda { |p|
130
- p > 0 && p < 25
131
- },
132
- }
128
+ callbacks: {
129
+ "should be a valid hour in a 24 hour clock" => lambda { |p|
130
+ p > 0 && p < 25
131
+ },
132
+ }
133
133
  # options: --- 2-digit number representing an hour of the day, uses a 24-hour clock, 12 == noon, 24 == midnight
134
134
 
135
135
  property :update_other_ms_products, [true, false], default: true, description: "Allows for other Microsoft products to get updates too"
@@ -28,67 +28,67 @@ class Chef
28
28
  introduced "16.0"
29
29
 
30
30
  examples <<~DOC
31
- **Set the SeNetworkLogonRight privilege for the Builtin Administrators and Authenticated Users groups**:
31
+ **Set the SeNetworkLogonRight privilege for the Builtin Administrators and Authenticated Users groups**:
32
32
 
33
- The `:set` action will add this privilege for these two groups and remove this privilege from all other groups or users.
33
+ The `:set` action will add this privilege for these two groups and remove this privilege from all other groups or users.
34
34
 
35
- ```ruby
36
- windows_user_privilege 'Network Logon Rights' do
37
- privilege 'SeNetworkLogonRight'
38
- users ['BUILTIN\\Administrators', 'NT AUTHORITY\\Authenticated Users']
39
- action :set
40
- end
41
- ```
35
+ ```ruby
36
+ windows_user_privilege 'Network Logon Rights' do
37
+ privilege 'SeNetworkLogonRight'
38
+ users ['BUILTIN\\Administrators', 'NT AUTHORITY\\Authenticated Users']
39
+ action :set
40
+ end
41
+ ```
42
42
 
43
- **Set the SeCreatePagefilePrivilege privilege for the Builtin Guests and Administrator groups**:
43
+ **Set the SeCreatePagefilePrivilege privilege for the Builtin Guests and Administrator groups**:
44
44
 
45
- The `:set` action will add this privilege for these two groups and remove this privilege from all other groups or users.
45
+ The `:set` action will add this privilege for these two groups and remove this privilege from all other groups or users.
46
46
 
47
- ```ruby
48
- windows_user_privilege 'Create Pagefile' do
49
- privilege 'SeCreatePagefilePrivilege'
50
- users ['BUILTIN\\Guests', 'BUILTIN\\Administrators']
51
- action :set
52
- end
53
- ```
47
+ ```ruby
48
+ windows_user_privilege 'Create Pagefile' do
49
+ privilege 'SeCreatePagefilePrivilege'
50
+ users ['BUILTIN\\Guests', 'BUILTIN\\Administrators']
51
+ action :set
52
+ end
53
+ ```
54
54
 
55
- **Add the SeDenyRemoteInteractiveLogonRight privilege to the 'Remote interactive logon' principal**:
55
+ **Add the SeDenyRemoteInteractiveLogonRight privilege to the 'Remote interactive logon' principal**:
56
56
 
57
- ```ruby
58
- windows_user_privilege 'Remote interactive logon' do
59
- privilege 'SeDenyRemoteInteractiveLogonRight'
60
- action :add
61
- end
62
- ```
57
+ ```ruby
58
+ windows_user_privilege 'Remote interactive logon' do
59
+ privilege 'SeDenyRemoteInteractiveLogonRight'
60
+ action :add
61
+ end
62
+ ```
63
63
 
64
- **Add the SeCreatePageFilePrivilege privilege to the Builtin Guests group**:
64
+ **Add the SeCreatePageFilePrivilege privilege to the Builtin Guests group**:
65
65
 
66
- ```ruby
67
- windows_user_privilege 'Guests add Create Pagefile' do
68
- principal 'BUILTIN\\Guests'
69
- privilege 'SeCreatePagefilePrivilege'
70
- action :add
71
- end
72
- ```
66
+ ```ruby
67
+ windows_user_privilege 'Guests add Create Pagefile' do
68
+ principal 'BUILTIN\\Guests'
69
+ privilege 'SeCreatePagefilePrivilege'
70
+ action :add
71
+ end
72
+ ```
73
73
 
74
- **Remove the SeCreatePageFilePrivilege privilege from the Builtin Guests group**:
74
+ **Remove the SeCreatePageFilePrivilege privilege from the Builtin Guests group**:
75
75
 
76
- ```ruby
77
- windows_user_privilege 'Create Pagefile' do
78
- privilege 'SeCreatePagefilePrivilege'
79
- users ['BUILTIN\\Guests']
80
- action :remove
81
- end
82
- ```
76
+ ```ruby
77
+ windows_user_privilege 'Create Pagefile' do
78
+ privilege 'SeCreatePagefilePrivilege'
79
+ users ['BUILTIN\\Guests']
80
+ action :remove
81
+ end
82
+ ```
83
83
 
84
- **Clear the SeDenyNetworkLogonRight privilege from all users**:
84
+ **Clear the SeDenyNetworkLogonRight privilege from all users**:
85
85
 
86
- ```ruby
87
- windows_user_privilege 'Allow any user the Network Logon right' do
88
- privilege 'SeDenyNetworkLogonRight'
89
- action :clear
90
- end
91
- ```
86
+ ```ruby
87
+ windows_user_privilege 'Allow any user the Network Logon right' do
88
+ privilege 'SeDenyNetworkLogonRight'
89
+ action :clear
90
+ end
91
+ ```
92
92
  DOC
93
93
 
94
94
  PRIVILEGE_OPTS = %w{ SeAssignPrimaryTokenPrivilege
@@ -139,20 +139,20 @@ class Chef
139
139
  }.freeze
140
140
 
141
141
  property :principal, String,
142
- description: "An optional property to add the privilege for given principal. Use only with add and remove action. Principal can either be a user, group, or [special identity](https://docs.microsoft.com/en-us/windows/security/identity-protection/access-control/special-identities).",
143
- name_property: true
142
+ description: "An optional property to add the privilege for given principal. Use only with add and remove action. Principal can either be a user, group, or [special identity](https://docs.microsoft.com/en-us/windows/security/identity-protection/access-control/special-identities).",
143
+ name_property: true
144
144
 
145
145
  property :users, [Array, String],
146
- description: "An optional property to set the privilege for the specified users. Use only with `:set` action",
147
- coerce: proc { |v| Array(v) }
146
+ description: "An optional property to set the privilege for the specified users. Use only with `:set` action",
147
+ coerce: proc { |v| Array(v) }
148
148
 
149
149
  property :privilege, [Array, String],
150
- description: "One or more privileges to set for principal or users/groups. For more information, see [Microsoft's documentation on what each privilege does](https://learn.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/user-rights-assignment).",
151
- required: true,
152
- coerce: proc { |v| Array(v) },
153
- callbacks: {
154
- "Privilege property restricted to the following values: #{PRIVILEGE_OPTS}" => lambda { |n| (n - PRIVILEGE_OPTS).empty? },
155
- }, identity: true
150
+ description: "One or more privileges to set for principal or users/groups. For more information, see [Microsoft's documentation on what each privilege does](https://learn.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/user-rights-assignment).",
151
+ required: true,
152
+ coerce: proc { |v| Array(v) },
153
+ callbacks: {
154
+ "Privilege property restricted to the following values: #{PRIVILEGE_OPTS}" => lambda { |n| (n - PRIVILEGE_OPTS).empty? },
155
+ }, identity: true
156
156
 
157
157
  load_current_value do |new_resource|
158
158
  if new_resource.principal && (new_resource.action.include?(:add) || new_resource.action.include?(:remove))
@@ -222,7 +222,7 @@ class Chef
222
222
  missing_res_privileges = (new_resource.privilege - curr_res_privilege)
223
223
 
224
224
  if missing_res_privileges
225
- Chef::Log.info("User \'#{new_resource.principal}\' for Privilege: #{missing_res_privileges.join(", ")} not found. Nothing to remove.")
225
+ Chef::Log.info("User '#{new_resource.principal}' for Privilege: #{missing_res_privileges.join(", ")} not found. Nothing to remove.")
226
226
  end
227
227
 
228
228
  (new_resource.privilege - missing_res_privileges).each do |principal_right|
@@ -27,20 +27,20 @@ class Chef
27
27
  description "Use the **windows_workgroup** resource to join or change the workgroup of a Windows host."
28
28
  introduced "14.5"
29
29
  examples <<~DOC
30
- **Join a workgroup**:
30
+ **Join a workgroup**:
31
31
 
32
- ```ruby
33
- windows_workgroup 'myworkgroup'
34
- ```
32
+ ```ruby
33
+ windows_workgroup 'myworkgroup'
34
+ ```
35
35
 
36
- **Join a workgroup using a specific user**:
36
+ **Join a workgroup using a specific user**:
37
37
 
38
- ```ruby
39
- windows_workgroup 'myworkgroup' do
40
- user 'Administrator'
41
- password 'passw0rd'
42
- end
43
- ```
38
+ ```ruby
39
+ windows_workgroup 'myworkgroup' do
40
+ user 'Administrator'
41
+ password 'passw0rd'
42
+ end
43
+ ```
44
44
  DOC
45
45
 
46
46
  property :workgroup_name, String,
@@ -107,7 +107,7 @@ class Chef
107
107
  # return [String] the appropriate PS command to joint the workgroup
108
108
  def join_command
109
109
  cmd = ""
110
- cmd << "$pswd = ConvertTo-SecureString \'#{new_resource.password}\' -AsPlainText -Force;" if new_resource.password
110
+ cmd << "$pswd = ConvertTo-SecureString '#{new_resource.password}' -AsPlainText -Force;" if new_resource.password
111
111
  cmd << "$credential = New-Object System.Management.Automation.PSCredential (\"#{new_resource.user}\",$pswd);" if new_resource.password
112
112
  cmd << "Add-Computer -WorkgroupName #{new_resource.workgroup_name}"
113
113
  cmd << " -Credential $credential" if new_resource.password
@@ -24,7 +24,7 @@ class Chef
24
24
  class YumPackage < Chef::Resource::Package
25
25
 
26
26
  provides :yum_package
27
- provides :package, platform_family: "fedora_derived"
27
+ provides :package, platform_family: %w{fedora rhel amazon}
28
28
 
29
29
  description "Use the **yum_package** resource to install, upgrade, and remove packages with Yum for the Red Hat and CentOS platforms. The yum_package resource is able to resolve `provides` data for packages much like Yum can do when it is run from the command line. This allows a variety of options for installing packages, like minimum versions, virtual provides, and library names. Note: Support for using file names to install packages (as in `yum_package '/bin/sh'`) is not available because the volume of data required to parse for this is excessive."
30
30
  examples <<~DOC
@@ -27,24 +27,24 @@ class Chef
27
27
  description "Use the **yum_repository** resource to manage a Yum repository configuration file located at `/etc/yum.repos.d/repositoryid.repo` on the local machine. This configuration file specifies which repositories to reference, how to handle cached data, etc."
28
28
  introduced "12.14"
29
29
  examples <<~DOC
30
- **Add an internal company repository**:
31
-
32
- ```ruby
33
- yum_repository 'OurCo' do
34
- description 'OurCo yum repository'
35
- mirrorlist 'http://artifacts.ourco.org/mirrorlist?repo=ourco-8&arch=$basearch'
36
- gpgkey 'http://artifacts.ourco.org/pub/yum/RPM-GPG-KEY-OURCO-8'
37
- action :create
38
- end
39
- ```
40
-
41
- **Delete a repository**:
42
-
43
- ```ruby
44
- yum_repository 'CentOS-Media' do
45
- action :delete
46
- end
47
- ```
30
+ **Add an internal company repository**:
31
+
32
+ ```ruby
33
+ yum_repository 'OurCo' do
34
+ description 'OurCo yum repository'
35
+ mirrorlist 'http://artifacts.ourco.org/mirrorlist?repo=ourco-8&arch=$basearch'
36
+ gpgkey 'http://artifacts.ourco.org/pub/yum/RPM-GPG-KEY-OURCO-8'
37
+ action :create
38
+ end
39
+ ```
40
+
41
+ **Delete a repository**:
42
+
43
+ ```ruby
44
+ yum_repository 'CentOS-Media' do
45
+ action :delete
46
+ end
47
+ ```
48
48
  DOC
49
49
 
50
50
  # http://linux.die.net/man/5/yum.conf as well as
@@ -67,8 +67,8 @@ class Chef
67
67
  default: true
68
68
 
69
69
  property :cost, String, regex: /^\d+$/,
70
- description: "Relative cost of accessing this repository. Useful for weighing one repo's packages as greater/less than any other.",
71
- validation_message: "The cost property must be a numeric value!"
70
+ description: "Relative cost of accessing this repository. Useful for weighing one repo's packages as greater/less than any other.",
71
+ validation_message: "The cost property must be a numeric value!"
72
72
 
73
73
  property :description, String,
74
74
  description: "Descriptive name for the repository channel and maps to the 'name' parameter in a repository .conf.",
@@ -99,7 +99,7 @@ class Chef
99
99
  description: "URL pointing to the ASCII-armored GPG key file for the repository. This is used if Yum needs a public key to verify a package and the required key hasn't been imported into the RPM database. If this option is set, Yum will automatically import the key from the specified URL. Multiple URLs may be specified in the same manner as the baseurl option. If a GPG key is required to install a package from a repository, all keys specified for that repository will be installed.\nMultiple URLs may be specified in the same manner as the baseurl option. If a GPG key is required to install a package from a repository, all keys specified for that repository will be installed."
100
100
 
101
101
  property :http_caching, String, equal_to: %w{packages all none},
102
- description: "Determines how upstream HTTP caches are instructed to handle any HTTP downloads that Yum does. This option can take the following values:\n - `all` means all HTTP downloads should be cached\n - `packages` means only RPM package downloads should be cached, but not repository metadata downloads\n - `none` means no HTTP downloads should be cached.\n\nThe default value of `all` is recommended unless you are experiencing caching related issues."
102
+ description: "Determines how upstream HTTP caches are instructed to handle any HTTP downloads that Yum does. This option can take the following values:\n - `all` means all HTTP downloads should be cached\n - `packages` means only RPM package downloads should be cached, but not repository metadata downloads\n - `none` means no HTTP downloads should be cached.\n\nThe default value of `all` is recommended unless you are experiencing caching related issues."
103
103
 
104
104
  property :include_config, String,
105
105
  description: "An external configuration file using the format `url://to/some/location`."
@@ -122,19 +122,19 @@ class Chef
122
122
  description: "Number of times any attempt to retrieve a file should retry before returning an error. Setting this to `0` makes Yum try forever."
123
123
 
124
124
  property :metadata_expire, String, regex: [/^\d+$/, /^\d+[mhd]$/, /never/],
125
- description: "Time (in seconds) after which the metadata will expire. If the current metadata downloaded is less than the value specified, then Yum will not update the metadata against the repository. If you find that Yum is not downloading information on updates as often as you would like lower the value of this option. You can also change from the default of using seconds to using days, hours or minutes by appending a `d`, `h` or `m` respectively. The default is six hours to compliment yum-updates running once per hour. It is also possible to use the word `never`, meaning that the metadata will never expire. Note: When using a metalink file, the metalink must always be newer than the metadata for the repository due to the validation, so this timeout also applies to the metalink file.",
126
- validation_message: "The metadata_expire property must be a numeric value for time in seconds, the string 'never', or a numeric value appended with with `d`, `h`, or `m`!"
125
+ description: "Time (in seconds) after which the metadata will expire. If the current metadata downloaded is less than the value specified, then Yum will not update the metadata against the repository. If you find that Yum is not downloading information on updates as often as you would like lower the value of this option. You can also change from the default of using seconds to using days, hours or minutes by appending a `d`, `h` or `m` respectively. The default is six hours to compliment yum-updates running once per hour. It is also possible to use the word `never`, meaning that the metadata will never expire. Note: When using a metalink file, the metalink must always be newer than the metadata for the repository due to the validation, so this timeout also applies to the metalink file.",
126
+ validation_message: "The metadata_expire property must be a numeric value for time in seconds, the string 'never', or a numeric value appended with with `d`, `h`, or `m`!"
127
127
 
128
128
  property :metalink, String,
129
129
  description: "Specifies a URL to a metalink file for the repomd.xml, a list of mirrors for the entire repository are generated by converting the mirrors for the repomd.xml file to a baseurl."
130
130
 
131
131
  property :mirror_expire, String, regex: [/^\d+$/, /^\d+[mhd]$/],
132
- description: "Time (in seconds) after which the mirrorlist locally cached will expire. If the current mirrorlist is less than this many seconds old then Yum will not download another copy of the mirrorlist, it has the same extra format as metadata_expire. If you find that Yum is not downloading the mirrorlists as often as you would like lower the value of this option. You can also change from the default of using seconds to using days, hours or minutes by appending a `d`, `h` or `m` respectively.",
133
- validation_message: "The mirror_expire property must be a numeric value for time in seconds, the string 'never', or a numeric value appended with with `d`, `h`, or `m`!"
132
+ description: "Time (in seconds) after which the mirrorlist locally cached will expire. If the current mirrorlist is less than this many seconds old then Yum will not download another copy of the mirrorlist, it has the same extra format as metadata_expire. If you find that Yum is not downloading the mirrorlists as often as you would like lower the value of this option. You can also change from the default of using seconds to using days, hours or minutes by appending a `d`, `h` or `m` respectively.",
133
+ validation_message: "The mirror_expire property must be a numeric value for time in seconds, the string 'never', or a numeric value appended with with `d`, `h`, or `m`!"
134
134
 
135
135
  property :mirrorlist_expire, String, regex: [/^\d+$/, /^\d+[mhd]$/],
136
- description: "Specifies the time (in seconds) after which the mirrorlist locally cached will expire. If the current mirrorlist is less than the value specified, then Yum will not download another copy of the mirrorlist. You can also change from the default of using seconds to using days, hours or minutes by appending a `d`, `h` or `m` respectively.",
137
- validation_message: "The mirrorlist_expire property must be a numeric value for time in seconds, the string 'never', or a numeric value appended with with `d`, `h`, or `m`!"
136
+ description: "Specifies the time (in seconds) after which the mirrorlist locally cached will expire. If the current mirrorlist is less than the value specified, then Yum will not download another copy of the mirrorlist. You can also change from the default of using seconds to using days, hours or minutes by appending a `d`, `h` or `m` respectively.",
137
+ validation_message: "The mirrorlist_expire property must be a numeric value for time in seconds, the string 'never', or a numeric value appended with with `d`, `h`, or `m`!"
138
138
 
139
139
  property :mirrorlist, String,
140
140
  description: "URL to a file containing a list of baseurls. This can be used instead of or with the baseurl option. Substitution variables, described below, can be used with this option."
@@ -146,14 +146,14 @@ class Chef
146
146
  property :options, Hash,
147
147
  description: "Specifies the repository options."
148
148
 
149
- property :password, String,
149
+ property :password, String, sensitive: true,
150
150
  description: "Password to use with the username for basic authentication."
151
151
 
152
152
  property :priority, String, regex: /^(\d?[1-9]|[0-9][0-9])$/,
153
- description: "Assigns a priority to a repository where the priority value is between `1` and `99` inclusive. Priorities are used to enforce ordered protection of repositories. Packages from repositories with a lower priority (higher numerical value) will never be used to upgrade packages that were installed from a repository with a higher priority (lower numerical value). The repositories with the lowest numerical priority number have the highest priority.",
154
- validation_message: "The priority property must be a numeric value from 1-99!"
153
+ description: "Assigns a priority to a repository where the priority value is between `1` and `99` inclusive. Priorities are used to enforce ordered protection of repositories. Packages from repositories with a lower priority (higher numerical value) will never be used to upgrade packages that were installed from a repository with a higher priority (lower numerical value). The repositories with the lowest numerical priority number have the highest priority.",
154
+ validation_message: "The priority property must be a numeric value from 1-99!"
155
155
 
156
- property :proxy_password, String,
156
+ property :proxy_password, String, sensitive: true,
157
157
  description: "Password for this proxy."
158
158
 
159
159
  property :proxy_username, String,
@@ -169,9 +169,9 @@ class Chef
169
169
  description: "Determines whether to report the instance ID when using Amazon Linux AMIs and repositories."
170
170
 
171
171
  property :repositoryid, String, regex: [%r{^[^/]+$}],
172
- description: "An optional property to set the repository name if it differs from the resource block's name.",
173
- validation_message: "repositoryid property cannot contain a forward slash '/'",
174
- name_property: true
172
+ description: "An optional property to set the repository name if it differs from the resource block's name.",
173
+ validation_message: "repositoryid property cannot contain a forward slash '/'",
174
+ name_property: true
175
175
 
176
176
  property :skip_if_unavailable, [TrueClass, FalseClass],
177
177
  description: "Allow yum to continue if this repository cannot be contacted for any reason."
@@ -195,8 +195,8 @@ class Chef
195
195
  description: "Enable bandwidth throttling for downloads."
196
196
 
197
197
  property :timeout, String, regex: /^\d+$/,
198
- description: "Number of seconds to wait for a connection before timing out. Defaults to 30 seconds. This may be too short of a time for extremely overloaded sites.",
199
- validation_message: "The timeout property must be a numeric value!"
198
+ description: "Number of seconds to wait for a connection before timing out. Defaults to 30 seconds. This may be too short of a time for extremely overloaded sites.",
199
+ validation_message: "The timeout property must be a numeric value!"
200
200
 
201
201
  property :username, String,
202
202
  description: "Username to use for basic authentication to a repository."
data/lib/chef/resource.rb CHANGED
@@ -255,7 +255,7 @@ class Chef
255
255
  when "before"
256
256
  notifies_before(action, resource)
257
257
  else
258
- raise ArgumentError, "invalid timing: #{timing} for notifies(#{action}, #{resources.inspect}, #{timing}) resource #{self} "\
258
+ raise ArgumentError, "invalid timing: #{timing} for notifies(#{action}, #{resources.inspect}, #{timing}) resource #{self} " \
259
259
  "Valid timings are: :delayed, :immediate, :immediately, :before"
260
260
  end
261
261
  end
@@ -170,12 +170,11 @@ class Chef
170
170
  rescue Chef::Exceptions::ResourceNotFound => e
171
171
  if arg =~ MULTIPLE_RESOURCE_MATCH
172
172
  begin
173
- results = []
174
173
  resource_type = $1
175
174
  arg =~ /^.+\[(.+)\]$/
176
175
  resource_list = $1
177
- resource_list.split(",").each do |instance_name|
178
- results << lookup(create_key(resource_type, instance_name))
176
+ results = resource_list.split(",").map do |instance_name|
177
+ lookup(create_key(resource_type, instance_name))
179
178
  end
180
179
  Chef.deprecated(:multiresource_match, "The resource_collection multi-resource syntax is deprecated")
181
180
  return results
@@ -85,8 +85,7 @@ class Chef
85
85
  # Here we do some magic to extract resources from files where there are multiple resources
86
86
  # in a file - to do this, we load the file, and take the delta of which resources
87
87
  # exist in object space
88
- existing_classes = []
89
- ObjectSpace.each_object(Class).select { |k| k < Chef::Resource }.each { |klass| existing_classes << klass }
88
+ existing_classes = ObjectSpace.each_object(Class).select { |k| k < Chef::Resource }.map { |klass| klass }
90
89
  # Load the set of resources from this file
91
90
  Chef::Resource::LWRPBase.build_from_file(name, pth, Chef::RunContext.new(Chef::Node.new, nil, nil))
92
91
  # Finally, process every new class added to the object space by that
@@ -318,7 +318,7 @@ class Chef
318
318
  #
319
319
  def add_delayed_action(notification)
320
320
  if delayed_actions.any? { |existing_notification| existing_notification.duplicates?(notification) }
321
- logger.info( "#{notification.notifying_resource} not queuing delayed action #{notification.action} on #{notification.resource}"\
321
+ logger.info( "#{notification.notifying_resource} not queuing delayed action #{notification.action} on #{notification.resource}" \
322
322
  " (delayed), as it's already been queued")
323
323
  else
324
324
  delayed_actions << notification
@@ -415,7 +415,7 @@ class Chef
415
415
  Recipe `#{recipe_name}` is not in the run_list, and cookbook '#{cookbook_name}'
416
416
  is not a dependency of any cookbook in the run_list. To load this recipe,
417
417
  first add a dependency of the cookbook '#{cookbook_name}' into the metadata
418
- of the cookbook which depends on '#{cookbook_name}'.
418
+ of the cookbook which depends on '#{cookbook_name}'.
419
419
  ERROR_MESSAGE
420
420
  end
421
421
 
data/lib/chef/runner.rb CHANGED
@@ -161,7 +161,7 @@ class Chef
161
161
  end
162
162
 
163
163
  def run_delayed_notification(notification)
164
- Chef::Log.info( "#{notification.notifying_resource} sending #{notification.action}"\
164
+ Chef::Log.info( "#{notification.notifying_resource} sending #{notification.action}" \
165
165
  " action to #{notification.resource} (delayed)")
166
166
  # notifications may have lazy strings in them to resolve
167
167
  notification.resolve_resource_reference(run_context.resource_collection)
@@ -54,4 +54,3 @@ class Chef
54
54
  end
55
55
  end
56
56
  end
57
-
@@ -131,4 +131,3 @@ class Chef
131
131
  end
132
132
  end
133
133
  end
134
-
@@ -239,9 +239,9 @@ module Shell
239
239
 
240
240
  desc "returns an object to control a paused #{ChefUtils::Dist::Infra::PRODUCT} run"
241
241
  subcommands resume: "resume the #{ChefUtils::Dist::Infra::PRODUCT} run",
242
- step: "run only the next resource",
243
- skip_back: "move back in the run list",
244
- skip_forward: "move forward in the run list"
242
+ step: "run only the next resource",
243
+ skip_back: "move back in the run list",
244
+ skip_forward: "move forward in the run list"
245
245
  def chef_run
246
246
  Shell.session.resource_collection.iterator
247
247
  end
@@ -393,17 +393,17 @@ module Shell
393
393
  This will strip the admin privileges from any client named after borat.
394
394
  E
395
395
  subcommands all: "list all api clients",
396
- show: "load an api client by name",
397
- search: "search for API clients",
398
- transform: "edit all api clients via a code block and save them"
396
+ show: "load an api client by name",
397
+ search: "search for API clients",
398
+ transform: "edit all api clients via a code block and save them"
399
399
  def clients
400
400
  @clients ||= Shell::ModelWrapper.new(Chef::ApiClient, :client)
401
401
  end
402
402
 
403
403
  desc "Find and edit cookbooks"
404
404
  subcommands all: "list all cookbooks",
405
- show: "load a cookbook by name",
406
- transform: "edit all cookbooks via a code block and save them"
405
+ show: "load a cookbook by name",
406
+ transform: "edit all cookbooks via a code block and save them"
407
407
  def cookbooks
408
408
  @cookbooks ||= Shell::ModelWrapper.new(Chef::CookbookVersion)
409
409
  end
@@ -455,9 +455,9 @@ module Shell
455
455
  This will assign the attribute to every node with a FQDN matching the regex.
456
456
  E
457
457
  subcommands all: "list all nodes",
458
- show: "load a node by name",
459
- search: "search for nodes",
460
- transform: "edit all nodes via a code block and save them"
458
+ show: "load a node by name",
459
+ search: "search for nodes",
460
+ transform: "edit all nodes via a code block and save them"
461
461
  def nodes
462
462
  @nodes ||= Shell::ModelWrapper.new(Chef::Node)
463
463
  end
@@ -477,9 +477,9 @@ module Shell
477
477
  See the help for +nodes+ for more information about the subcommands.
478
478
  E
479
479
  subcommands all: "list all roles",
480
- show: "load a role by name",
481
- search: "search for roles",
482
- transform: "edit all roles via a code block and save them"
480
+ show: "load a role by name",
481
+ search: "search for roles",
482
+ transform: "edit all roles via a code block and save them"
483
483
  def roles
484
484
  @roles ||= Shell::ModelWrapper.new(Chef::Role)
485
485
  end
@@ -503,9 +503,9 @@ module Shell
503
503
 
504
504
  E
505
505
  subcommands all: "list all items in the data bag",
506
- show: "load a data bag item by id",
507
- search: "search for items in the data bag",
508
- transform: "edit all items via a code block and save them"
506
+ show: "load a data bag item by id",
507
+ search: "search for items in the data bag",
508
+ transform: "edit all items via a code block and save them"
509
509
  def databags(databag_name)
510
510
  @named_databags_wrappers ||= {}
511
511
  @named_databags_wrappers[databag_name] ||= Shell::NamedDataBagWrapper.new(databag_name)
@@ -526,9 +526,9 @@ module Shell
526
526
  See the help for +nodes+ for more information about the subcommands.
527
527
  E
528
528
  subcommands all: "list all environments",
529
- show: "load an environment by name",
530
- search: "search for environments",
531
- transform: "edit all environments via a code block and save them"
529
+ show: "load an environment by name",
530
+ search: "search for environments",
531
+ transform: "edit all environments via a code block and save them"
532
532
  def environments
533
533
  @environments ||= Shell::ModelWrapper.new(Chef::Environment)
534
534
  end
@@ -268,7 +268,7 @@ module Shell
268
268
 
269
269
  def register
270
270
  @rest = Chef::ServerAPI.new(Chef::Config[:chef_server_url], client_name: Chef::Config[:node_name],
271
- signing_key_filename: Chef::Config[:client_key])
271
+ signing_key_filename: Chef::Config[:client_key])
272
272
  end
273
273
 
274
274
  end
data/lib/chef/shell.rb CHANGED
@@ -72,6 +72,13 @@ module Shell
72
72
  # to get access to the main object before irb starts.
73
73
  ::IRB.setup(nil)
74
74
 
75
+ # Apply Windows AltGr input fix for affected Reline versions (< 0.3.2).
76
+ # European keyboard layouts (e.g. German) use AltGr (Ctrl+Alt) to produce
77
+ # characters such as { } [ ]. Without this patch Reline emits a spurious ESC
78
+ # prefix making chef-shell unusable for those users. Safe no-op on non-Windows
79
+ # and on Reline versions where the upstream fix is already present.
80
+ require_relative "monkey_patches/reline-windows"
81
+
75
82
  irb_conf[:USE_COLORIZE] = options.config[:use_colorize]
76
83
  irb_conf[:USE_SINGLELINE] = options.config[:use_singleline]
77
84
  irb_conf[:USE_MULTILINE] = options.config[:use_multiline]