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
@@ -375,6 +375,8 @@ class Chef
375
375
  cmd = "#{@gem_binary_location} list #{gem_dependency.name} --remote --all #{source_args}"
376
376
  result = shell_out!(cmd)
377
377
 
378
+ target_platforms = nil
379
+
378
380
  versions = []
379
381
  result.stdout.each_line do |line|
380
382
  next unless line.start_with?("#{gem_dependency.name} (")
@@ -383,10 +385,31 @@ class Chef
383
385
  next unless version_string
384
386
 
385
387
  version_string.split(/,\s*/).each do |v|
386
- version = Gem::Version.new(v.strip)
388
+ # `gem list --remote --all` emits entries like "1.6.0 x86_64-linux".
389
+ # Accept platform-specific tokens only when the platform is compatible
390
+ # with the target gem environment; pure-Ruby tokens have no suffix and
391
+ # are always accepted.
392
+ version_token, *platform_tokens = v.strip.split(/\s+/)
393
+
394
+ if platform_tokens.any?
395
+ target_platforms ||= gem_platforms
396
+ # Each comma-separated entry from `gem list --remote --all` can list
397
+ # multiple platforms for one version: "1.5.9 ruby x86_64-linux aarch64-linux ...".
398
+ # Accept if any listed platform is "ruby" (pure-Ruby) or matches the target env.
399
+ compatible = platform_tokens.any? do |pt|
400
+ pt == "ruby" || target_platforms.any? do |p|
401
+ Gem::Platform.new(p) === Gem::Platform.new(pt)
402
+ rescue ArgumentError
403
+ false
404
+ end
405
+ end
406
+ next unless compatible
407
+ end
408
+
409
+ version = Gem::Version.new(version_token)
387
410
  versions << version if gem_dependency.requirement.satisfied_by?(version)
388
411
  rescue ArgumentError
389
- # Skip invalid versions
412
+ # Skip tokens with invalid version strings.
390
413
  end
391
414
  end
392
415
 
@@ -135,7 +135,7 @@ class Chef
135
135
  "Accept: application/json\r\n" +
136
136
  "Content-Type: application/json\r\n"
137
137
  if method == "POST"
138
- pdata = post_data.to_json.to_s
138
+ pdata = post_data.to_json
139
139
  request.concat("Content-Length: #{pdata.bytesize}\r\n\r\n#{pdata}")
140
140
  end
141
141
  request.concat("\r\n")
@@ -92,7 +92,7 @@ class Chef
92
92
 
93
93
  def current_installed_version
94
94
  @current_installed_version ||=
95
- if uninstall_entries.count != 0
95
+ if uninstall_entries.any?
96
96
  uninstall_entries.map(&:display_version).uniq
97
97
  end
98
98
  end
@@ -52,7 +52,7 @@ class Chef
52
52
  logger.trace("#{new_resource} checking package status and version for #{product_code}")
53
53
  get_installed_version(product_code)
54
54
  else
55
- if uninstall_entries.count != 0
55
+ if uninstall_entries.any?
56
56
  uninstall_entries.map(&:display_version).uniq
57
57
  end
58
58
  end
@@ -78,12 +78,12 @@ class Chef
78
78
 
79
79
  def isalpha(x)
80
80
  v = x.ord
81
- (v >= 65 && v <= 90) || (v >= 97 && v <= 122)
81
+ (v.between?(65, 90)) || (v.between?(97, 122))
82
82
  end
83
83
 
84
84
  def isdigit(x)
85
85
  v = x.ord
86
- v >= 48 && v <= 57
86
+ v.between?(48, 57)
87
87
  end
88
88
 
89
89
  # based on the reference spec in lib/rpmvercmp.c in rpm 4.9.0
@@ -38,7 +38,7 @@ class Chef
38
38
  use_package_name_for_source
39
39
  use_magic_version
40
40
 
41
- provides :package, platform_family: "fedora_derived"
41
+ provides :package, platform_family: %w{fedora rhel amazon}
42
42
 
43
43
  provides :yum_package
44
44
 
@@ -204,91 +204,91 @@ class Chef
204
204
  # very slightly different semantics.
