chef 17.10.163 → 18.7.10

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 (400) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +25 -21
  3. data/README.md +7 -7
  4. data/Rakefile +3 -22
  5. data/{chef-universal-mingw32.gemspec → chef-universal-mingw-ucrt.gemspec} +7 -6
  6. data/chef.gemspec +33 -27
  7. data/lib/chef/api_client_v1.rb +9 -1
  8. data/lib/chef/application/base.rb +20 -2
  9. data/lib/chef/application/exit_code.rb +3 -3
  10. data/lib/chef/chef_fs/file_pattern.rb +1 -1
  11. data/lib/chef/chef_fs/file_system.rb +21 -7
  12. data/lib/chef/chef_fs/path_utils.rb +7 -9
  13. data/lib/chef/client.rb +186 -2
  14. data/lib/chef/compliance/default_attributes.rb +2 -2
  15. data/lib/chef/compliance/input.rb +1 -1
  16. data/lib/chef/compliance/profile.rb +1 -1
  17. data/lib/chef/compliance/profile_collection.rb +0 -1
  18. data/lib/chef/compliance/runner.rb +6 -1
  19. data/lib/chef/compliance/waiver.rb +1 -1
  20. data/lib/chef/cookbook/chefignore.rb +4 -1
  21. data/lib/chef/cookbook/cookbook_version_loader.rb +1 -1
  22. data/lib/chef/cookbook/metadata.rb +1 -1
  23. data/lib/chef/cookbook/remote_file_vendor.rb +1 -3
  24. data/lib/chef/cookbook/synchronizer.rb +21 -3
  25. data/lib/chef/cookbook/syntax_check.rb +2 -2
  26. data/lib/chef/cookbook_manifest.rb +2 -2
  27. data/lib/chef/cookbook_version.rb +1 -1
  28. data/lib/chef/data_collector.rb +14 -0
  29. data/lib/chef/delayed_evaluator.rb +4 -0
  30. data/lib/chef/dsl/reader_helpers.rb +1 -1
  31. data/lib/chef/dsl/rest_resource.rb +77 -0
  32. data/lib/chef/event_dispatch/base.rb +3 -0
  33. data/lib/chef/event_dispatch/dispatcher.rb +0 -1
  34. data/lib/chef/exceptions.rb +9 -1
  35. data/lib/chef/file_access_control/windows.rb +4 -1
  36. data/lib/chef/file_cache.rb +17 -2
  37. data/lib/chef/formatters/doc.rb +1 -1
  38. data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +2 -0
  39. data/lib/chef/http/authenticator.rb +253 -3
  40. data/lib/chef/http/ssl_policies.rb +2 -2
  41. data/lib/chef/mixin/{homebrew_user.rb → homebrew.rb} +13 -16
  42. data/lib/chef/mixin/openssl_helper.rb +1 -16
  43. data/lib/chef/mixin/powershell_exec.rb +5 -28
  44. data/lib/chef/monkey_patches/net-http.rb +127 -0
  45. data/lib/chef/node/attribute.rb +3 -11
  46. data/lib/chef/node/attribute_collections.rb +10 -1
  47. data/lib/chef/node/immutable_collections.rb +17 -6
  48. data/lib/chef/node/mixin/immutablize_array.rb +1 -0
  49. data/lib/chef/node/mixin/state_tracking.rb +7 -4
  50. data/lib/chef/node/mixin/state_tracking_array.rb +41 -0
  51. data/lib/chef/node.rb +23 -1
  52. data/lib/chef/platform/query_helpers.rb +4 -2
  53. data/lib/chef/policy_builder/policyfile.rb +8 -0
  54. data/lib/chef/property.rb +13 -6
  55. data/lib/chef/provider/group/windows.rb +1 -1
  56. data/lib/chef/provider/http_request.rb +11 -9
  57. data/lib/chef/provider/launchd.rb +2 -1
  58. data/lib/chef/provider/mount/linux.rb +6 -1
  59. data/lib/chef/provider/mount/mount.rb +13 -5
  60. data/lib/chef/provider/mount/windows.rb +1 -1
  61. data/lib/chef/provider/package/apt.rb +11 -2
  62. data/lib/chef/provider/package/chocolatey.rb +260 -22
  63. data/lib/chef/provider/package/dnf/dnf_helper.py +7 -0
  64. data/lib/chef/provider/package/homebrew.rb +6 -9
  65. data/lib/chef/provider/package/powershell.rb +1 -0
  66. data/lib/chef/provider/package/rubygems.rb +5 -1
  67. data/lib/chef/provider/package/snap.rb +3 -2
  68. data/lib/chef/provider/package/windows/msi.rb +2 -2
  69. data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +1 -1
  70. data/lib/chef/provider/package/yum/yum_helper.py +3 -3
  71. data/lib/chef/provider/package/zypper/version.rb +60 -0
  72. data/lib/chef/provider/package/zypper.rb +47 -3
  73. data/lib/chef/provider/powershell_script.rb +96 -6
  74. data/lib/chef/provider/registry_key.rb +2 -0
  75. data/lib/chef/provider/remote_file/http.rb +1 -1
  76. data/lib/chef/provider/service/systemd.rb +23 -8
  77. data/lib/chef/provider/service/windows.rb +1 -1
  78. data/lib/chef/provider/service.rb +14 -0
  79. data/lib/chef/provider/user/aix.rb +5 -0
  80. data/lib/chef/provider/user/linux.rb +29 -0
  81. data/lib/chef/provider/user/mac.rb +1 -1
  82. data/lib/chef/provider/user/windows.rb +5 -0
  83. data/lib/chef/provider/user.rb +45 -9
  84. data/lib/chef/provider/yum_repository.rb +13 -1
  85. data/lib/chef/provider.rb +1 -1
  86. data/lib/chef/recipe.rb +4 -12
  87. data/lib/chef/resource/_rest_resource.rb +389 -0
  88. data/lib/chef/resource/alternatives.rb +0 -1
  89. data/lib/chef/resource/apt_package.rb +21 -1
  90. data/lib/chef/resource/apt_preference.rb +0 -1
  91. data/lib/chef/resource/apt_repository.rb +138 -18
  92. data/lib/chef/resource/apt_update.rb +0 -1
  93. data/lib/chef/resource/archive_file.rb +0 -1
  94. data/lib/chef/resource/bash.rb +13 -1
  95. data/lib/chef/resource/batch.rb +0 -1
  96. data/lib/chef/resource/bff_package.rb +0 -1
  97. data/lib/chef/resource/breakpoint.rb +0 -1
  98. data/lib/chef/resource/build_essential.rb +0 -1
  99. data/lib/chef/resource/cab_package.rb +0 -1
  100. data/lib/chef/resource/chef_client_config.rb +12 -14
  101. data/lib/chef/resource/chef_client_cron.rb +1 -2
  102. data/lib/chef/resource/chef_client_launchd.rb +2 -2
  103. data/lib/chef/resource/chef_client_scheduled_task.rb +3 -3
  104. data/lib/chef/resource/chef_client_systemd_timer.rb +5 -1
  105. data/lib/chef/resource/chef_client_trusted_certificate.rb +0 -1
  106. data/lib/chef/resource/chef_gem.rb +1 -2
  107. data/lib/chef/resource/chef_handler.rb +0 -1
  108. data/lib/chef/resource/chef_sleep.rb +1 -3
  109. data/lib/chef/resource/chef_vault_secret.rb +0 -1
  110. data/lib/chef/resource/chocolatey_config.rb +0 -1
  111. data/lib/chef/resource/chocolatey_feature.rb +0 -1
  112. data/lib/chef/resource/chocolatey_installer.rb +207 -0
  113. data/lib/chef/resource/chocolatey_package.rb +8 -1
  114. data/lib/chef/resource/chocolatey_source.rb +0 -1
  115. data/lib/chef/resource/cookbook_file.rb +0 -1
  116. data/lib/chef/resource/cron/_cron_shared.rb +0 -1
  117. data/lib/chef/resource/cron/cron.rb +0 -1
  118. data/lib/chef/resource/cron/cron_d.rb +15 -1
  119. data/lib/chef/resource/cron_access.rb +0 -1
  120. data/lib/chef/resource/csh.rb +0 -1
  121. data/lib/chef/resource/directory.rb +0 -1
  122. data/lib/chef/resource/dmg_package.rb +2 -1
  123. data/lib/chef/resource/dnf_package.rb +0 -1
  124. data/lib/chef/resource/dpkg_package.rb +0 -1
  125. data/lib/chef/resource/dsc_resource.rb +0 -1
  126. data/lib/chef/resource/dsc_script.rb +1 -2
  127. data/lib/chef/resource/execute.rb +8 -7
  128. data/lib/chef/resource/file.rb +0 -1
  129. data/lib/chef/resource/freebsd_package.rb +2 -1
  130. data/lib/chef/resource/gem_package.rb +2 -1
  131. data/lib/chef/resource/group.rb +25 -2
  132. data/lib/chef/resource/habitat/habitat_package.rb +0 -1
  133. data/lib/chef/resource/habitat/habitat_sup.rb +6 -7
  134. data/lib/chef/resource/habitat/habitat_sup_windows.rb +1 -1
  135. data/lib/chef/resource/habitat_config.rb +0 -1
  136. data/lib/chef/resource/habitat_install.rb +2 -2
  137. data/lib/chef/resource/habitat_service.rb +0 -1
  138. data/lib/chef/resource/habitat_user_toml.rb +0 -1
  139. data/lib/chef/resource/homebrew_cask.rb +21 -33
  140. data/lib/chef/resource/homebrew_package.rb +3 -2
  141. data/lib/chef/resource/homebrew_tap.rb +32 -18
  142. data/lib/chef/resource/homebrew_update.rb +4 -6
  143. data/lib/chef/resource/hostname.rb +0 -1
  144. data/lib/chef/resource/http_request.rb +0 -1
  145. data/lib/chef/resource/ifconfig.rb +0 -1
  146. data/lib/chef/resource/inspec_input.rb +0 -1
  147. data/lib/chef/resource/inspec_waiver.rb +0 -1
  148. data/lib/chef/resource/inspec_waiver_file_entry.rb +2 -3
  149. data/lib/chef/resource/ips_package.rb +0 -1
  150. data/lib/chef/resource/kernel_module.rb +0 -1
  151. data/lib/chef/resource/ksh.rb +0 -1
  152. data/lib/chef/resource/launchd.rb +9 -3
  153. data/lib/chef/resource/link.rb +0 -1
  154. data/lib/chef/resource/locale.rb +0 -1
  155. data/lib/chef/resource/log.rb +0 -1
  156. data/lib/chef/resource/lwrp_base.rb +0 -4
  157. data/lib/chef/resource/macos_pkg.rb +111 -0
  158. data/lib/chef/resource/macos_userdefaults.rb +3 -4
  159. data/lib/chef/resource/macosx_service.rb +0 -1
  160. data/lib/chef/resource/macports_package.rb +2 -1
  161. data/lib/chef/resource/mdadm.rb +0 -1
  162. data/lib/chef/resource/mount.rb +0 -1
  163. data/lib/chef/resource/msu_package.rb +0 -1
  164. data/lib/chef/resource/notify_group.rb +0 -2
  165. data/lib/chef/resource/ohai.rb +0 -1
  166. data/lib/chef/resource/ohai_hint.rb +0 -1
  167. data/lib/chef/resource/openbsd_package.rb +2 -1
  168. data/lib/chef/resource/openssl_dhparam.rb +0 -2
  169. data/lib/chef/resource/openssl_ec_private_key.rb +0 -2
  170. data/lib/chef/resource/openssl_ec_public_key.rb +0 -2
  171. data/lib/chef/resource/openssl_rsa_private_key.rb +0 -2
  172. data/lib/chef/resource/openssl_rsa_public_key.rb +0 -2
  173. data/lib/chef/resource/openssl_x509_certificate.rb +0 -2
  174. data/lib/chef/resource/openssl_x509_crl.rb +0 -2
  175. data/lib/chef/resource/openssl_x509_request.rb +0 -2
  176. data/lib/chef/resource/osx_profile.rb +0 -1
  177. data/lib/chef/resource/package.rb +0 -1
  178. data/lib/chef/resource/pacman_package.rb +2 -1
  179. data/lib/chef/resource/paludis_package.rb +0 -1
  180. data/lib/chef/resource/perl.rb +0 -1
  181. data/lib/chef/resource/plist.rb +7 -3
  182. data/lib/chef/resource/portage_package.rb +2 -1
  183. data/lib/chef/resource/powershell_package.rb +4 -1
  184. data/lib/chef/resource/powershell_package_source.rb +0 -1
  185. data/lib/chef/resource/powershell_script.rb +5 -2
  186. data/lib/chef/resource/python.rb +0 -1
  187. data/lib/chef/resource/reboot.rb +0 -1
  188. data/lib/chef/resource/registry_key.rb +6 -1
  189. data/lib/chef/resource/remote_directory.rb +0 -1
  190. data/lib/chef/resource/remote_file.rb +0 -1
  191. data/lib/chef/resource/rhsm_errata.rb +0 -1
  192. data/lib/chef/resource/rhsm_errata_level.rb +0 -1
  193. data/lib/chef/resource/rhsm_register.rb +2 -4
  194. data/lib/chef/resource/rhsm_repo.rb +0 -1
  195. data/lib/chef/resource/rhsm_subscription.rb +0 -1
  196. data/lib/chef/resource/route.rb +0 -1
  197. data/lib/chef/resource/rpm_package.rb +2 -1
  198. data/lib/chef/resource/ruby.rb +0 -1
  199. data/lib/chef/resource/ruby_block.rb +0 -1
  200. data/lib/chef/resource/scm/_scm.rb +0 -2
  201. data/lib/chef/resource/scm/git.rb +0 -2
  202. data/lib/chef/resource/scm/subversion.rb +0 -2
  203. data/lib/chef/resource/script.rb +0 -1
  204. data/lib/chef/resource/selinux/common_helpers.rb +47 -0
  205. data/lib/chef/resource/selinux/selinux_debian.erb +18 -0
  206. data/lib/chef/resource/selinux/selinux_default.erb +15 -0
  207. data/lib/chef/resource/selinux_boolean.rb +101 -0
  208. data/lib/chef/resource/selinux_fcontext.rb +160 -0
  209. data/lib/chef/resource/selinux_install.rb +107 -0
  210. data/lib/chef/resource/selinux_login.rb +129 -0
  211. data/lib/chef/resource/selinux_module.rb +143 -0
  212. data/lib/chef/resource/selinux_permissive.rb +64 -0
  213. data/lib/chef/resource/selinux_port.rb +118 -0
  214. data/lib/chef/resource/selinux_state.rb +166 -0
  215. data/lib/chef/resource/selinux_user.rb +137 -0
  216. data/lib/chef/resource/service.rb +4 -2
  217. data/lib/chef/resource/smartos_package.rb +2 -1
  218. data/lib/chef/resource/snap_package.rb +25 -1
  219. data/lib/chef/resource/solaris_package.rb +2 -1
  220. data/lib/chef/resource/ssh_known_hosts_entry.rb +0 -1
  221. data/lib/chef/resource/sudo.rb +37 -3
  222. data/lib/chef/resource/support/client.erb +2 -2
  223. data/lib/chef/resource/support/ulimit.erb +40 -0
  224. data/lib/chef/resource/swap_file.rb +0 -1
  225. data/lib/chef/resource/sysctl.rb +2 -2
  226. data/lib/chef/resource/systemd_unit.rb +0 -1
  227. data/lib/chef/resource/template.rb +0 -1
  228. data/lib/chef/resource/timezone.rb +0 -1
  229. data/lib/chef/resource/user/aix_user.rb +0 -1
  230. data/lib/chef/resource/user/linux_user.rb +0 -1
  231. data/lib/chef/resource/user/mac_user.rb +0 -1
  232. data/lib/chef/resource/user/pw_user.rb +0 -1
  233. data/lib/chef/resource/user/solaris_user.rb +0 -1
  234. data/lib/chef/resource/user/windows_user.rb +0 -1
  235. data/lib/chef/resource/user.rb +10 -1
  236. data/lib/chef/resource/user_ulimit.rb +38 -1
  237. data/lib/chef/resource/whyrun_safe_ruby_block.rb +0 -1
  238. data/lib/chef/resource/windows_ad_join.rb +0 -2
  239. data/lib/chef/resource/windows_audit_policy.rb +0 -2
  240. data/lib/chef/resource/windows_auto_run.rb +0 -1
  241. data/lib/chef/resource/windows_certificate.rb +1 -1
  242. data/lib/chef/resource/windows_defender.rb +0 -1
  243. data/lib/chef/resource/windows_defender_exclusion.rb +0 -1
  244. data/lib/chef/resource/windows_dfs_folder.rb +0 -1
  245. data/lib/chef/resource/windows_dfs_namespace.rb +0 -1
  246. data/lib/chef/resource/windows_dfs_server.rb +0 -1
  247. data/lib/chef/resource/windows_dns_record.rb +0 -1
  248. data/lib/chef/resource/windows_dns_zone.rb +0 -1
  249. data/lib/chef/resource/windows_env.rb +0 -1
  250. data/lib/chef/resource/windows_feature.rb +0 -1
  251. data/lib/chef/resource/windows_feature_dism.rb +0 -1
  252. data/lib/chef/resource/windows_feature_powershell.rb +0 -1
  253. data/lib/chef/resource/windows_firewall_profile.rb +0 -2
  254. data/lib/chef/resource/windows_firewall_rule.rb +0 -1
  255. data/lib/chef/resource/windows_font.rb +2 -3
  256. data/lib/chef/resource/windows_package.rb +3 -4
  257. data/lib/chef/resource/windows_pagefile.rb +0 -2
  258. data/lib/chef/resource/windows_path.rb +0 -1
  259. data/lib/chef/resource/windows_printer.rb +0 -1
  260. data/lib/chef/resource/windows_printer_port.rb +0 -1
  261. data/lib/chef/resource/windows_script.rb +0 -2
  262. data/lib/chef/resource/windows_security_policy.rb +2 -3
  263. data/lib/chef/resource/windows_service.rb +0 -1
  264. data/lib/chef/resource/windows_share.rb +0 -1
  265. data/lib/chef/resource/windows_shortcut.rb +1 -2
  266. data/lib/chef/resource/windows_task.rb +0 -1
  267. data/lib/chef/resource/windows_uac.rb +0 -1
  268. data/lib/chef/resource/windows_update_settings.rb +0 -1
  269. data/lib/chef/resource/windows_user_privilege.rb +14 -11
  270. data/lib/chef/resource/windows_workgroup.rb +0 -1
  271. data/lib/chef/resource/yum_package.rb +2 -1
  272. data/lib/chef/resource/yum_repository.rb +4 -1
  273. data/lib/chef/resource/zypper_package.rb +2 -1
  274. data/lib/chef/resource/zypper_repository.rb +0 -1
  275. data/lib/chef/resource.rb +23 -5
  276. data/lib/chef/resource_inspector.rb +25 -7
  277. data/lib/chef/resource_reporter.rb +4 -0
  278. data/lib/chef/resources.rb +11 -0
  279. data/lib/chef/run_context.rb +3 -3
  280. data/lib/chef/secret_fetcher/azure_key_vault.rb +1 -1
  281. data/lib/chef/util/powershell/ps_credential.rb +10 -0
  282. data/lib/chef/version.rb +1 -1
  283. data/lib/chef/win32/handle.rb +6 -7
  284. data/lib/chef/win32/registry.rb +12 -4
  285. data/lib/chef/win32/security.rb +16 -1
  286. data/spec/data/rubygems.org/sexp_processor-info +2 -1
  287. data/spec/data/trusted_certs/intermediate.pem +38 -27
  288. data/spec/functional/resource/cookbook_file_spec.rb +1 -1
  289. data/spec/functional/resource/dsc_script_spec.rb +1 -1
  290. data/spec/functional/resource/execute_spec.rb +1 -1
  291. data/spec/functional/resource/group_spec.rb +26 -42
  292. data/spec/functional/resource/link_spec.rb +8 -8
  293. data/spec/functional/resource/plist_spec.rb +25 -0
  294. data/spec/functional/resource/registry_spec.rb +233 -609
  295. data/spec/functional/resource/remote_file_spec.rb +1 -1
  296. data/spec/functional/resource/user/linux_user_spec.rb +127 -0
  297. data/spec/functional/resource/windows_certificate_spec.rb +1 -1
  298. data/spec/functional/resource/windows_font_spec.rb +12 -9
  299. data/spec/functional/resource/yum_package_spec.rb +1 -1
  300. data/spec/functional/resource/zypper_package_spec.rb +12 -0
  301. data/spec/functional/shell_spec.rb +1 -2
  302. data/spec/functional/version_spec.rb +1 -1
  303. data/spec/functional/win32/registry_spec.rb +0 -3
  304. data/spec/integration/client/client_spec.rb +88 -3
  305. data/spec/integration/client/exit_code_spec.rb +1 -1
  306. data/spec/integration/client/fips_spec.rb +5 -5
  307. data/spec/integration/client/ipv6_spec.rb +1 -1
  308. data/spec/integration/client/open_ssl_spec.rb +3 -3
  309. data/spec/integration/compliance/compliance_spec.rb +1 -1
  310. data/spec/integration/recipes/accumulator_spec.rb +1 -1
  311. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +1 -1
  312. data/spec/integration/recipes/lwrp_spec.rb +1 -1
  313. data/spec/integration/recipes/notifies_spec.rb +1 -1
  314. data/spec/integration/recipes/notifying_block_spec.rb +1 -1
  315. data/spec/integration/recipes/remote_directory.rb +1 -1
  316. data/spec/integration/recipes/unified_mode_spec.rb +1 -1
  317. data/spec/integration/recipes/use_partial_spec.rb +2 -1
  318. data/spec/integration/solo/solo_spec.rb +2 -2
  319. data/spec/spec_helper.rb +7 -4
  320. data/spec/support/chef_helpers.rb +2 -2
  321. data/spec/support/platform_helpers.rb +28 -7
  322. data/spec/support/ruby_installer.rb +1 -1
  323. data/spec/support/shared/functional/file_resource.rb +3 -3
  324. data/spec/support/shared/functional/windows_script.rb +2 -2
  325. data/spec/tiny_server.rb +5 -2
  326. data/spec/unit/application/client_spec.rb +0 -10
  327. data/spec/unit/chef_fs/file_system_spec.rb +2 -0
  328. data/spec/unit/client_spec.rb +80 -4
  329. data/spec/unit/compliance/runner_spec.rb +8 -0
  330. data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
  331. data/spec/unit/data_collector_spec.rb +106 -2
  332. data/spec/unit/delayed_evaluator_spec.rb +35 -0
  333. data/spec/unit/file_cache_spec.rb +64 -0
  334. data/spec/unit/http/authenticator_spec.rb +121 -0
  335. data/spec/unit/mixin/homebrew_spec.rb +118 -0
  336. data/spec/unit/mixin/openssl_helper_spec.rb +5 -0
  337. data/spec/unit/mixin/powershell_exec_spec.rb +5 -5
  338. data/spec/unit/node/vivid_mash_spec.rb +42 -0
  339. data/spec/unit/node_spec.rb +6 -0
  340. data/spec/unit/platform/query_helpers_spec.rb +2 -17
  341. data/spec/unit/property/validation_spec.rb +30 -0
  342. data/spec/unit/provider/apt_repository_spec.rb +48 -12
  343. data/spec/unit/provider/cron_spec.rb +2 -0
  344. data/spec/unit/provider/http_request_spec.rb +60 -72
  345. data/spec/unit/provider/launchd_spec.rb +2 -2
  346. data/spec/unit/provider/mount/aix_spec.rb +2 -2
  347. data/spec/unit/provider/mount/linux_spec.rb +15 -4
  348. data/spec/unit/provider/mount/mount_spec.rb +8 -8
  349. data/spec/unit/provider/package/apt_spec.rb +18 -13
  350. data/spec/unit/provider/package/chocolatey_spec.rb +41 -9
  351. data/spec/unit/provider/package/homebrew_spec.rb +4 -1
  352. data/spec/unit/provider/package/rpm_spec.rb +2 -2
  353. data/spec/unit/provider/package/rubygems_spec.rb +1 -1
  354. data/spec/unit/provider/package/windows_spec.rb +5 -5
  355. data/spec/unit/provider/package/zypper_spec.rb +32 -0
  356. data/spec/unit/provider/powershell_script_spec.rb +100 -4
  357. data/spec/unit/provider/registry_key_spec.rb +17 -17
  358. data/spec/unit/provider/remote_file/http_spec.rb +4 -4
  359. data/spec/unit/provider/service/systemd_service_spec.rb +1 -0
  360. data/spec/unit/provider/user/linux_spec.rb +51 -1
  361. data/spec/unit/provider/user/windows_spec.rb +1 -0
  362. data/spec/unit/provider/user_spec.rb +24 -6
  363. data/spec/unit/resource/apt_repository_spec.rb +5 -0
  364. data/spec/unit/resource/archive_file_spec.rb +1 -1
  365. data/spec/unit/resource/chef_client_cron_spec.rb +5 -0
  366. data/spec/unit/resource/chef_client_launchd_spec.rb +5 -0
  367. data/spec/unit/resource/chef_client_scheduled_task_spec.rb +5 -0
  368. data/spec/unit/resource/chef_client_systemd_timer_spec.rb +1 -1
  369. data/spec/unit/resource/chocolatey_installer_spec.rb +151 -0
  370. data/spec/unit/resource/cron_d_spec.rb +37 -1
  371. data/spec/unit/resource/macos_pkg_spec.rb +38 -0
  372. data/spec/unit/resource/powershell_script_spec.rb +2 -2
  373. data/spec/unit/resource/rest_resource_spec.rb +381 -0
  374. data/spec/unit/resource/selinux_boolean_spec.rb +92 -0
  375. data/spec/unit/resource/selinux_fcontext_spec.rb +65 -0
  376. data/spec/unit/resource/selinux_install_spec.rb +60 -0
  377. data/spec/unit/resource/selinux_login_spec.rb +73 -0
  378. data/spec/unit/resource/selinux_module_spec.rb +55 -0
  379. data/spec/unit/resource/selinux_permissive_spec.rb +39 -0
  380. data/spec/unit/resource/selinux_port_spec.rb +42 -0
  381. data/spec/unit/resource/selinux_state_spec.rb +46 -0
  382. data/spec/unit/resource/selinux_user_spec.rb +92 -0
  383. data/spec/unit/resource/sysctl_spec.rb +2 -2
  384. data/spec/unit/resource/user/linux_user_spec.rb +42 -0
  385. data/spec/unit/resource/yum_repository_spec.rb +4 -0
  386. data/spec/unit/resource_inspector_spec.rb +36 -0
  387. data/spec/unit/resource_reporter_spec.rb +57 -3
  388. data/spec/unit/resource_spec.rb +94 -2
  389. data/spec/unit/util/dsc/local_configuration_manager_spec.rb +1 -1
  390. data/spec/unit/util/powershell/ps_credential_spec.rb +6 -0
  391. data/tasks/rspec.rb +1 -1
  392. metadata +126 -44
  393. data/lib/chef/powershell.rb +0 -81
  394. data/spec/unit/mixin/homebrew_user_spec.rb +0 -119
  395. /data/spec/functional/assets/yumrepo/repodata/{01a3b-filelists.sqlite.bz2 → 4632d67cb92636e7575d911c24f0e04d3505a944e97c483abe0c3e73a7c62d33-filelists.sqlite.bz2} +0 -0
  396. /data/spec/functional/assets/yumrepo/repodata/{6bf96-other.xml.gz → 74599b793e54d877323837d2d81a1c3c594c44e4335f9528234bb490f7b9b439-other.xml.gz} +0 -0
  397. /data/spec/functional/assets/yumrepo/repodata/{5dc1e-primary.sqlite.bz2 → a845d418f919d2115ab95a56b2c76f6825ad0d0bede49181a55c04f58995d057-primary.sqlite.bz2} +0 -0
  398. /data/spec/functional/assets/yumrepo/repodata/{7c365-other.sqlite.bz2 → af9b7cf9ef23bd7b43068d74a460f3b5d06753d638e58e4a0c9edc35bfb9cdc4-other.sqlite.bz2} +0 -0
  399. /data/spec/functional/assets/yumrepo/repodata/{401dc-filelists.xml.gz → bdb4f5f1492a3b9532f22c43110a81500dd744f23da0aec5c33b2a41317c737d-filelists.xml.gz} +0 -0
  400. /data/spec/functional/assets/yumrepo/repodata/{dabe2-primary.xml.gz → c10d1d34ce99e02f12ec96ef68360543ab1bb7c3cb81a4a2bf78df7d8597e9df-primary.xml.gz} +0 -0
