chef 12.18.31 → 12.19.33

Sign up to get free protection for your applications and to get access to all the features.
Files changed (305) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +5 -4
  3. data/README.md +12 -13
  4. data/VERSION +1 -1
  5. data/acceptance/Gemfile +4 -4
  6. data/acceptance/Gemfile.lock +70 -69
  7. data/chef-universal-mingw32.gemspec +2 -3
  8. data/chef.gemspec +6 -6
  9. data/lib/chef/api_client.rb +8 -10
  10. data/lib/chef/api_client_v1.rb +9 -11
  11. data/lib/chef/application/apply.rb +8 -10
  12. data/lib/chef/application/client.rb +1 -1
  13. data/lib/chef/application/exit_code.rb +3 -5
  14. data/lib/chef/application/knife.rb +2 -2
  15. data/lib/chef/application/windows_service.rb +29 -30
  16. data/lib/chef/application/windows_service_manager.rb +1 -1
  17. data/lib/chef/audit/audit_event_proxy.rb +2 -2
  18. data/lib/chef/audit/control_group_data.rb +1 -1
  19. data/lib/chef/chef_class.rb +1 -0
  20. data/lib/chef/chef_fs/chef_fs_data_store.rb +5 -7
  21. data/lib/chef/chef_fs/command_line.rb +15 -16
  22. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +1 -1
  23. data/lib/chef/chef_fs/data_handler/container_data_handler.rb +1 -1
  24. data/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb +1 -1
  25. data/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +1 -1
  26. data/lib/chef/chef_fs/data_handler/environment_data_handler.rb +1 -1
  27. data/lib/chef/chef_fs/data_handler/group_data_handler.rb +1 -1
  28. data/lib/chef/chef_fs/data_handler/node_data_handler.rb +1 -1
  29. data/lib/chef/chef_fs/data_handler/organization_data_handler.rb +1 -1
  30. data/lib/chef/chef_fs/data_handler/role_data_handler.rb +1 -1
  31. data/lib/chef/chef_fs/data_handler/user_data_handler.rb +1 -1
  32. data/lib/chef/chef_fs/file_pattern.rb +2 -2
  33. data/lib/chef/chef_fs/file_system.rb +1 -1
  34. data/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb +5 -6
  35. data/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb +8 -10
  36. data/lib/chef/chef_fs/file_system/chef_server/data_bags_dir.rb +8 -10
  37. data/lib/chef/chef_fs/file_system/chef_server/nodes_dir.rb +10 -12
  38. data/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb +28 -30
  39. data/lib/chef/chef_fs/file_system/chef_server/policy_group_entry.rb +1 -1
  40. data/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb +27 -29
  41. data/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb +18 -24
  42. data/lib/chef/chef_fs/file_system/memory/memory_file.rb +1 -1
  43. data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +10 -12
  44. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb +10 -12
  45. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +9 -13
  46. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +2 -0
  47. data/lib/chef/chef_fs/file_system/repository/cookbooks_dir.rb +1 -1
  48. data/lib/chef/chef_fs/file_system/repository/nodes_dir.rb +3 -0
  49. data/lib/chef/chef_fs/parallelizer.rb +9 -11
  50. data/lib/chef/cookbook/cookbook_version_loader.rb +25 -31
  51. data/lib/chef/cookbook/metadata.rb +26 -26
  52. data/lib/chef/cookbook/syntax_check.rb +1 -1
  53. data/lib/chef/cookbook_version.rb +3 -3
  54. data/lib/chef/data_bag.rb +1 -1
  55. data/lib/chef/data_bag_item.rb +3 -3
  56. data/lib/chef/data_collector.rb +3 -4
  57. data/lib/chef/decorator.rb +1 -1
  58. data/lib/chef/deprecated.rb +30 -0
  59. data/lib/chef/dsl/audit.rb +2 -2
  60. data/lib/chef/dsl/declare_resource.rb +1 -1
  61. data/lib/chef/dsl/platform_introspection.rb +29 -31
  62. data/lib/chef/dsl/reboot_pending.rb +1 -1
  63. data/lib/chef/dsl/resources.rb +6 -8
  64. data/lib/chef/encrypted_data_bag_item.rb +2 -2
  65. data/lib/chef/environment.rb +9 -11
  66. data/lib/chef/event_loggers/windows_eventlog.rb +1 -1
  67. data/lib/chef/exceptions.rb +4 -1
  68. data/lib/chef/file_access_control/unix.rb +14 -14
  69. data/lib/chef/file_access_control/windows.rb +1 -1
  70. data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +4 -5
  71. data/lib/chef/formatters/error_mapper.rb +6 -6
  72. data/lib/chef/http/api_versions.rb +50 -0
  73. data/lib/chef/http/validate_content_length.rb +2 -2
  74. data/lib/chef/json_compat.rb +6 -10
  75. data/lib/chef/key.rb +5 -5
  76. data/lib/chef/knife.rb +4 -4
  77. data/lib/chef/knife/cookbook_site_install.rb +2 -2
  78. data/lib/chef/knife/core/cookbook_scm_repo.rb +2 -2
  79. data/lib/chef/knife/core/gem_glob_loader.rb +1 -1
  80. data/lib/chef/knife/core/status_presenter.rb +1 -1
  81. data/lib/chef/knife/core/ui.rb +19 -25
  82. data/lib/chef/knife/data_bag_secret_options.rb +1 -1
  83. data/lib/chef/knife/deps.rb +32 -34
  84. data/lib/chef/knife/help.rb +1 -1
  85. data/lib/chef/knife/list.rb +1 -1
  86. data/lib/chef/knife/search.rb +2 -2
  87. data/lib/chef/knife/ssh.rb +37 -27
  88. data/lib/chef/knife/ssl_check.rb +1 -1
  89. data/lib/chef/knife/user_delete.rb +1 -1
  90. data/lib/chef/mash.rb +1 -1
  91. data/lib/chef/mixin/command.rb +2 -2
  92. data/lib/chef/mixin/create_path.rb +3 -5
  93. data/lib/chef/mixin/from_file.rb +2 -2
  94. data/lib/chef/mixin/get_source_from_package.rb +2 -2
  95. data/lib/chef/mixin/notifying_block.rb +7 -9
  96. data/lib/chef/mixin/params_validate.rb +3 -3
  97. data/lib/chef/mixin/securable.rb +1 -1
  98. data/lib/chef/mixin/shell_out.rb +23 -3
  99. data/lib/chef/mixin/unformatter.rb +2 -2
  100. data/lib/chef/mixin/uris.rb +4 -6
  101. data/lib/chef/mixin/versioned_api.rb +69 -0
  102. data/lib/chef/mixin/which.rb +25 -8
  103. data/lib/chef/mixin/windows_architecture_helper.rb +2 -2
  104. data/lib/chef/mixin/xml_escape.rb +3 -5
  105. data/lib/chef/monkey_patches/webrick-utils.rb +1 -1
  106. data/lib/chef/node.rb +8 -8
  107. data/lib/chef/node/attribute.rb +4 -4
  108. data/lib/chef/node/common_api.rb +5 -7
  109. data/lib/chef/org.rb +10 -12
  110. data/lib/chef/platform/provider_mapping.rb +7 -7
  111. data/lib/chef/platform/query_helpers.rb +1 -1
  112. data/lib/chef/policy_builder/policyfile.rb +1 -0
  113. data/lib/chef/property.rb +31 -0
  114. data/lib/chef/provider/batch.rb +1 -1
  115. data/lib/chef/provider/breakpoint.rb +1 -1
  116. data/lib/chef/provider/cookbook_file.rb +3 -3
  117. data/lib/chef/provider/cron.rb +38 -38
  118. data/lib/chef/provider/deploy.rb +81 -81
  119. data/lib/chef/provider/deploy/revision.rb +3 -5
  120. data/lib/chef/provider/directory.rb +32 -32
  121. data/lib/chef/provider/dsc_resource.rb +22 -6
  122. data/lib/chef/provider/env.rb +28 -28
  123. data/lib/chef/provider/env/windows.rb +1 -1
  124. data/lib/chef/provider/erl_call.rb +13 -13
  125. data/lib/chef/provider/execute.rb +5 -2
  126. data/lib/chef/provider/file.rb +49 -51
  127. data/lib/chef/provider/git.rb +55 -55
  128. data/lib/chef/provider/http_request.rb +36 -36
  129. data/lib/chef/provider/launchd.rb +2 -2
  130. data/lib/chef/provider/link.rb +50 -50
  131. data/lib/chef/provider/log.rb +2 -2
  132. data/lib/chef/provider/mdadm.rb +25 -25
  133. data/lib/chef/provider/mount/aix.rb +2 -2
  134. data/lib/chef/provider/mount/mount.rb +2 -2
  135. data/lib/chef/provider/ohai.rb +1 -1
  136. data/lib/chef/provider/osx_profile.rb +23 -23
  137. data/lib/chef/provider/package.rb +74 -56
  138. data/lib/chef/provider/package/aix.rb +55 -52
  139. data/lib/chef/provider/package/apt.rb +15 -13
  140. data/lib/chef/provider/package/cab.rb +49 -20
  141. data/lib/chef/provider/package/chocolatey.rb +9 -10
  142. data/lib/chef/provider/package/dnf.rb +20 -18
  143. data/lib/chef/provider/package/dnf/dnf_helper.py +1 -1
  144. data/lib/chef/provider/package/dnf/python_helper.rb +63 -26
  145. data/lib/chef/provider/package/dnf/version.rb +1 -1
  146. data/lib/chef/provider/package/dpkg.rb +8 -9
  147. data/lib/chef/provider/package/easy_install.rb +22 -22
  148. data/lib/chef/provider/package/freebsd/base.rb +10 -10
  149. data/lib/chef/provider/package/freebsd/pkg.rb +15 -15
  150. data/lib/chef/provider/package/freebsd/pkgng.rb +13 -15
  151. data/lib/chef/provider/package/freebsd/port.rb +7 -7
  152. data/lib/chef/provider/package/homebrew.rb +11 -10
  153. data/lib/chef/provider/package/ips.rb +18 -23
  154. data/lib/chef/provider/package/macports.rb +23 -23
  155. data/lib/chef/provider/package/msu.rb +11 -11
  156. data/lib/chef/provider/package/openbsd.rb +25 -22
  157. data/lib/chef/provider/package/pacman.rb +16 -16
  158. data/lib/chef/provider/package/paludis.rb +26 -27
  159. data/lib/chef/provider/package/portage.rb +22 -22
  160. data/lib/chef/provider/package/powershell.rb +17 -17
  161. data/lib/chef/provider/package/rpm.rb +25 -25
  162. data/lib/chef/provider/package/rubygems.rb +60 -60
  163. data/lib/chef/provider/package/smartos.rb +16 -16
  164. data/lib/chef/provider/package/solaris.rb +44 -44
  165. data/lib/chef/provider/package/windows.rb +3 -3
  166. data/lib/chef/provider/package/windows/exe.rb +6 -6
  167. data/lib/chef/provider/package/windows/msi.rb +6 -6
  168. data/lib/chef/provider/package/yum.rb +318 -268
  169. data/lib/chef/provider/package/yum/rpm_utils.rb +34 -34
  170. data/lib/chef/provider/package/yum/yum_cache.rb +12 -12
  171. data/lib/chef/provider/package/zypper.rb +11 -11
  172. data/lib/chef/provider/powershell_script.rb +15 -7
  173. data/lib/chef/provider/reboot.rb +10 -10
  174. data/lib/chef/provider/registry_key.rb +39 -39
  175. data/lib/chef/provider/remote_directory.rb +3 -3
  176. data/lib/chef/provider/remote_file.rb +3 -3
  177. data/lib/chef/provider/route.rb +1 -1
  178. data/lib/chef/provider/ruby_block.rb +3 -3
  179. data/lib/chef/provider/script.rb +42 -6
  180. data/lib/chef/provider/service.rb +49 -49
  181. data/lib/chef/provider/service/solaris.rb +1 -1
  182. data/lib/chef/provider/service/systemd.rb +1 -1
  183. data/lib/chef/provider/subversion.rb +39 -39
  184. data/lib/chef/provider/systemd_unit.rb +2 -0
  185. data/lib/chef/provider/template.rb +3 -3
  186. data/lib/chef/provider/user.rb +42 -42
  187. data/lib/chef/provider/whyrun_safe_ruby_block.rb +4 -4
  188. data/lib/chef/resource.rb +27 -16
  189. data/lib/chef/resource/apt_repository.rb +0 -1
  190. data/lib/chef/resource/chef_gem.rb +1 -1
  191. data/lib/chef/resource/dnf_package.rb +6 -3
  192. data/lib/chef/resource/dsc_resource.rb +9 -1
  193. data/lib/chef/resource/execute.rb +70 -6
  194. data/lib/chef/resource/file/verification/systemd_unit.rb +67 -0
  195. data/lib/chef/resource/freebsd_package.rb +1 -1
  196. data/lib/chef/resource/gem_package.rb +1 -1
  197. data/lib/chef/resource/launchd.rb +13 -1
  198. data/lib/chef/resource/package.rb +2 -2
  199. data/lib/chef/resource/registry_key.rb +1 -1
  200. data/lib/chef/resource/yum_package.rb +12 -3
  201. data/lib/chef/resource/yum_repository.rb +0 -1
  202. data/lib/chef/resource_collection/resource_collection_serialization.rb +3 -3
  203. data/lib/chef/resource_collection/resource_set.rb +2 -2
  204. data/lib/chef/resource_reporter.rb +1 -1
  205. data/lib/chef/run_context.rb +3 -3
  206. data/lib/chef/run_list/run_list_item.rb +1 -1
  207. data/lib/chef/run_list/versioned_recipe_list.rb +6 -6
  208. data/lib/chef/server_api.rb +2 -0
  209. data/lib/chef/server_api_versions.rb +40 -0
  210. data/lib/chef/shell.rb +1 -1
  211. data/lib/chef/shell/ext.rb +3 -3
  212. data/lib/chef/shell/shell_session.rb +1 -1
  213. data/lib/chef/user.rb +9 -11
  214. data/lib/chef/user_v1.rb +9 -11
  215. data/lib/chef/util/diff.rb +1 -1
  216. data/lib/chef/util/dsc/lcm_output_parser.rb +1 -1
  217. data/lib/chef/util/selinux.rb +1 -1
  218. data/lib/chef/util/windows/net_group.rb +18 -30
  219. data/lib/chef/util/windows/net_use.rb +7 -11
  220. data/lib/chef/util/windows/net_user.rb +11 -17
  221. data/lib/chef/util/windows/volume.rb +9 -15
  222. data/lib/chef/version.rb +1 -1
  223. data/lib/chef/version_class.rb +1 -1
  224. data/lib/chef/win32/api.rb +4 -6
  225. data/lib/chef/win32/api/file.rb +25 -31
  226. data/lib/chef/win32/api/installer.rb +2 -2
  227. data/lib/chef/win32/file.rb +4 -6
  228. data/lib/chef/win32/registry.rb +9 -9
  229. data/lib/chef/win32/security.rb +2 -2
  230. data/lib/chef/win32/security/acl.rb +2 -2
  231. data/lib/chef/win32/unicode.rb +2 -2
  232. data/lib/chef/win32/version.rb +1 -1
  233. data/spec/data/prefer_metadata_json/metadata.json +51 -0
  234. data/spec/data/prefer_metadata_json/metadata.rb +6 -0
  235. data/spec/data/prefer_metadata_json/recipes/default.rb +0 -0
  236. data/spec/functional/knife/ssh_spec.rb +5 -5
  237. data/spec/functional/resource/batch_spec.rb +5 -1
  238. data/spec/functional/resource/dsc_script_spec.rb +2 -4
  239. data/spec/functional/resource/execute_spec.rb +17 -0
  240. data/spec/functional/resource/user/dscl_spec.rb +2 -4
  241. data/spec/integration/client/client_spec.rb +33 -0
  242. data/spec/integration/recipes/recipe_dsl_spec.rb +58 -58
  243. data/spec/spec_helper.rb +4 -0
  244. data/spec/support/chef_helpers.rb +5 -7
  245. data/spec/support/platform_helpers.rb +6 -0
  246. data/spec/support/platforms/prof/gc.rb +4 -6
  247. data/spec/support/shared/context/client.rb +1 -1
  248. data/spec/support/shared/functional/execute_resource.rb +150 -0
  249. data/spec/support/shared/functional/windows_script.rb +74 -4
  250. data/spec/support/shared/unit/execute_resource.rb +37 -0
  251. data/spec/support/shared/unit/provider/file.rb +10 -0
  252. data/spec/unit/cookbook/cookbook_version_loader_spec.rb +9 -0
  253. data/spec/unit/cookbook/syntax_check_spec.rb +8 -2
  254. data/spec/unit/http/api_versions_spec.rb +69 -0
  255. data/spec/unit/knife/ssh_spec.rb +34 -36
  256. data/spec/unit/mixin/versioned_api_spec.rb +107 -0
  257. data/spec/unit/mixin/which.rb +160 -0
  258. data/spec/unit/platform_spec.rb +28 -1
  259. data/spec/unit/provider/deploy_spec.rb +1 -1
  260. data/spec/unit/provider/directory_spec.rb +10 -0
  261. data/spec/unit/provider/dsc_resource_spec.rb +175 -0
  262. data/spec/unit/provider/execute_spec.rb +0 -1
  263. data/spec/unit/provider/launchd_spec.rb +2 -2
  264. data/spec/unit/provider/package/aix_spec.rb +22 -22
  265. data/spec/unit/provider/package/apt_spec.rb +27 -27
  266. data/spec/unit/provider/package/cab_spec.rb +59 -5
  267. data/spec/unit/provider/package/dnf/python_helper_spec.rb +29 -0
  268. data/spec/unit/provider/package/dpkg_spec.rb +16 -16
  269. data/spec/unit/provider/package/easy_install_spec.rb +18 -18
  270. data/spec/unit/provider/package/freebsd/pkg_spec.rb +15 -15
  271. data/spec/unit/provider/package/freebsd/pkgng_spec.rb +9 -9
  272. data/spec/unit/provider/package/freebsd/port_spec.rb +9 -9
  273. data/spec/unit/provider/package/homebrew_spec.rb +9 -9
  274. data/spec/unit/provider/package/ips_spec.rb +37 -31
  275. data/spec/unit/provider/package/macports_spec.rb +10 -10
  276. data/spec/unit/provider/package/openbsd_spec.rb +10 -10
  277. data/spec/unit/provider/package/pacman_spec.rb +6 -6
  278. data/spec/unit/provider/package/paludis_spec.rb +7 -7
  279. data/spec/unit/provider/package/portage_spec.rb +6 -7
  280. data/spec/unit/provider/package/rpm_spec.rb +23 -23
  281. data/spec/unit/provider/package/rubygems_spec.rb +38 -38
  282. data/spec/unit/provider/package/solaris_spec.rb +15 -15
  283. data/spec/unit/provider/package/windows_spec.rb +2 -1
  284. data/spec/unit/provider/package/yum_spec.rb +51 -43
  285. data/spec/unit/provider/package/zypper_spec.rb +34 -34
  286. data/spec/unit/provider/package_spec.rb +8 -0
  287. data/spec/unit/provider/remote_file/sftp_spec.rb +3 -3
  288. data/spec/unit/provider/route_spec.rb +7 -1
  289. data/spec/unit/provider/script_spec.rb +49 -6
  290. data/spec/unit/resource/dsc_resource_spec.rb +6 -0
  291. data/spec/unit/resource/execute_spec.rb +214 -0
  292. data/spec/unit/resource/file/verification/systemd_unit_spec.rb +103 -0
  293. data/spec/unit/resource/freebsd_package_spec.rb +2 -2
  294. data/spec/unit/resource/package_spec.rb +5 -0
  295. data/spec/unit/resource/yum_package_spec.rb +42 -1
  296. data/spec/unit/resource_reporter_spec.rb +1 -1
  297. data/spec/unit/resource_spec.rb +18 -0
  298. data/spec/unit/server_api_versions_spec.rb +44 -0
  299. data/spec/unit/util/selinux_spec.rb +3 -14
  300. data/spec/unit/win32/error_spec.rb +67 -0
  301. data/spec/unit/win32/security_spec.rb +66 -0
  302. data/tasks/changelog.rb +1 -1
  303. data/tasks/dependencies.rb +20 -4
  304. metadata +39 -18
  305. data/lib/chef/monkey_patches/net-ssh-multi.rb +0 -141