205
205
  def powershell_wrapper_script
206
206
  <<~EOH
207
- # Chef Client wrapper for powershell_script resources
208
-
209
- # In rare cases, such as when PowerShell is executed
210
- # as an alternate user, the new-variable cmdlet is not
211
- # available, so import it just in case
212
- if ( get-module -ListAvailable Microsoft.PowerShell.Utility )
213
- {
214
- Import-Module Microsoft.PowerShell.Utility
215
- }
216
-
217
- # LASTEXITCODE can be uninitialized -- make it explicitly 0
218
- # to avoid incorrect detection of failure (non-zero) codes
219
- $global:LASTEXITCODE = 0
220
-
221
- # Catch any exceptions -- without this, exceptions will result
222
- # In a zero return code instead of the desired non-zero code
223
- # that indicates a failure
224
-
225
- #{if new_resource.use_inline_powershell
226
- # Inline powershell doesn't allow for private visibility variables,
227
- # and uses return instead of exit
228
- <<-EOI
229
- trap [Exception] {write-error ($_.Exception.Message);return 1}
230
- $interpolatedexitcode = $#{new_resource.convert_boolean_return}
231
- EOI
232
- else
233
- <<-EOI
234
- trap [Exception] {write-error ($_.Exception.Message);exit 1}
235
-
236
- # Variable state that should not be accessible to the user code
237
- new-variable -name interpolatedexitcode -visibility private -value $#{new_resource.convert_boolean_return}
238
- new-variable -name chefscriptresult -visibility private
239
- EOI
240
- end}
241
- # Initialize a variable we use to capture $? inside a block
242
- $global:lastcmdlet = $null
243
-
244
- # Execute the user's code in a script block --
245
- $chefscriptresult =
246
- {
247
- #{new_resource.code}
248
-
249
- # This assignment doesn't affect the block's return value
250
- $global:lastcmdlet = $?
251
- }.invokereturnasis()
252
-
253
- # Assume failure status of 1 -- success cases
254
- # will have to override this
255
- $exitstatus = 1
256
-
257
- # If convert_boolean_return is enabled, the block's return value
258
- # gets precedence in determining our exit status
259
- if ($interpolatedexitcode -and $chefscriptresult -ne $null -and $chefscriptresult.gettype().name -eq 'boolean')
260
- {
261
- $exitstatus = [int32](!$chefscriptresult)
262
- }
263
- elseif ($lastcmdlet)
264
- {
265
- # Otherwise, a successful cmdlet execution defines the status
266
- $exitstatus = 0
267
- }
268
- elseif ( $LASTEXITCODE -ne $null -and $LASTEXITCODE -ne 0 )
269
- {
270
- # If the cmdlet status is failed, allow the Win32 status
271
- # in $LASTEXITCODE to define exit status. This handles the case
272
- # where no cmdlets, only Win32 processes have run since $?
273
- # will be set to $false whenever a Win32 process returns a non-zero
274
- # status.
275
- $exitstatus = $LASTEXITCODE
207
+ # Chef Client wrapper for powershell_script resources
208
+
209
+ # In rare cases, such as when PowerShell is executed
210
+ # as an alternate user, the new-variable cmdlet is not
211
+ # available, so import it just in case
212
+ if ( get-module -ListAvailable Microsoft.PowerShell.Utility )
213
+ {
214
+ Import-Module Microsoft.PowerShell.Utility
215
+ }
216
+
217
+ # LASTEXITCODE can be uninitialized -- make it explicitly 0
218
+ # to avoid incorrect detection of failure (non-zero) codes
219
+ $global:LASTEXITCODE = 0
220
+
221
+ # Catch any exceptions -- without this, exceptions will result
222
+ # In a zero return code instead of the desired non-zero code
223
+ # that indicates a failure
224
+
225
+ #{if new_resource.use_inline_powershell
226
+ # Inline powershell doesn't allow for private visibility variables,
227
+ # and uses return instead of exit
228
+ <<-EOI
229
+ trap [Exception] {write-error ($_.Exception.Message);return 1}
230
+ $interpolatedexitcode = $#{new_resource.convert_boolean_return}
231
+ EOI
232
+ else
233
+ <<-EOI
234
+ trap [Exception] {write-error ($_.Exception.Message);exit 1}
235
+
236
+ # Variable state that should not be accessible to the user code
237
+ new-variable -name interpolatedexitcode -visibility private -value $#{new_resource.convert_boolean_return}
238
+ new-variable -name chefscriptresult -visibility private
239
+ EOI
240
+ end}
241
+ # Initialize a variable we use to capture $? inside a block
242
+ $global:lastcmdlet = $null
243
+
244
+ # Execute the user's code in a script block --
245
+ $chefscriptresult =
246
+ {
247
+ #{new_resource.code}
248
+
249
+ # This assignment doesn't affect the block's return value
250
+ $global:lastcmdlet = $?
251
+ }.invokereturnasis()
252
+
253
+ # Assume failure status of 1 -- success cases
254
+ # will have to override this
255
+ $exitstatus = 1
256
+
257
+ # If convert_boolean_return is enabled, the block's return value
258
+ # gets precedence in determining our exit status
259
+ if ($interpolatedexitcode -and $chefscriptresult -ne $null -and $chefscriptresult.gettype().name -eq 'boolean')
260
+ {
261
+ $exitstatus = [int32](!$chefscriptresult)
262
+ }
263
+ elseif ($lastcmdlet)
264
+ {
265
+ # Otherwise, a successful cmdlet execution defines the status
266
+ $exitstatus = 0
267
+ }
268
+ elseif ( $LASTEXITCODE -ne $null -and $LASTEXITCODE -ne 0 )
269
+ {
270
+ # If the cmdlet status is failed, allow the Win32 status
271
+ # in $LASTEXITCODE to define exit status. This handles the case
272
+ # where no cmdlets, only Win32 processes have run since $?
273
+ # will be set to $false whenever a Win32 process returns a non-zero
274
+ # status.
275
+ $exitstatus = $LASTEXITCODE
276
+ }
277
+
278
+ # Print STDOUT for the script execution
279
+ Write-Output $chefscriptresult
280
+
281
+ # If this script is launched with -File, the process exit
282
+ # status of PowerShell.exe will be $exitstatus. If it was
283
+ # launched with -Command, it will be 0 if $exitstatus was 0,
284
+ # 1 (i.e. failed) otherwise.
285
+ #{if new_resource.use_inline_powershell
286
+ # Inline powershell needs return, not exit
287
+ "return $exitstatus\n"
288
+ else
289
+ "exit $exitstatus\n"
290
+ end
276
291
  }