@@ -14,10 +14,15 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
  #
17
+ # This uses class variables on purpose to maintain a state cache between resources,
18
+ # since they work on shared state
19
+ #
20
+ # rubocop:disable Style/ClassVars
17
21
 
18
22
  require_relative "../package"
19
23
  require_relative "../../resource/chocolatey_package"
20
24
  require_relative "../../win32/api/command_line_helper" if ChefUtils.windows?
25
+ require "zip" unless defined?(Zip)
21
26
 
22
27
  class Chef
23
28
  class Provider
@@ -32,12 +37,16 @@ class Chef
32
37
  PATHFINDING_POWERSHELL_COMMAND = "[System.Environment]::GetEnvironmentVariable('ChocolateyInstall', 'MACHINE')".freeze
33
38
  CHOCO_MISSING_MSG = <<~EOS.freeze
34
39
  Could not locate your Chocolatey install. To install chocolatey, we recommend
35
- the 'chocolatey' cookbook (https://github.com/chocolatey/chocolatey-cookbook).
40
+ the 'chocolatey_installer' resource.
36
41
  If Chocolatey is installed, ensure that the 'ChocolateyInstall' environment
37
42
  variable is correctly set. You can verify this with the PowerShell command
38
43
  '#{PATHFINDING_POWERSHELL_COMMAND}'.
39
44
  EOS
40
45
 
46
+ # initialize our cache on load
47
+ @@choco_available_packages = nil
48
+ @@choco_config = nil
49
+
41
50
  # Responsible for building the current_resource.
42
51
  #
43
52
  # @return [Chef::Resource::ChocolateyPackage] the current_resource
@@ -45,6 +54,10 @@ class Chef
45
54
  @current_resource = Chef::Resource::ChocolateyPackage.new(new_resource.name)
46
55
  current_resource.package_name(new_resource.package_name)
47
56
  current_resource.version(build_current_versions)
57
+ # Ensure that we have a working chocolatey executable - this used to be
58
+ # covered off by loading the resource, but since that's no longer required,
59
+ # we're going to put a quick check here to fail early!
60
+ choco_exe
48
61
  current_resource
49
62
  end
50
63
 
@@ -131,16 +144,65 @@ class Chef
131
144
  def check_resource_semantics!; end
132
145
 
133
146
  def get_choco_version
134
- @get_choco_version ||= powershell_exec!("#{choco_exe} --version").result
147
+ # We need a different way to get the version than by simply calling "choco --version".
148
+ # If the license file is installed (for business customers) but not the Chocolatey.Extension (because you're using the choco resource to install it)
149
+ # then you get a license error. This method bypasses that by getting the version from the exe directly instead of invoking it.
150
+ # deprecated: @get_choco_version ||= powershell_exec!("#{choco_exe} --version").result
151
+ @get_choco_version ||= powershell_exec!("Get-ItemProperty #{choco_exe} | select-object -expandproperty versioninfo | select-object -expandproperty productversion").result
135
152
  end
136
153
 
137
154
  # Choco V2 uses 'Search' for remote repositories and 'List' for local packages
138
155
  def query_command
139
- return "list" if get_choco_version.match?(/^1/)
156
+ return "list" if Gem::Dependency.new("", "< 1.4.0").match?("", get_choco_version)
140
157
 
141
158
  "search"
142
159
  end
143
160
 
161
+ # invalidate cache for testing purposes
162
+ def invalidate_cache
163
+ @@choco_config = nil
164
+ end
165
+
166
+ # This checks that the repo list has not changed between now and when we last checked
167
+ # the cache
168
+ def cache_is_valid?
169
+ return false if @@choco_config.nil? || (actual_config != @@choco_config)
170
+
171
+ true
172
+ end
173
+
174
+ # Find the set of packages to ask the chocolatey server about
175
+ #
176
+ # if walk_resource_tree is true, this finds _all_ of the packages that
177
+ # we have referenced anywhere in our recipes - this is so we can
178
+ # attempt to query them all in a single transaction. However,
179
+ # currently we don't do that - see the comment on available_packages
180
+ # for details of the why, but the TL;DR is that the public chocolatey
181
+ # servers do not support `or` type queries properly.
182
+ #
183
+ # If walk_resource_tree is false, we don't do any of that - we just filter
184
+ # the package list based on cache data. This is the default due to reasons
185
+ # explained in the comment on available_packages - the goal is to eventually
186
+ # turn this back on, hence the default false parameter here.
187
+ #
188
+ # @return [Array] List of chocolatey packages referenced in the run list
189
+ def collect_package_requests(ignore_list: [], walk_resource_tree: false)
190
+ return ["*"] if new_resource.bulk_query || Chef::Config[:always_use_bulk_chocolatey_package_list]
191
+
192
+ if walk_resource_tree
193
+ # Get to the root of the resource collection
194
+ rc = run_context.parent_run_context || run_context
195
+ rc = rc.parent_run_context while rc.parent_run_context
196
+
197
+ package_collection = package_name_array
198
+ package_collection += nested_package_resources(rc.resource_collection)
199
+ else
200
+ package_collection = package_name_array
201
+ end
202
+ # downcase the array and uniq. sorted for easier testing...
203
+ package_collection.uniq.sort.filter { |pkg| !ignore_list.include?(pkg) }
204
+ end
205
+
144
206
  private
145
207
 
146
208
  def version_compare(v1, v2)
@@ -154,6 +216,22 @@ class Chef
154
216
  gem_v1 <=> gem_v2
155
217
  end
156
218
 
219
+ # Cache the configuration in order to ensure that we can check our
220
+ # package cache is valid for a run
221
+ def actual_config
222
+ config_path = ::File.join("#{choco_install_path}", "config", "chocolatey.config")
223
+ if ::File.exist?(config_path)
224
+ return ::File.read(config_path)
225
+ end
226
+
227
+ nil
228
+ end
229
+
230
+ # update the validity of the package cache
231
+ def set_package_cache
232
+ @@choco_config = actual_config
233
+ end
234
+
157
235
  # Magic to find where chocolatey is installed in the system, and to
158
236
  # return the full path of choco.exe
159
237
  #
@@ -162,7 +240,7 @@ class Chef
162
240
  @choco_exe ||= begin
163
241
  # if this check is in #define_resource_requirements, it won't get
164
242
  # run before choco.exe gets called from #load_current_resource.
165
- exe_path = ::File.join(choco_install_path, "bin", "choco.exe")
243
+ exe_path = ::File.join(choco_install_path, "choco.exe")
166
244
  raise Chef::Exceptions::MissingLibrary, CHOCO_MISSING_MSG unless ::File.exist?(exe_path)
167
245
 
168
246
  exe_path
@@ -171,9 +249,15 @@ class Chef
171
249
 
172
250
  # lets us mock out an incorrect value for testing.
173
251
  def choco_install_path
174
- result = powershell_exec!(PATHFINDING_POWERSHELL_COMMAND).result
175
- result = "" if result.empty?
176
- result
252
+ @choco_install_path ||= begin
253
+ result = powershell_exec!(PATHFINDING_POWERSHELL_COMMAND).result
254
+ result = "" if result.empty?
255
+ result
256
+ end
257
+ end
258
+
259
+ def choco_lib_path
260
+ ::File.join(choco_install_path, "lib")
177
261
  end
178
262
 
179
263
  # Helper to dispatch a choco command through shell_out using the timeout
@@ -214,6 +298,17 @@ class Chef
214
298
  Hash[*lowercase_names(new_resource.package_name).zip(desired_versions).flatten]
215
299
  end
216
300
 
301
+ def nested_package_resources(res)
302
+ package_collection = []
303
+ res.each do |child_res|
304
+ package_collection += nested_package_resources(child_res.resources)
305
+ next unless child_res.is_a?(Chef::Resource::ChocolateyPackage)
306
+
307
+ package_collection += child_res.package_name.flatten
308
+ end
309
+ package_collection
310
+ end
311
+
217
312
  # Helper to construct optional args out of new_resource
218
313
  #
219
314
  # @param include_source [Boolean] should the source parameter be added
@@ -230,37 +325,140 @@ class Chef
230
325
  #
231
326
  # @return [Hash] name-to-version mapping of available packages
232
327
  def available_packages
233
- return @available_packages if @available_packages
328
+ return @available_packages unless @available_packages.nil?
329
+
330
+ # @available_packages is per object - each resource is an object, meaning if you
331
+ # have a LOT of chocolatey package installs, then this quickly gets very slow.
332
+ # So we use @@choco_available_packages instead - BUT it's important to ensure that
333
+ # the cache is valid before you do this. There are two cache items that can change:
334
+ # a) the sources - we check this with cache_is_valid?
335
+ if cache_is_valid? && @@choco_available_packages.is_a?(Hash) &&
336
+ @@choco_available_packages[new_resource.list_options]
337
+
338
+ # Ensure we have the package names, or else double check...
339
+ need_redo = false
340
+ package_name_array.each do |pkg|
341
+ need_redo = true unless @@choco_available_packages[new_resource.list_options][pkg.downcase]
342
+ end
343
+ return @@choco_available_packages[new_resource.list_options] unless need_redo
344
+ end
345
+ if new_resource.list_options
346
+ Chef::Log.info("Fetching chocolatey package list with options #{new_resource.list_options.inspect}")
347
+ else
348
+ Chef::Log.info("Fetching chocolatey package list")
349
+ end
350
+
351
+ # Only reset the array if the cache is invalid - if we're just augmenting it, don't
352
+ # clear it
353
+ @@choco_available_packages = {} if @@choco_available_packages.nil? || !cache_is_valid?
354
+ if @@choco_available_packages[new_resource.list_options].nil?
355
+ @@choco_available_packages[new_resource.list_options] = {}
356
+ end
234
357
 
235
- @available_packages = {}
236
- package_name_array.each do |pkg|
358
+ # This would previously grab 25 packages at a time, which previously worked - however,
359
+ # upstream changed and it turns out this was only working by accident - see
360
+ # https://github.com/chocolatey/choco/issues/2116 for this. So the TL;DR ends up
361
+ # being that this can be re-enabled when the chocolatey server actually supports an
362
+ # or operator. So it makes sense to leave the logic here for this split, while we
363
+ # work with upstream to get this to be a working feature there
364
+ #
365
+ # Foot guns: there is a --id-starts-with for chocolatey, which you'd think would work,
366
+ # but that actually fails on public chocolatey as well, because it seems to do the filtering
367
+ # locally. Which means it too will omit a lot of results (this is also corroborated by
368
+ # the 2116 issue above).
369
+ #
370
+ # collect_package_requests, however, continues to be useful here because it filters
371
+ # the already cached things from the list. However, for now it will no longer walk the
372
+ # resource tree until 2116 can be sorted out. When we regain that ability, we should
373
+ # re-evaluate this, since it does save a LOT of API requests!
374
+ collect_package_requests(
375
+ ignore_list: @@choco_available_packages[new_resource.list_options].keys
376
+ ).each do |pkg_set|
237
377
  available_versions =
238
378
  begin
239
- cmd = [ query_command, "-r", pkg ]
240
- cmd += common_options
241
- cmd.push( new_resource.list_options ) if new_resource.list_options
242
-
243
- raw = parse_list_output(*cmd)
244
- raw.keys.each_with_object({}) do |name, available|
245
- available[name] = desired_name_versions[name] || raw[name]
246
- end
379
+ cmd = [ query_command, "-r" ]
380
+
381
+ # Chocolatey doesn't actually take a wildcard for this query, however
382
+ # it will return all packages when using '*' as a query
383
+ unless pkg_set == "*"
384
+ cmd << pkg_set
385
+ end
386
+ cmd += common_options
387
+ cmd.push( new_resource.list_options ) if new_resource.list_options
388
+
389
+ Chef::Log.debug("Choco List Command: #{cmd}")
390
+
391
+ raw = parse_list_output(*cmd)
392
+ raw.keys.each_with_object({}) do |name, available|
393
+ available[name] = desired_name_versions[name] || raw[name]
247
394
  end
248
- @available_packages.merge! available_versions
395
+ end
396
+ @@choco_available_packages[new_resource.list_options].merge!(available_versions)
249
397
  end
250
- @available_packages
398
+ # Mark the cache as valid, with the required metadata
399
+ set_package_cache
400
+ # Why both? So when we fail to find a package once, we don't try on every
401
+ # retry, even though it would be reasonable to do so if queried in another
402
+ # resource (because the chocolatey configuration may well have changed!)
403
+ @available_packages = @@choco_available_packages[new_resource.list_options]
251
404
  end
252
405
 
253
406
  # Installed packages in chocolatey as a Hash of names mapped to versions
254
- # (names are downcased for case-insensitive matching)
407
+ # (names are downcased for case-insensitive matching). Depending on the user
408
+ # preference, we get these either from the local database, or from the choco
409
+ # list command
255
410
  #
411
+ # @return [Hash] name-to-version mapping of installed packages
412
+ def installed_packages
413
+ # Logic here must be either use_choco_list is false _and_ always_use_choco_list is
414
+ # falsy, since the global overrides the local
415
+ if new_resource.use_choco_list == false && !Chef::Config[:always_use_choco_list]
416
+ installed_packages_via_disk
417
+ else
418
+ installed_packages_via_choco
419
+ end
420
+ end
421
+
256
422
  # Beginning with Choco 2.0, "list" returns local packages only while "search" returns packages from external package sources
257
423
  #
258
424
  # @return [Hash] name-to-version mapping of installed packages
259
- def installed_packages
425
+ def installed_packages_via_choco
260
426
  @installed_packages ||= Hash[*parse_list_output("list", "-l", "-r").flatten]
261
427
  @installed_packages
262
428
  end
263
429
 
430
+ # Return packages sourced from the local disk - because this doesn't have
431
+ # shell out overhead, this ends up being a significant performance win
432
+ # vs calling choco list
433
+ #
434
+ # @return [Hash] name-to-version mapping of installed packages
435
+ def installed_packages_via_disk
436
+ @installed_packages ||= begin
437
+ targets = new_resource.name
438
+ target_dirs = []
439
+ # If we're using a single package name, have it at the head of the list
440
+ # so we can get more performance. In either case, the
441
+ # array is filled by the call to `get_local_pkg_dirs` below - but
442
+ # that contains all possible package folders, and so we push our
443
+ # guess to the front as an optimization.
444
+ target_dirs << targets.first.downcase if targets.length == 1
445
+ if targets.is_a?(String)
446
+ target_dirs << targets.downcase
447
+ end
448
+ target_dirs += get_local_pkg_dirs(choco_lib_path)
449
+ fetch_package_versions(choco_lib_path, target_dirs, targets)
450
+ end
451
+ end
452
+
453
+ # Grab the nupkg folder list
454
+ def get_local_pkg_dirs(base_dir)
455
+ return [] unless Dir.exist?(base_dir)
456
+
457
+ Dir.entries(base_dir).select do |dir|
458
+ ::File.directory?(::File.join(base_dir, dir)) && !dir.start_with?(".")
459
+ end
460
+ end
461
+
264
462
  # Helper to convert choco.exe list output to a Hash
265
463
  # (names are downcased for case-insensitive matching)
266
464
  #
@@ -292,7 +490,47 @@ class Chef
292
490
  args.push( [ "--password", new_resource.password ]) if new_resource.password
293
491
  args
294
492
  end
493
+
494
+ # Fetch the local package versions from chocolatey
495
+ def fetch_package_versions(base_dir, target_dirs, targets)
496
+ pkg_versions = {}
497
+ targets = [targets] if targets.is_a?(String)
498
+ target_dirs.each do |dir|
499
+ pkg_versions.merge!(get_pkg_data(::File.join(base_dir, dir)))
500
+ # return early if we found the single package version we were looking for
501
+ return pkg_versions if targets.length == 1 && pkg_versions[targets.first]
502
+ end
503
+ pkg_versions
504
+ end
505
+
506
+ # Grab the locally installed packages from the nupkg list
507
+ # rather than shelling out to chocolatey
508
+ def get_pkg_data(path)
509
+ t = ::File.join(path, "*.nupkg").gsub("\\", "/")
510
+ targets = Dir.glob(t)
511
+
512
+ # Extract package version from the first nuspec file in this nupkg
513
+ targets.each do |target|
514
+ Zip::File.open(target) do |zip_file|
515
+ zip_file.each do |entry|
516
+ next unless entry.name.end_with?(".nuspec")
517
+
518
+ f = entry.get_input_stream
519
+ doc = REXML::Document.new(f.read.to_s)
520
+ f.close
521
+ id = doc.elements["package/metadata/id"]
522
+ version = doc.elements["package/metadata/version"]
523
+ return { id.text.to_s.downcase => version.text } if id && version
524
+ end
525
+ end
526
+ end
527
+ {}
528
+ rescue StandardError => e
529
+ Chef::Log.warn("Failed to get package info for #{path}: #{e}")
530
+ {}
531
+ end
295
532
  end
296
533
  end
297
534
  end
298
535
  end
536
+ # rubocop:enable Style/ClassVars
@@ -92,6 +92,13 @@ def query(command):
92
92
  q = subj.get_best_query(sack, with_provides=True)
93
93
 
94
94
  if command['action'] == "whatinstalled":
95
+ # When attempting to figure out what is installed, we should ignore any
96
+ # excludes that are configured, otherwise the "best" query for a given
97
+ # subject may refer to a package that is installed that provides that
98
+ # subject, but we really want to know if a package by that name exists
99
+ # in any available repository
100
+ q = subj.get_best_query(sack, with_provides=True, query=sack.query(flags=hawkey.IGNORE_EXCLUDES))
101
+
95
102
  q = q.installed()
96
103
 
97
104
  if command['action'] == "whatavailable":
@@ -18,7 +18,7 @@
18
18
  #
19
19
 
20
20
  require "etc" unless defined?(Etc)
21
- require_relative "../../mixin/homebrew_user"
21
+ require_relative "../../mixin/homebrew"
22
22
 
23
23
  class Chef
24
24
  class Provider
@@ -30,7 +30,7 @@ class Chef
30
30
  provides :package, os: "darwin"
31
31
  provides :homebrew_package
32
32
 
33
- include Chef::Mixin::HomebrewUser
33
+ include Chef::Mixin::Homebrew
34
34
 
35
35
  def load_current_resource
36
36
  @current_resource = Chef::Resource::HomebrewPackage.new(new_resource.name)
@@ -63,9 +63,8 @@ class Chef
63
63
  # and which packages can be upgrades. We do this by checking if brew_info has an entry
64
64
  # via the installed_version helper.
65
65
  def upgrade_package(names, versions)
66
- # @todo when we no longer support Ruby 2.6 this can be simplified to be a .filter_map
67
- upgrade_pkgs = names.select { |x| x if installed_version(x) }.compact
68
- install_pkgs = names.select { |x| x unless installed_version(x) }.compact
66
+ upgrade_pkgs = names.filter_map { |x| x if installed_version(x) }
67
+ install_pkgs = names.filter_map { |x| x unless installed_version(x) }
69
68
 
70
69
  brew_cmd_output("upgrade", options, upgrade_pkgs) unless upgrade_pkgs.empty?
71
70
  brew_cmd_output("install", options, install_pkgs) unless install_pkgs.empty?
@@ -182,7 +181,7 @@ class Chef
182
181
  homebrew_uid = find_homebrew_uid(new_resource.respond_to?(:homebrew_user) && new_resource.homebrew_user)
183
182
  homebrew_user = Etc.getpwuid(homebrew_uid)
184
183
 
185
- logger.trace "Executing 'brew #{command.join(" ")}' as user '#{homebrew_user.name}'"
184
+ logger.trace "Executing '#{homebrew_bin_path} #{command.join(" ")}' as user '#{homebrew_user.name}'"
186
185
 
187
186
  # allow the calling method to decide if the cmd should raise or not
188
187
  # brew_info uses this when querying out available package info since a bad
@@ -190,11 +189,9 @@ class Chef
190
189
  # the package provider can magically handle that
191
190
  shell_out_cmd = options[:allow_failure] ? :shell_out : :shell_out!
192
191
 
193
- # FIXME: this 1800 second default timeout should be deprecated
194
- output = send(shell_out_cmd, "brew", *command, timeout: 1800, user: homebrew_uid, environment: { "HOME" => homebrew_user.dir, "RUBYOPT" => nil, "TMPDIR" => nil })
192
+ output = send(shell_out_cmd, homebrew_bin_path, *command, user: homebrew_uid, login: true, environment: { "HOME" => homebrew_user.dir, "RUBYOPT" => nil, "TMPDIR" => nil })
195
193
  output.stdout.chomp
196
194
  end
197
-
198
195
  end
199
196
  end
200
197
  end
@@ -127,6 +127,7 @@ class Chef
127
127
  command.push("-RequiredVersion #{version}") if version
128
128
  command.push("-Source #{new_resource.source}") if new_resource.source && cmdlet_name =~ Regexp.union(/Install-Package/, /Find-Package/)
129
129
  command.push("-SkipPublisherCheck") if new_resource.skip_publisher_check && cmdlet_name !~ /Find-Package/
130
+ command.push("-AllowClobber") if new_resource.allow_clobber
130
131
  if new_resource.options && cmdlet_name !~ Regexp.union(/Get-Package/, /Find-Package/)
131
132
  new_resource.options.each do |arg|
132
133
  command.push(arg) unless command.include?(arg)
@@ -92,7 +92,7 @@ class Chef
92
92
  #
93
93
  def installed_versions(gem_dep)
94
94
  rubygems_version = Gem::Version.new(Gem::VERSION)
95
- if rubygems_version >= Gem::Version.new("2.7")
95
+ if rubygems_version >= Gem::Version.new("3.1")
96
96
  # In newer Rubygems, bundler is now a "default gem" which means
97
97
  # even with AlternateGemEnvironment when you try to get the
98
98
  # installed versions, you get the one from Chef's Ruby's default
@@ -136,6 +136,10 @@ class Chef
136
136
  if defined?(Gem::Format) && Gem::Package.respond_to?(:open)
137
137
  Gem::Format.from_file_by_path(file).spec
138
138
  else
139
+ # Gem::Package is getting defined as an empty class as of bundler 2.5.23
140
+ # and therefore won't autoload
141
+ # ["bundler-2.5.23/lib/bundler/rubygems_ext.rb", 457]
142
+ require "rubygems/package" if Gem::Package.method(:new).source_location.nil?
139
143
  Gem::Package.new(file).spec
140
144
  end
141
145
  end
@@ -66,7 +66,7 @@ class Chef
66
66
  if new_resource.source
67
67
  install_snap_from_source(names, new_resource.source)
68
68
  else
69
- install_snaps(names)
69
+ install_snaps(names, versions)
70
70
  end
71
71
  end
72
72
 
@@ -218,11 +218,12 @@ class Chef
218
218
  waiting = true
219
219
  while waiting
220
220
  result = get_change_id(id)
221
+
221
222
  case result["result"]["status"]
222
223
  when "Do", "Doing", "Undoing", "Undo"
223
224
  # Continue
224
225
  when "Abort", "Hold", "Error"
225
- raise result
226
+ raise "#{result["result"]["summary"]} - #{result["result"]["status"]} - #{result["result"]["err"]}"
226
227
  when "Done"
227
228
  waiting = false
228
229
  else
@@ -18,7 +18,7 @@
18
18
 
19
19
  # TODO: Allow new_resource.source to be a Product Code as a GUID for uninstall / network install
20
20
 
21
- require_relative "../../../win32/api/installer" if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
21
+ require_relative "../../../win32/api/installer" if RUBY_PLATFORM.match?(/mswin|mingw|windows/)
22
22
  require_relative "../../../mixin/shell_out"
23
23
 
24
24
  class Chef
@@ -26,7 +26,7 @@ class Chef
26
26
  class Package
27
27
  class Windows
28
28
  class MSI
29
- include Chef::ReservedNames::Win32::API::Installer if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
29
+ include Chef::ReservedNames::Win32::API::Installer if RUBY_PLATFORM.match?(/mswin|mingw|windows/)
30
30
  include Chef::Mixin::ShellOut
31
31
 
32
32
  def initialize(resource, uninstall_entries)
@@ -18,7 +18,7 @@
18
18
  #
19
19
 
20
20
  module Win32
21
- autoload :Registry, File.expand_path("../../../monkey_patches/win32/registry", __dir__) if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
21
+ autoload :Registry, File.expand_path("../../../monkey_patches/win32/registry", __dir__) if RUBY_PLATFORM.match?(/mswin|mingw|windows/)
22
22
  end
23
23
 
24
24
  class Chef
@@ -92,8 +92,8 @@ def query(base, command):
92
92
  # then the result was searchNevra'd. please be extremely careful if attempting to fix that
93
93
  # since searchNevra does not support prco tuples.
94
94
  if bool(re.search('\\s+', command['provides'])):
95
- # handles flags (<, >, =, etc) and versions, but no wildcareds
96
- # raises error for any invalid input like: 'FOO BAR BAZ'
95
+ # handles flags (<, >, =, etc) and versions, but no wildcards
96
+ # raises error for any invalid input like: 'FOO BAR BAZ'
97
97
  pkgs = obj.getProvides(*string_to_prco_tuple(command['provides']))
98
98
  elif do_nevra:
99
99
  # now if we're given version or arch properties explicitly, then we do a SearchNevra.
@@ -166,7 +166,7 @@ try:
166
166
 
167
167
  try:
168
168
  command = json.loads(line)
169
- except ValueError, e:
169
+ except ValueError as e:
170
170
  raise RuntimeError("bad json parse")
171
171
 
172
172
  if base is None:
@@ -0,0 +1,60 @@
1
+ #
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ class Chef
19
+ class Provider
20
+ class Package
21
+ class Zypper < Chef::Provider::Package
22
+
23
+ # helper class to assist in passing around name/version/arch triples
24
+ class Version
25
+ attr_accessor :name
26
+ attr_accessor :version
27
+ attr_accessor :arch
28
+
29
+ def initialize(name, version, arch)
30
+ @name = name
31
+ @version = version
32
+ @arch = arch
33
+ end
34
+
35
+ def to_s
36
+ "#{name}-#{version}.#{arch}" unless version.nil?
37
+ end
38
+
39
+ def version_with_arch
40
+ "#{version}.#{arch}" unless version.nil?
41
+ end
42
+
43
+ def name_with_arch
44
+ "#{name}.#{arch}" unless name.nil?
45
+ end
46
+
47
+ def matches_name_and_arch?(other)
48
+ other.version == version && other.arch == arch
49
+ end
50
+
51
+ def ==(other)
52
+ name == other.name && version == other.version && arch == other.arch
53
+ end
54
+
55
+ alias eql? ==
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end