@@ -37,7 +37,7 @@ class Chef
37
37
  lead = 0
38
38
  tail = evr.size
39
39
 
40
- if %r{^([\d]+):}.match(evr) # rubocop:disable Performance/RedundantMatch
40
+ if /^([\d]+):/.match(evr) # rubocop:disable Performance/RedundantMatch
41
41
  epoch = $1.to_i
42
42
  lead = $1.length + 1
43
43
  elsif evr[0].ord == ":".ord
@@ -45,7 +45,7 @@ class Chef
45
45
  lead = 1
46
46
  end
47
47
 
48
- if %r{:?.*-(.*)$}.match(evr) # rubocop:disable Performance/RedundantMatch
48
+ if /:?.*-(.*)$/.match(evr) # rubocop:disable Performance/RedundantMatch
49
49
  release = $1
50
50
  tail = evr.length - release.length - lead - 1
51
51
 
@@ -230,17 +230,17 @@ class Chef
230
230
  @v = args[1]
231
231
  @r = args[2]
232
232
  else
233
- raise ArgumentError, "Expecting either 'epoch-version-release' or 'epoch, " +
233
+ raise ArgumentError, "Expecting either 'epoch-version-release' or 'epoch, " \
234
234
  "version, release'"
235
235
  end
236
236
  end