277
-
278
- # Print STDOUT for the script execution
279
- Write-Output $chefscriptresult
280
-
281
- # If this script is launched with -File, the process exit
282
- # status of PowerShell.exe will be $exitstatus. If it was
283
- # launched with -Command, it will be 0 if $exitstatus was 0,
284
- # 1 (i.e. failed) otherwise.
285
- #{if new_resource.use_inline_powershell
286
- # Inline powershell needs return, not exit
287
- "return $exitstatus\n"
288
- else
289
- "exit $exitstatus\n"
290
- end
291
- }
292
292
  EOH
293
293
  end
294
294
 
@@ -91,11 +91,9 @@ class Chef
91
91
 
92
92
  def get_priority
93
93
  priority = {}
94
- rc_files = []
95
-
96
94
  levels = parse_init_file(@init_command)
97
- levels.each do |level|
98
- rc_files.push Dir.glob("/etc/rc#{level}.d/[SK][0-9][0-9]#{current_resource.service_name}")
95
+ rc_files = levels.map do |level|
96
+ Dir.glob("/etc/rc#{level}.d/[SK][0-9][0-9]#{current_resource.service_name}")
99
97
  end
100
98
 
101
99
  rc_files.flatten.each do |line|
@@ -429,7 +429,7 @@ in 'password', with the associated 'salt' and 'iterations'.")
429
429
  # Unlocks the user
430
430
  #
431
431
  def unlock_user