237
237
  attr_reader :e, :v, :r
238
- alias :epoch :e
239
- alias :version :v
240
- alias :release :r
238
+ alias epoch e
239
+ alias version v
240
+ alias release r
241
241
 
242
242
  def self.parse(*args)
243
- self.new(*args)
243
+ new(*args)
244
244
  end
245
245
 
246
246
  def <=>(other)
@@ -317,7 +317,7 @@ class Chef
317
317
  return cmp
318
318
  end
319
319
 
320
- return 0
320
+ 0
321
321
  end
322
322
  end
323
323
 
@@ -339,7 +339,7 @@ class Chef
339
339
  @a = args[4]
340
340
  @provides = args[5]
341
341
  else
342
- raise ArgumentError, "Expecting either 'name, epoch-version-release, arch, provides' " +
342
+ raise ArgumentError, "Expecting either 'name, epoch-version-release, arch, provides' " \
343
343
  "or 'name, epoch, version, release, arch, provides'"
344
344
  end
345
345
 
@@ -349,8 +349,8 @@ class Chef
349
349
  end
350
350
  end
351
351
  attr_reader :n, :a, :version, :provides
352
- alias :name :n
353
- alias :arch :a
352
+ alias name n
353
+ alias arch a
354
354
 
355
355
  def <=>(other)