432
- auth_string = authentication_authority.gsub(/AuthenticationAuthority: /, "").gsub(/;DisabledUser;/, "").strip
432
+ auth_string = authentication_authority.gsub("AuthenticationAuthority: ", "").gsub(";DisabledUser;", "").strip
433
433
  run_dscl("create", "/Users/#{new_resource.username}", "AuthenticationAuthority", auth_string)
434
434
  end
435
435
 
@@ -307,7 +307,7 @@ class Chef
307
307
 
308
308
  def remove_user
309
309
  cmd = ["-deleteUser", new_resource.username]
310
- cmd << new_resource.manage_home ? "-secure" : "-keepHome"
310
+ cmd << new_resource.manage_home ? "-secure" : "-keepHome" # rubocop:disable Lint/Void
311
311
  if %i{admin_username admin_password}.all? { |p| prop_is_set?(p) }
312
312
  cmd += ["-adminUser", new_resource.admin_username]
313
313
  cmd += ["-adminPassword", new_resource.admin_password]
@@ -94,7 +94,7 @@ class Chef
94
94
  acl = Chef::ReservedNames::Win32::Security::ACL.create(aces)
95
95
 
96
96
  # This actually applies the modified DACL to the file
97
- # Use parentheses to bypass RuboCop / ChefStyle warning
97
+ # Use parentheses to bypass RuboCop / Cookstyle warning
98
98
  # about useless setter
99
99
  (securable_object.dacl = acl)
100
100
  end
@@ -86,7 +86,7 @@ action :delete do
86
86
  end
87
87
  else
88
88
  logger.debug format("REST resource %<name>s of type %<type>s does not exist. Skipping.",
89
- type: new_resource.name, name: id_property)
89
+ type: new_resource.name, name: id_property)
90
90
  end
91
91
  end
92
92
 
@@ -174,13 +174,15 @@ action_class do
174
174
  end
175
175
 
176
176
  def rest_url_collection
177
- current_resource.class.rest_api_collection
177
+ endpoint = current_resource.class.rest_api_endpoint || ""
178
+ "#{endpoint}#{current_resource.class.rest_api_collection}"
178
179
  end
179
180
 
180
181
  # Resource document URL after RFC 6570 template evaluation via properties substitution
181
182
  def rest_url_document
183
+ endpoint = current_resource.class.rest_api_endpoint || ""
182
184
  template = ::Addressable::Template.new(current_resource.class.rest_api_document)
183
- template.expand(property_map).to_s
185
+ "#{endpoint}#{template.expand(property_map)}"
184
186
  end
185
187
 
186
188
  # Convenience method for conditional requires
@@ -198,9 +200,9 @@ action_class do
198
200
  end
199
201
 
200
202
  message = format("Setting property :%<property>s requires properties :%<properties>s to be set as well on resource %<resource_name>s",
201
- property: property,
202
- properties: dependent_properties.join(", :"),
203
- resource_name: current_resource.to_s)
203
+ property: property,
204
+ properties: dependent_properties.join(", :"),
205
+ resource_name: current_resource.to_s)
204
206
 
205
207
  a.failure_message message
206
208
  end
@@ -376,7 +378,7 @@ action_class do
376
378
  arr = path.split(".")
377
379
  ret = {}
378
380
 
379
- if arr.count == 1
381
+ if arr.one?
380
382
  ret[arr.first] = value
381
383
 
382
384
  ret
@@ -28,54 +28,54 @@ class Chef
28
28
  description "Use the **alternatives** resource to configure command alternatives in Linux using the alternatives or update-alternatives packages."
29
29
  introduced "16.0"
30
30
  examples <<~DOC
31
- **Install an alternative**:
32
-
33
- ```ruby
34
- alternatives 'python install 2' do
35
- link_name 'python'
36
- path '/usr/bin/python2.7'
37
- priority 100
38
- action :install
39
- end
40
- ```
31
+ **Install an alternative**:
32
+
33
+ ```ruby
34
+ alternatives 'python install 2' do
35
+ link_name 'python'
36
+ path '/usr/bin/python2.7'
37
+ priority 100
38
+ action :install
39
+ end
40
+ ```
41
41
 
42
- **Set an alternative**:
42
+ **Set an alternative**:
43
43
 