356
356
  compare(other)
@@ -395,7 +395,7 @@ class Chef
395
395
  end
396
396
  end
397
397
 
398
- return 0
398
+ 0
399
399
  end
400
400
 
401
401
  def to_s
@@ -423,7 +423,7 @@ class Chef
423
423
  @version = RPMVersion.new(e, v, r)
424
424
  @flag = args[4] || :==
425
425
  else
426
- raise ArgumentError, "Expecting either 'name, epoch-version-release, flag' or " +
426
+ raise ArgumentError, "Expecting either 'name, epoch-version-release, flag' or " \
427
427
  "'name, epoch, version, release, flag'"
428
428
  end
429
429
  end
@@ -434,25 +434,25 @@ class Chef
434
434
  # "mtr >= 2:0.71-3.0"
435
435
  # "mta"
436
436
  def self.parse(string)
437
- if %r{^(\S+)\s+(>|>=|=|==|<=|<)\s+(\S+)$}.match(string) # rubocop:disable Performance/RedundantMatch
437
+ if /^(\S+)\s+(>|>=|=|==|<=|<)\s+(\S+)$/.match(string) # rubocop:disable Performance/RedundantMatch
438
438
  name = $1
439
- if $2 == "="
440
- flag = :==
441
- else
442
- flag = :"#{$2}"
443
- end
439
+ flag = if $2 == "="
440
+ :==
441
+ else
442
+ :"#{$2}"
443
+ end
444
444
  version = $3
445
445
 
446
- return self.new(name, version, flag)
446
+ new(name, version, flag)
447
447
  else
448
448
  name = string
449
- return self.new(name, nil, nil)
449
+ new(name, nil, nil)
450
450
  end
451
451
  end
452
452
 
453
453
  # Test if another RPMDependency satisfies our requirements
454
454
  def satisfy?(y)
455
- unless y.kind_of?(RPMDependency)
455
+ unless y.is_a?(RPMDependency)
456
456
  raise ArgumentError, "Expecting an RPMDependency object"
457
457
  end
458
458
 
@@ -481,7 +481,7 @@ class Chef
481
481
  return true
482
482
  end
483
483
 
484
- return false
484
+ false
485
485
  end
486
486
  end
487
487
 
@@ -504,11 +504,11 @@ class Chef
504
504
  class RPMDb
505
505
  def initialize
506
506
  # package name => [ RPMPackage, RPMPackage ] of different versions
507
- @rpms = Hash.new
507
+ @rpms = {}
508
508
  # package nevra => RPMPackage for lookups
509
- @index = Hash.new
509
+ @index = {}
510
510
  # provide name (aka feature) => [RPMPackage, RPMPackage] each providing this feature
511
- @provides = Hash.new
511
+ @provides = {}
512
512
  # RPMPackages listed as available