44
- ```ruby
45
- alternatives 'python set version 3' do
46
- link_name 'python'
47
- path '/usr/bin/python3'
48
- action :set
49
- end
50
- ```
44
+ ```ruby
45
+ alternatives 'python set version 3' do
46
+ link_name 'python'
47
+ path '/usr/bin/python3'
48
+ action :set
49
+ end
50
+ ```
51
51
 
52
- **Set the automatic alternative state**:
52
+ **Set the automatic alternative state**:
53
53
 
54
- ```ruby
55
- alternatives 'python auto' do
56
- link_name 'python'
57
- action :auto
58
- end
59
- ```
54
+ ```ruby
55
+ alternatives 'python auto' do
56
+ link_name 'python'
57
+ action :auto
58
+ end
59
+ ```
60
60
 
61
- **Refresh an alternative**:
61
+ **Refresh an alternative**:
62
62
 
63
- ```ruby
64
- alternatives 'python refresh' do
65
- link_name 'python'
66
- action :refresh
67
- end
68
- ```
63
+ ```ruby
64
+ alternatives 'python refresh' do
65
+ link_name 'python'
66
+ action :refresh
67
+ end
68
+ ```
69
69
 
70
- **Remove an alternative**:
70
+ **Remove an alternative**:
71
71
 
72
- ```ruby
73
- alternatives 'python remove' do
74
- link_name 'python'
75
- path '/usr/bin/python3'
76
- action :remove
77
- end
78
- ```
72
+ ```ruby
73
+ alternatives 'python remove' do
74
+ link_name 'python'
75
+ path '/usr/bin/python3'
76
+ action :remove
77
+ end
78
+ ```
79
79
  DOC
80
80
 
81
81
  property :link_name, String,
@@ -91,7 +91,7 @@ class Chef
91
91
  description: "The absolute path to the original application binary such as `/usr/bin/ruby27`."
92
92
 
93
93
  property :priority, [String, Integer],
94
- coerce: proc { |n| n.to_i },
94
+ coerce: proc(&:to_i),
95
95
  description: "The priority of the alternative."
96
96
 
97
97
  def define_resource_requirements
@@ -25,48 +25,48 @@ class Chef
25
25
  provides :apt_package, target_mode: true
26
26
  provides :package, platform_family: "debian", target_mode: true
27
27
  examples <<~DOC
28
- **Install a package using package manager**:
28
+ **Install a package using package manager**:
29
29
 
30
- ```ruby
31
- apt_package 'name of package' do
32
- action :install
33
- end
34
- ```
30
+ ```ruby
31
+ apt_package 'name of package' do
32
+ action :install
33
+ end
34
+ ```
35
35
 
36
- **Install a package without specifying the default action**:
36
+ **Install a package without specifying the default action**:
37
37
 
38
- ```ruby
39
- apt_package 'name of package'
40
- ```
38
+ ```ruby
39
+ apt_package 'name of package'
40
+ ```
41
41
 
42
- **Install multiple packages at once**:
42
+ **Install multiple packages at once**:
43
43
 
44
- ```ruby
45
- apt_package %w(package1 package2 package3)
46
- ```
44
+ ```ruby
45
+ apt_package %w(package1 package2 package3)
46
+ ```
47
47
 
48
- **Install without using recommend packages as a dependency**:
48
+ **Install without using recommend packages as a dependency**:
49
49
 
50
- ```ruby
51
- package 'apache2' do
52
- options '--no-install-recommends'
53
- end
54
- ```
50
+ ```ruby
51
+ package 'apache2' do
52
+ options '--no-install-recommends'
53
+ end
54
+ ```
55
55
 
56
- **Prevent the apt_package resource from installing packages with pattern matching names**:
56
+ **Prevent the apt_package resource from installing packages with pattern matching names**:
57
57
 
58
- By default, the apt_package resource will install the named package.
59
- If it can't find a package with the exact same name, it will treat the package name as regular expression string and match with any package that matches that regular expression.
60
- This may lead Chef Infra Client to install one or more packages with names that match that regular expression.
58
+ By default, the apt_package resource will install the named package.
59
+ If it can't find a package with the exact same name, it will treat the package name as regular expression string and match with any package that matches that regular expression.
60
+ This may lead Chef Infra Client to install one or more packages with names that match that regular expression.
61
61
 