513
513
  @available = Set.new
514
514
  # RPMPackages listed as installed
@@ -516,7 +516,7 @@ class Chef
516
516
  end
517
517
 
518
518
  def [](package_name)
519
- self.lookup(package_name)
519
+ lookup(package_name)
520
520
  end
521
521
 
522
522
  # Lookup package_name and return a descending array of package objects
@@ -537,11 +537,11 @@ class Chef
537
537
  # The available/installed state can be overwritten for existing packages.
538
538
  def push(*args)
539
539
  args.flatten.each do |new_rpm|
540
- unless new_rpm.kind_of?(RPMDbPackage)
540
+ unless new_rpm.is_a?(RPMDbPackage)
541
541
  raise ArgumentError, "Expecting an RPMDbPackage object"
542
542
  end
543
543
 
544
- @rpms[new_rpm.n] ||= Array.new
544
+ @rpms[new_rpm.n] ||= []
545
545
 
546
546
  # we may already have this one, like when the installed list is refreshed
547
547
  idx = @index[new_rpm.nevra]
@@ -552,7 +552,7 @@ class Chef
552
552
  @rpms[new_rpm.n] << new_rpm
553
553
 
554
554
  new_rpm.provides.each do |provide|
555
- @provides[provide.name] ||= Array.new
555
+ @provides[provide.name] ||= []
556
556
  @provides[provide.name] << new_rpm
557
557
  end
558
558
 
@@ -574,7 +574,7 @@ class Chef
574
574
  end
575
575
 
576
576
  def <<(*args)
577
- self.push(args)
577
+ push(args)
578
578
  end
579
579
 
580
580
  def clear
@@ -596,7 +596,7 @@ class Chef
596
596
  def size
597
597
  @rpms.size
598
598
  end
599
- alias :length :size
599
+ alias length size
600
600
 
601
601
  def available_size
602
602
  @available.size
@@ -615,7 +615,7 @@ class Chef
615
615
  end
616
616
 
617
617
  def whatprovides(rpmdep)
618
- unless rpmdep.kind_of?(RPMDependency)
618
+ unless rpmdep.is_a?(RPMDependency)
619
619
  raise ArgumentError, "Expecting an RPMDependency object"
620
620
  end
621
621
 
@@ -632,7 +632,7 @@ class Chef
632
632
  end
633
633
  end
634
634
 
635
- return what
635
+ what
636
636
  end
637
637
  end
638
638
 
@@ -101,12 +101,12 @@ class Chef
101
101
  status = nil
102
102
 
103
103
  begin
104
- status = shell_out!("#{python_bin} #{yum_dump_path}#{opts}", :timeout => Chef::Config[:yum_timeout])
104
+ status = shell_out!("#{python_bin} #{yum_dump_path}#{opts}", timeout: Chef::Config[:yum_timeout])
105
105
  status.stdout.each_line do |line|
106
106
  one_line = true
107
107
 
108
108
  line.chomp!
109
- if line =~ %r{\[option (.*)\] (.*)}
109
+ if line =~ /\[option (.*)\] (.*)/
110
110
  if $1 == "installonlypkgs"
111
111
  @allow_multi_install = $2.split
112
112
  else
@@ -115,7 +115,7 @@ class Chef
115
115
  next
116
116
  end
117
117
 
118
- if line =~ %r{^(\S+) ([0-9]+) (\S+) (\S+) (\S+) \[(.*)\] ([i,a,r]) (\S+)$}
118
+ if line =~ /^(\S+) ([0-9]+) (\S+) (\S+) (\S+) \[(.*)\] ([i,a,r]) (\S+)$/
119
119
  name = $1
120
120
  epoch = $2
121
121
  version = $3
@@ -125,7 +125,7 @@ class Chef
125
125
  type = $7
126
126
  repoid = $8
127
127
  else
128
- Chef::Log.warn("Problem parsing line '#{line}' from yum-dump.py! " +
128
+ Chef::Log.warn("Problem parsing line '#{line}' from yum-dump.py! " \
129
129
  "Please check your yum configuration.")
130
130
  next
131
131
  end
@@ -158,7 +158,7 @@ class Chef
158
158
  raise Chef::Exceptions::Package, "Yum failed - #{status.inspect} - returns: #{error}"
159
159
  else
160
160
  unless one_line
161
- Chef::Log.warn("Odd, no output from yum-dump.py. Please check " +
161
+ Chef::Log.warn("Odd, no output from yum-dump.py. Please check " \
162
162
  "your yum configuration.")
163
163
  end
164
164
  end
@@ -233,7 +233,7 @@ class Chef
233
233
  if @rpmdb.lookup(package_name)
234
234
  return true
235
235
  else
236
- if package_name =~ %r{^(.*)\.(.*)$}
236
+ if package_name =~ /^(.*)\.(.*)$/
237
237
  pkg_name = $1
238
238
  pkg_arch = $2
239
239
 
@@ -245,7 +245,7 @@ class Chef
245
245
  end
246
246
  end
247
247
 
248
- return false
248
+ false
249
249
  end
250
250
 
251
251
  # Returns a array of packages satisfying an RPMDependency
@@ -260,7 +260,7 @@ class Chef
260
260
  return true if desired_version == v
261
261
  end
262
262
 
263
- return false
263
+ false
264
264
  end
265
265
 
266
266
  # Return the source repository for a package-version.arch
@@ -269,14 +269,14 @@ class Chef
269
269
  return pkg.repoid if desired_version == pkg.version.to_s
270
270
  end
271
271
 
272
- return nil
272
+ nil
273
273
  end
274
274
 
275
275
  # Return the latest available version for a package.arch
276
276
  def available_version(package_name, arch = nil)
277
277
  version(package_name, arch, true, false)
278
278
  end
279
- alias :candidate_version :available_version
279
+ alias candidate_version available_version
280
280
 
281
281
  # Return the currently installed version for a package.arch
282
282
  def installed_version(package_name, arch = nil)
@@ -361,12 +361,12 @@ class Chef
361
361
  # ['atk = 1.12.2-1.fc6', 'libatk-1.0.so.0']
362
362
  string.split(", ").each do |seg|
363
363
  # 'atk = 1.12.2-1.fc6'
364
- if seg =~ %r{^'(.*)'$}
364
+ if seg =~ /^'(.*)'$/
365
365
  ret << RPMProvide.parse($1)
366
366
  end
367
367
  end
368
368
 
369
- return ret
369
+ ret
370
370
  end
371
371
 
372
372
  end # YumCache
@@ -35,7 +35,7 @@ class Chef
35
35
  candidate_version = current_version = nil
36
36
  is_installed = false
37
37
  Chef::Log.debug("#{new_resource} checking zypper")
38
- status = shell_out_with_timeout!("zypper --non-interactive info #{package_name}")
38
+ status = shell_out_compact_timeout!("zypper", "--non-interactive", "info", package_name)
39
39
  status.stdout.each_line do |line|
40
40
  case line
41
41
  when /^Version *: (.+) *$/
@@ -77,14 +77,14 @@ class Chef
77
77
 
78
78
  def package_locked(name, version)
79
79
  islocked = false
80
- locked = shell_out_with_timeout!("zypper locks")
80
+ locked = shell_out_compact_timeout!("zypper", "locks")
81
81
  locked.stdout.each_line do |line|
82
82
  line_package = line.split("|").shift(2).last.strip
83
83
  if line_package == name
84
84
  islocked = true
85
85
  end
86
86
  end
87
- return islocked
87
+ islocked
88
88
  end
89
89
 
90
90
  def load_current_resource
@@ -103,7 +103,7 @@ class Chef
103
103
  end
104
104
 
105
105
  def install_package(name, version)
106
- zypper_package("install --auto-agree-with-licenses", name, version)
106
+ zypper_package("install", "--auto-agree-with-licenses", name, version)
107
107
  end
108
108
 
109
109
  def upgrade_package(name, version)
@@ -116,7 +116,7 @@ class Chef
116
116
  end
117
117
 
118
118
  def purge_package(name, version)
119
- zypper_package("remove --clean-deps", name, version)
119
+ zypper_package("remove", "--clean-deps", name, version)
120
120
  end
121
121
 
122
122
  def lock_package(name, version)
@@ -135,24 +135,24 @@ class Chef
135
135
  end
136
136
  end
137
137
 
138
- def zypper_package(command, names, versions)
138
+ def zypper_package(command, *options, names, versions)
139
139
  zipped_names = zip(names, versions)
140
140
  if zypper_version < 1.0
141
- shell_out_with_timeout!(a_to_s("zypper", gpg_checks, command, "-y", names))
141
+ shell_out_compact_timeout!("zypper", gpg_checks, command, *options, "-y", names)
142
142
  else
143
- shell_out_with_timeout!(a_to_s("zypper --non-interactive", gpg_checks, command, zipped_names))
143
+ shell_out_compact_timeout!("zypper", "--non-interactive", gpg_checks, command, *options, zipped_names)
144
144
  end
145
145
  end
146
146
 
147
147
  def gpg_checks
148
148
  case Chef::Config[:zypper_check_gpg]
149
149
  when true
150
- ""
150
+ nil
151
151
  when false
152
152
  "--no-gpg-checks"
153
153
  when nil
154
- Chef::Log.warn("Chef::Config[:zypper_check_gpg] was not set. " +
155
- "All packages will be installed without gpg signature checks. " +
154
+ Chef::Log.warn("Chef::Config[:zypper_check_gpg] was not set. " \
155
+ "All packages will be installed without gpg signature checks. " \
156
156
  "This is a security hazard.")
157
157
  "--no-gpg-checks"
158
158
  end
@@ -60,8 +60,8 @@ class Chef
60
60
  def flags
61
61
  interpreter_flags = [*default_interpreter_flags].join(" ")
62
62
 
63
- if ! (@new_resource.flags.nil?)
64
- interpreter_flags = [@new_resource.flags, interpreter_flags].join(" ")
63
+ if ! (new_resource.flags.nil?)
64
+ interpreter_flags = [new_resource.flags, interpreter_flags].join(" ")
65
65
  end
66
66
 
67
67
  interpreter_flags
@@ -73,8 +73,8 @@ class Chef
73
73
  # special handling to cover common use cases.
74
74
  def add_exit_status_wrapper
75
75
  self.code = wrapper_script
76
- Chef::Log.debug("powershell_script provider called with script code:\n\n#{@new_resource.code}\n")
77
- Chef::Log.debug("powershell_script provider will execute transformed code:\n\n#{self.code}\n")
76
+ Chef::Log.debug("powershell_script provider called with script code:\n\n#{new_resource.code}\n")
77
+ Chef::Log.debug("powershell_script provider will execute transformed code:\n\n#{code}\n")
78
78
  end
79
79
 
80
80
  def validate_script_syntax!
@@ -87,7 +87,7 @@ class Chef
87
87
  # actually running the script.
88
88
  user_code_wrapped_in_powershell_script_block = <<-EOH
89
89
  {
90
- #{@new_resource.code}
90
+ #{new_resource.code}
91
91
  }
92
92
  EOH
93
93
  user_script_file.puts user_code_wrapped_in_powershell_script_block
@@ -149,6 +149,14 @@ EOH
149
149
  <<-EOH
150
150
  # Chef Client wrapper for powershell_script resources
151
151
 
152
+ # In rare cases, such as when PowerShell is executed
153
+ # as an alternate user, the new-variable cmdlet is not
154
+ # available, so import it just in case
155
+ if ( get-module -ListAvailable Microsoft.PowerShell.Utility )
156
+ {
157
+ Import-Module Microsoft.PowerShell.Utility
158
+ }
159
+
152
160
  # LASTEXITCODE can be uninitialized -- make it explictly 0
153
161
  # to avoid incorrect detection of failure (non-zero) codes
154
162
  $global:LASTEXITCODE = 0
@@ -159,7 +167,7 @@ $global:LASTEXITCODE = 0
159
167
  trap [Exception] {write-error ($_.Exception.Message);exit 1}
160
168
 
161
169
  # Variable state that should not be accessible to the user code
162
- new-variable -name interpolatedexitcode -visibility private -value $#{@new_resource.convert_boolean_return}
170
+ new-variable -name interpolatedexitcode -visibility private -value $#{new_resource.convert_boolean_return}
163
171
  new-variable -name chefscriptresult -visibility private
164
172
 
165
173
  # Initialize a variable we use to capture $? inside a block
@@ -168,7 +176,7 @@ $global:lastcmdlet = $null
168
176
  # Execute the user's code in a script block --
169
177
  $chefscriptresult =
170
178
  {
171
- #{@new_resource.code}
179
+ #{new_resource.code}
172
180
 
173
181
  # This assignment doesn't affect the block's return value
174
182
  $global:lastcmdlet = $?
@@ -29,31 +29,31 @@ class Chef
29
29
  end
30
30
 
31
31
  def load_current_resource
32
- @current_resource ||= Chef::Resource::Reboot.new(@new_resource.name)
33
- @current_resource.reason(@new_resource.reason)
34
- @current_resource.delay_mins(@new_resource.delay_mins)
35
- @current_resource
32
+ @current_resource ||= Chef::Resource::Reboot.new(new_resource.name)
33
+ current_resource.reason(new_resource.reason)
34
+ current_resource.delay_mins(new_resource.delay_mins)
35
+ current_resource
36
36
  end
37
37
 
38
38
  def request_reboot
39
39
  node.run_context.request_reboot(
40
- :delay_mins => @new_resource.delay_mins,
41
- :reason => @new_resource.reason,
40
+ :delay_mins => new_resource.delay_mins,
41
+ :reason => new_resource.reason,
42
42
  :timestamp => Time.now,
43
- :requested_by => @new_resource.name
43
+ :requested_by => new_resource.name
44
44
  )
45
45
  end
46
46
 
47
47
  def action_request_reboot
48
48
  converge_by("request a system reboot to occur if the run succeeds") do
49
- Chef::Log.warn "Reboot requested:'#{@new_resource.name}'"
49
+ Chef::Log.warn "Reboot requested:'#{new_resource.name}'"
50
50
  request_reboot
51
51
  end
52
52
  end
53
53
 
54
54
  def action_reboot_now
55
55
  converge_by("rebooting the system immediately") do
56
- Chef::Log.warn "Rebooting system immediately, requested by '#{@new_resource.name}'"
56
+ Chef::Log.warn "Rebooting system immediately, requested by '#{new_resource.name}'"
57
57
  request_reboot
58
58
  throw :end_client_run_early
59
59
  end
@@ -61,7 +61,7 @@ class Chef
61
61
 
62
62
  def action_cancel
63
63
  converge_by("cancel any existing end-of-run reboot request") do
64
- Chef::Log.warn "Reboot canceled: '#{@new_resource.name}'"
64
+ Chef::Log.warn "Reboot canceled: '#{new_resource.name}'"
65
65
  node.run_context.cancel_reboot
66
66
  end
67
67
  end