62
- In this example, `anchor_package_regex true` prevents the apt_package resource from installing matching packages if it can't find the `lua5.3` package.
62
+ In this example, `anchor_package_regex true` prevents the apt_package resource from installing matching packages if it can't find the `lua5.3` package.
63
63
 
64
- ```ruby
65
- apt_package 'lua5.3' do
66
- version '5.3.3-1.1ubuntu2'
67
- anchor_package_regex true
68
- end
69
- ```
64
+ ```ruby
65
+ apt_package 'lua5.3' do
66
+ version '5.3.3-1.1ubuntu2'
67
+ anchor_package_regex true
68
+ end
69
+ ```
70
70
  DOC
71
71
 
72
72
  description "Use the **apt_package** resource to manage packages on Debian, Ubuntu, and other platforms that use the APT package system."
@@ -27,34 +27,34 @@ class Chef
27
27
  description "Use the **apt_preference** resource to create APT [preference files](https://wiki.debian.org/AptPreferences). Preference files are used to control which package versions and sources are prioritized during installation."
28
28
  introduced "13.3"
29
29
  examples <<~DOC
30
- **Pin libmysqlclient16 to a version 5.1.49-3**:
30
+ **Pin libmysqlclient16 to a version 5.1.49-3**:
31
31
 
32
- ```ruby
33
- apt_preference 'libmysqlclient16' do
34
- pin 'version 5.1.49-3'
35
- pin_priority '700'
36
- end
37
- ```
32
+ ```ruby
33
+ apt_preference 'libmysqlclient16' do
34
+ pin 'version 5.1.49-3'
35
+ pin_priority '700'
36
+ end
37
+ ```
38
38
 
39
- Note: The `pin_priority` of `700` ensures that this version will be preferred over any other available versions.
39
+ Note: The `pin_priority` of `700` ensures that this version will be preferred over any other available versions.
40
40
 
41
- **Unpin a libmysqlclient16**:
41
+ **Unpin a libmysqlclient16**:
42
42
 
43
- ```ruby
44
- apt_preference 'libmysqlclient16' do
45
- action :remove
46
- end
47
- ```
43
+ ```ruby
44
+ apt_preference 'libmysqlclient16' do
45
+ action :remove
46
+ end
47
+ ```
48
48
 
49
- **Pin all packages to prefer the packages.dotdeb.org repository**:
49
+ **Pin all packages to prefer the packages.dotdeb.org repository**:
50
50
 
51
- ```ruby
52
- apt_preference 'dotdeb' do
53
- glob '*'
54
- pin 'origin packages.dotdeb.org'
55
- pin_priority '700'
56
- end
57
- ```
51
+ ```ruby
52
+ apt_preference 'dotdeb' do
53
+ glob '*'
54
+ pin 'origin packages.dotdeb.org'
55
+ pin_priority '700'
56
+ end
57
+ ```
58
58
  DOC
59
59
 
60
60
  property :package_name, String,
@@ -201,7 +201,7 @@ class Chef
201
201
  # @return [Array] an array of fingerprints
202
202
  def extract_fingerprints_from_cmd(*cmd)
203
203
  so = shell_out(*cmd)
204
- so.stdout.split(/\n/).map do |t|
204
+ so.stdout.split("\n").map do |t|
205
205
  if z = t.match(/^fpr:+([0-9A-F]+):/)
206
206
  z[1].split.join
207
207
  end
@@ -218,7 +218,7 @@ class Chef
218
218
  so = shell_out(*cmd)
219
219
  # Sample output
220
220
  # pub:-:4096:1:D94AA3F0EFE21092:1336774248:::-:::scSC::::::23::0:
221
- so.stdout.split(/\n/).map do |t|
221
+ so.stdout.split("\n").map do |t|
222
222
  if t.match(/^pub:/)
223
223
  f = t.split(":")
224
224
  f.slice(0, 6).join(":")