chef 17.10.0 → 18.0.185

Sign up to get free protection for your applications and to get access to all the features.
Files changed (311) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +16 -8
  3. data/README.md +7 -7
  4. data/Rakefile +5 -24
  5. data/{chef-universal-mingw32.gemspec → chef-universal-mingw-ucrt.gemspec} +7 -6
  6. data/chef.gemspec +14 -7
  7. data/lib/chef/api_client_v1.rb +9 -1
  8. data/lib/chef/application/exit_code.rb +3 -3
  9. data/lib/chef/client.rb +167 -0
  10. data/lib/chef/compliance/input.rb +1 -1
  11. data/lib/chef/compliance/input_collection.rb +1 -1
  12. data/lib/chef/compliance/profile.rb +1 -1
  13. data/lib/chef/compliance/profile_collection.rb +1 -2
  14. data/lib/chef/compliance/waiver.rb +1 -1
  15. data/lib/chef/compliance/waiver_collection.rb +1 -1
  16. data/lib/chef/cookbook/syntax_check.rb +2 -2
  17. data/lib/chef/dsl/reader_helpers.rb +1 -1
  18. data/lib/chef/dsl/rest_resource.rb +77 -0
  19. data/lib/chef/dsl/secret.rb +113 -5
  20. data/lib/chef/event_dispatch/base.rb +3 -0
  21. data/lib/chef/exceptions.rb +8 -0
  22. data/lib/chef/http/authenticator.rb +170 -3
  23. data/lib/chef/http/ssl_policies.rb +3 -3
  24. data/lib/chef/mixin/checksum.rb +6 -0
  25. data/lib/chef/mixin/powershell_exec.rb +5 -28
  26. data/lib/chef/mixin/properties.rb +6 -0
  27. data/lib/chef/node/attribute.rb +20 -3
  28. data/lib/chef/node/mixin/deep_merge_cache.rb +4 -4
  29. data/lib/chef/node/mixin/immutablize_array.rb +1 -0
  30. data/lib/chef/property.rb +5 -3
  31. data/lib/chef/provider/cron.rb +5 -1
  32. data/lib/chef/provider/file.rb +2 -2
  33. data/lib/chef/provider/group/windows.rb +1 -1
  34. data/lib/chef/provider/http_request.rb +11 -9
  35. data/lib/chef/provider/mount/linux.rb +5 -0
  36. data/lib/chef/provider/mount/mount.rb +8 -0
  37. data/lib/chef/provider/mount/windows.rb +1 -1
  38. data/lib/chef/provider/package/powershell.rb +1 -1
  39. data/lib/chef/provider/package/rubygems.rb +1 -1
  40. data/lib/chef/provider/package/snap.rb +1 -1
  41. data/lib/chef/provider/package/windows/msi.rb +2 -2
  42. data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +1 -1
  43. data/lib/chef/provider/package/windows.rb +1 -1
  44. data/lib/chef/provider/package/zypper/version.rb +60 -0
  45. data/lib/chef/provider/package/zypper.rb +47 -3
  46. data/lib/chef/provider/service/windows.rb +1 -1
  47. data/lib/chef/provider/user/aix.rb +5 -0
  48. data/lib/chef/provider/user/linux.rb +29 -0
  49. data/lib/chef/provider/user/mac.rb +1 -1
  50. data/lib/chef/provider/user.rb +45 -9
  51. data/lib/chef/provider.rb +1 -1
  52. data/lib/chef/recipe.rb +1 -1
  53. data/lib/chef/resource/_rest_resource.rb +389 -0
  54. data/lib/chef/resource/alternatives.rb +0 -1
  55. data/lib/chef/resource/apt_package.rb +2 -1
  56. data/lib/chef/resource/apt_preference.rb +0 -1
  57. data/lib/chef/resource/apt_repository.rb +0 -1
  58. data/lib/chef/resource/apt_update.rb +0 -1
  59. data/lib/chef/resource/archive_file.rb +0 -1
  60. data/lib/chef/resource/bash.rb +0 -1
  61. data/lib/chef/resource/batch.rb +0 -1
  62. data/lib/chef/resource/bff_package.rb +0 -1
  63. data/lib/chef/resource/breakpoint.rb +0 -1
  64. data/lib/chef/resource/build_essential.rb +0 -1
  65. data/lib/chef/resource/cab_package.rb +0 -1
  66. data/lib/chef/resource/chef_client_config.rb +17 -14
  67. data/lib/chef/resource/chef_client_cron.rb +1 -2
  68. data/lib/chef/resource/chef_client_launchd.rb +2 -2
  69. data/lib/chef/resource/chef_client_scheduled_task.rb +3 -3
  70. data/lib/chef/resource/chef_client_systemd_timer.rb +0 -1
  71. data/lib/chef/resource/chef_client_trusted_certificate.rb +0 -1
  72. data/lib/chef/resource/chef_gem.rb +0 -1
  73. data/lib/chef/resource/chef_handler.rb +0 -1
  74. data/lib/chef/resource/chef_sleep.rb +1 -3
  75. data/lib/chef/resource/chef_vault_secret.rb +0 -1
  76. data/lib/chef/resource/chocolatey_config.rb +0 -1
  77. data/lib/chef/resource/chocolatey_feature.rb +0 -1
  78. data/lib/chef/resource/chocolatey_package.rb +0 -1
  79. data/lib/chef/resource/chocolatey_source.rb +0 -1
  80. data/lib/chef/resource/cookbook_file.rb +0 -1
  81. data/lib/chef/resource/cron/_cron_shared.rb +0 -1
  82. data/lib/chef/resource/cron/cron.rb +0 -1
  83. data/lib/chef/resource/cron/cron_d.rb +15 -1
  84. data/lib/chef/resource/cron_access.rb +0 -1
  85. data/lib/chef/resource/csh.rb +0 -1
  86. data/lib/chef/resource/directory.rb +0 -1
  87. data/lib/chef/resource/dmg_package.rb +2 -1
  88. data/lib/chef/resource/dnf_package.rb +0 -1
  89. data/lib/chef/resource/dpkg_package.rb +0 -1
  90. data/lib/chef/resource/dsc_resource.rb +0 -1
  91. data/lib/chef/resource/dsc_script.rb +0 -1
  92. data/lib/chef/resource/execute.rb +0 -1
  93. data/lib/chef/resource/file.rb +0 -1
  94. data/lib/chef/resource/freebsd_package.rb +2 -1
  95. data/lib/chef/resource/gem_package.rb +2 -1
  96. data/lib/chef/resource/group.rb +25 -2
  97. data/lib/chef/resource/habitat/habitat_package.rb +0 -1
  98. data/lib/chef/resource/habitat/habitat_sup.rb +6 -7
  99. data/lib/chef/resource/habitat/habitat_sup_windows.rb +1 -1
  100. data/lib/chef/resource/habitat_config.rb +0 -1
  101. data/lib/chef/resource/habitat_install.rb +0 -1
  102. data/lib/chef/resource/habitat_service.rb +0 -1
  103. data/lib/chef/resource/habitat_user_toml.rb +0 -1
  104. data/lib/chef/resource/homebrew_cask.rb +0 -1
  105. data/lib/chef/resource/homebrew_package.rb +2 -1
  106. data/lib/chef/resource/homebrew_tap.rb +0 -1
  107. data/lib/chef/resource/homebrew_update.rb +0 -2
  108. data/lib/chef/resource/hostname.rb +0 -1
  109. data/lib/chef/resource/http_request.rb +0 -1
  110. data/lib/chef/resource/ifconfig.rb +0 -1
  111. data/lib/chef/resource/inspec_input.rb +0 -1
  112. data/lib/chef/resource/inspec_waiver.rb +0 -1
  113. data/lib/chef/resource/inspec_waiver_file_entry.rb +2 -3
  114. data/lib/chef/resource/ips_package.rb +0 -1
  115. data/lib/chef/resource/kernel_module.rb +0 -1
  116. data/lib/chef/resource/ksh.rb +0 -1
  117. data/lib/chef/resource/launchd.rb +0 -1
  118. data/lib/chef/resource/link.rb +0 -1
  119. data/lib/chef/resource/locale.rb +1 -2
  120. data/lib/chef/resource/log.rb +0 -1
  121. data/lib/chef/resource/lwrp_base.rb +0 -4
  122. data/lib/chef/resource/macos_userdefaults.rb +0 -1
  123. data/lib/chef/resource/macosx_service.rb +0 -1
  124. data/lib/chef/resource/macports_package.rb +2 -1
  125. data/lib/chef/resource/mdadm.rb +0 -1
  126. data/lib/chef/resource/mount.rb +0 -1
  127. data/lib/chef/resource/msu_package.rb +0 -1
  128. data/lib/chef/resource/notify_group.rb +0 -2
  129. data/lib/chef/resource/ohai.rb +0 -1
  130. data/lib/chef/resource/ohai_hint.rb +0 -1
  131. data/lib/chef/resource/openbsd_package.rb +2 -1
  132. data/lib/chef/resource/openssl_dhparam.rb +0 -2
  133. data/lib/chef/resource/openssl_ec_private_key.rb +0 -2
  134. data/lib/chef/resource/openssl_ec_public_key.rb +0 -2
  135. data/lib/chef/resource/openssl_rsa_private_key.rb +0 -2
  136. data/lib/chef/resource/openssl_rsa_public_key.rb +0 -2
  137. data/lib/chef/resource/openssl_x509_certificate.rb +0 -2
  138. data/lib/chef/resource/openssl_x509_crl.rb +0 -2
  139. data/lib/chef/resource/openssl_x509_request.rb +0 -2
  140. data/lib/chef/resource/osx_profile.rb +0 -1
  141. data/lib/chef/resource/package.rb +0 -1
  142. data/lib/chef/resource/pacman_package.rb +2 -1
  143. data/lib/chef/resource/paludis_package.rb +0 -1
  144. data/lib/chef/resource/perl.rb +0 -1
  145. data/lib/chef/resource/plist.rb +7 -3
  146. data/lib/chef/resource/portage_package.rb +2 -1
  147. data/lib/chef/resource/powershell_package.rb +0 -1
  148. data/lib/chef/resource/powershell_package_source.rb +0 -1
  149. data/lib/chef/resource/powershell_script.rb +0 -1
  150. data/lib/chef/resource/python.rb +0 -1
  151. data/lib/chef/resource/reboot.rb +0 -1
  152. data/lib/chef/resource/registry_key.rb +0 -1
  153. data/lib/chef/resource/remote_directory.rb +0 -1
  154. data/lib/chef/resource/remote_file.rb +0 -1
  155. data/lib/chef/resource/rhsm_errata.rb +0 -1
  156. data/lib/chef/resource/rhsm_errata_level.rb +0 -1
  157. data/lib/chef/resource/rhsm_register.rb +17 -1
  158. data/lib/chef/resource/rhsm_repo.rb +0 -1
  159. data/lib/chef/resource/rhsm_subscription.rb +0 -1
  160. data/lib/chef/resource/route.rb +0 -1
  161. data/lib/chef/resource/rpm_package.rb +2 -1
  162. data/lib/chef/resource/ruby.rb +0 -1
  163. data/lib/chef/resource/ruby_block.rb +0 -1
  164. data/lib/chef/resource/scm/_scm.rb +0 -2
  165. data/lib/chef/resource/scm/git.rb +0 -2
  166. data/lib/chef/resource/scm/subversion.rb +0 -2
  167. data/lib/chef/resource/script.rb +0 -1
  168. data/lib/chef/resource/selinux/common_helpers.rb +47 -0
  169. data/lib/chef/resource/selinux/selinux_debian.erb +18 -0
  170. data/lib/chef/resource/selinux/selinux_default.erb +15 -0
  171. data/lib/chef/resource/selinux_boolean.rb +101 -0
  172. data/lib/chef/resource/selinux_fcontext.rb +160 -0
  173. data/lib/chef/resource/selinux_install.rb +107 -0
  174. data/lib/chef/resource/selinux_module.rb +143 -0
  175. data/lib/chef/resource/selinux_permissive.rb +64 -0
  176. data/lib/chef/resource/selinux_port.rb +118 -0
  177. data/lib/chef/resource/selinux_state.rb +166 -0
  178. data/lib/chef/resource/service.rb +0 -1
  179. data/lib/chef/resource/smartos_package.rb +2 -1
  180. data/lib/chef/resource/snap_package.rb +2 -1
  181. data/lib/chef/resource/solaris_package.rb +2 -1
  182. data/lib/chef/resource/ssh_known_hosts_entry.rb +0 -1
  183. data/lib/chef/resource/sudo.rb +0 -1
  184. data/lib/chef/resource/support/client.erb +3 -4
  185. data/lib/chef/resource/swap_file.rb +0 -1
  186. data/lib/chef/resource/sysctl.rb +1 -2
  187. data/lib/chef/resource/systemd_unit.rb +0 -1
  188. data/lib/chef/resource/template.rb +0 -1
  189. data/lib/chef/resource/timezone.rb +0 -1
  190. data/lib/chef/resource/user/aix_user.rb +0 -1
  191. data/lib/chef/resource/user/linux_user.rb +0 -1
  192. data/lib/chef/resource/user/mac_user.rb +0 -1
  193. data/lib/chef/resource/user/pw_user.rb +0 -1
  194. data/lib/chef/resource/user/solaris_user.rb +0 -1
  195. data/lib/chef/resource/user/windows_user.rb +0 -1
  196. data/lib/chef/resource/user.rb +10 -1
  197. data/lib/chef/resource/user_ulimit.rb +0 -1
  198. data/lib/chef/resource/whyrun_safe_ruby_block.rb +0 -1
  199. data/lib/chef/resource/windows_ad_join.rb +0 -2
  200. data/lib/chef/resource/windows_audit_policy.rb +0 -2
  201. data/lib/chef/resource/windows_auto_run.rb +0 -1
  202. data/lib/chef/resource/windows_certificate.rb +54 -43
  203. data/lib/chef/resource/windows_defender.rb +0 -1
  204. data/lib/chef/resource/windows_defender_exclusion.rb +0 -1
  205. data/lib/chef/resource/windows_dfs_folder.rb +0 -1
  206. data/lib/chef/resource/windows_dfs_namespace.rb +0 -1
  207. data/lib/chef/resource/windows_dfs_server.rb +0 -1
  208. data/lib/chef/resource/windows_dns_record.rb +0 -1
  209. data/lib/chef/resource/windows_dns_zone.rb +0 -1
  210. data/lib/chef/resource/windows_env.rb +0 -1
  211. data/lib/chef/resource/windows_feature.rb +0 -1
  212. data/lib/chef/resource/windows_feature_dism.rb +0 -1
  213. data/lib/chef/resource/windows_feature_powershell.rb +0 -1
  214. data/lib/chef/resource/windows_firewall_profile.rb +0 -2
  215. data/lib/chef/resource/windows_firewall_rule.rb +0 -1
  216. data/lib/chef/resource/windows_font.rb +2 -3
  217. data/lib/chef/resource/windows_package.rb +3 -4
  218. data/lib/chef/resource/windows_pagefile.rb +27 -22
  219. data/lib/chef/resource/windows_path.rb +0 -1
  220. data/lib/chef/resource/windows_printer.rb +0 -1
  221. data/lib/chef/resource/windows_printer_port.rb +0 -1
  222. data/lib/chef/resource/windows_script.rb +0 -2
  223. data/lib/chef/resource/windows_security_policy.rb +0 -1
  224. data/lib/chef/resource/windows_service.rb +0 -1
  225. data/lib/chef/resource/windows_share.rb +0 -1
  226. data/lib/chef/resource/windows_shortcut.rb +1 -2
  227. data/lib/chef/resource/windows_task.rb +0 -1
  228. data/lib/chef/resource/windows_uac.rb +0 -1
  229. data/lib/chef/resource/windows_update_settings.rb +0 -1
  230. data/lib/chef/resource/windows_user_privilege.rb +36 -27
  231. data/lib/chef/resource/windows_workgroup.rb +0 -1
  232. data/lib/chef/resource/yum_package.rb +2 -1
  233. data/lib/chef/resource/yum_repository.rb +0 -1
  234. data/lib/chef/resource/zypper_package.rb +2 -1
  235. data/lib/chef/resource/zypper_repository.rb +0 -1
  236. data/lib/chef/resource.rb +13 -5
  237. data/lib/chef/resources.rb +7 -0
  238. data/lib/chef/run_context.rb +19 -3
  239. data/lib/chef/secret_fetcher/azure_key_vault.rb +3 -3
  240. data/lib/chef/secret_fetcher/hashi_vault.rb +1 -1
  241. data/lib/chef/version.rb +1 -1
  242. data/lib/chef/win32/handle.rb +6 -7
  243. data/lib/chef/win32/registry.rb +7 -3
  244. data/lib/chef/win32/version.rb +2 -1
  245. data/spec/data/rubygems.org/sexp_processor-info +2 -1
  246. data/spec/functional/resource/dsc_script_spec.rb +1 -1
  247. data/spec/functional/resource/group_spec.rb +10 -6
  248. data/spec/functional/resource/link_spec.rb +8 -8
  249. data/spec/functional/resource/plist_spec.rb +25 -0
  250. data/spec/functional/resource/user/linux_user_spec.rb +127 -0
  251. data/spec/functional/resource/windows_certificate_spec.rb +15 -12
  252. data/spec/functional/resource/windows_font_spec.rb +11 -8
  253. data/spec/functional/resource/windows_pagefile_spec.rb +31 -4
  254. data/spec/functional/resource/zypper_package_spec.rb +12 -0
  255. data/spec/functional/shell_spec.rb +7 -2
  256. data/spec/functional/version_spec.rb +1 -1
  257. data/spec/integration/client/client_spec.rb +82 -3
  258. data/spec/integration/client/exit_code_spec.rb +1 -1
  259. data/spec/integration/client/ipv6_spec.rb +1 -1
  260. data/spec/integration/compliance/compliance_spec.rb +1 -1
  261. data/spec/integration/recipes/accumulator_spec.rb +1 -1
  262. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +1 -1
  263. data/spec/integration/recipes/lwrp_spec.rb +1 -1
  264. data/spec/integration/recipes/notifies_spec.rb +1 -1
  265. data/spec/integration/recipes/notifying_block_spec.rb +1 -1
  266. data/spec/integration/recipes/remote_directory.rb +1 -1
  267. data/spec/integration/recipes/unified_mode_spec.rb +1 -1
  268. data/spec/integration/recipes/use_partial_spec.rb +2 -1
  269. data/spec/integration/solo/solo_spec.rb +2 -2
  270. data/spec/spec_helper.rb +1 -0
  271. data/spec/support/platform_helpers.rb +4 -0
  272. data/spec/support/ruby_installer.rb +1 -1
  273. data/spec/support/shared/functional/windows_script.rb +2 -2
  274. data/spec/unit/application/client_spec.rb +0 -10
  275. data/spec/unit/client_spec.rb +54 -2
  276. data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
  277. data/spec/unit/daemon_spec.rb +1 -5
  278. data/spec/unit/dsl/secret_spec.rb +127 -23
  279. data/spec/unit/http/authenticator_spec.rb +68 -0
  280. data/spec/unit/mixin/checksum_spec.rb +28 -0
  281. data/spec/unit/mixin/powershell_exec_spec.rb +5 -5
  282. data/spec/unit/platform/query_helpers_spec.rb +2 -17
  283. data/spec/unit/provider/cron_spec.rb +36 -0
  284. data/spec/unit/provider/http_request_spec.rb +60 -72
  285. data/spec/unit/provider/mount/linux_spec.rb +10 -0
  286. data/spec/unit/provider/package/rubygems_spec.rb +2 -2
  287. data/spec/unit/provider/package/zypper_spec.rb +32 -0
  288. data/spec/unit/provider/user/linux_spec.rb +96 -1
  289. data/spec/unit/provider/user_spec.rb +24 -6
  290. data/spec/unit/resource/archive_file_spec.rb +1 -1
  291. data/spec/unit/resource/chef_client_config_spec.rb +8 -0
  292. data/spec/unit/resource/chef_client_cron_spec.rb +5 -0
  293. data/spec/unit/resource/chef_client_launchd_spec.rb +5 -0
  294. data/spec/unit/resource/chef_client_scheduled_task_spec.rb +5 -0
  295. data/spec/unit/resource/chef_client_systemd_timer_spec.rb +1 -1
  296. data/spec/unit/resource/cron_d_spec.rb +37 -1
  297. data/spec/unit/resource/rest_resource_spec.rb +381 -0
  298. data/spec/unit/resource/selinux_boolean_spec.rb +92 -0
  299. data/spec/unit/resource/selinux_fcontext_spec.rb +65 -0
  300. data/spec/unit/resource/selinux_install_spec.rb +60 -0
  301. data/spec/unit/resource/selinux_module_spec.rb +55 -0
  302. data/spec/unit/resource/selinux_permissive_spec.rb +39 -0
  303. data/spec/unit/resource/selinux_port_spec.rb +42 -0
  304. data/spec/unit/resource/selinux_state_spec.rb +46 -0
  305. data/spec/unit/resource/sysctl_spec.rb +2 -2
  306. data/spec/unit/resource/user/linux_user_spec.rb +42 -0
  307. data/spec/unit/resource_spec.rb +21 -1
  308. data/spec/unit/run_context_spec.rb +16 -0
  309. data/spec/unit/util/dsc/local_configuration_manager_spec.rb +1 -1
  310. data/tasks/rspec.rb +1 -1
  311. metadata +87 -27
@@ -71,6 +71,11 @@ class Chef
71
71
  when /\A#{Regexp.escape(real_mount_point)}\s+#{device_mount_regex}\[/
72
72
  mounted = true
73
73
  logger.trace("Network device #{device_logstring} mounted as #{real_mount_point}")
74
+ # Permalink for network device mounted with a space in device name https://rubular.com/r/CK5zWWms96CRES
75
+ # See the comment in "device_with_space_escape" for an explanation what's going here.
76
+ when /\A#{Regexp.escape(real_mount_point)}\s+#{device_with_space_escape}\s/
77
+ mounted = true
78
+ logger.trace("Network device #{device_logstring} mounted as #{real_mount_point}")
74
79
  end
75
80
  end
76
81
  @current_resource.mounted(mounted)
@@ -217,6 +217,14 @@ class Chef
217
217
  end
218
218
  end
219
219
 
220
+ def device_with_space_escape
221
+ # For CIFS (and perhaps other remote network mounts) when a space is in the "device name"
222
+ # It will appear with the space substituted with a special character. However, when mounting,
223
+ # The mount needs to be done with an actual space. This function provides the device name with
224
+ # The special character to determine if the device is mounted.
225
+ device_mount_regex.gsub(" ", "\\x20")
226
+ end
227
+
220
228
  def device_mount_regex
221
229
  if network_device?
222
230
  # ignore trailing slash
@@ -17,7 +17,7 @@
17
17
  #
18
18
 
19
19
  require_relative "../mount"
20
- if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
20
+ if RUBY_PLATFORM.match?(/mswin|mingw|windows/)
21
21
  require_relative "../../util/windows/net_use"
22
22
  require_relative "../../util/windows/volume"
23
23
  end
@@ -56,7 +56,7 @@ class Chef
56
56
  names.each_with_index do |name, index|
57
57
  cmd = powershell_exec(build_powershell_package_command("Install-Package '#{name}'", versions[index]), timeout: new_resource.timeout)
58
58
  next if cmd.nil?
59
- raise Chef::Exceptions::PowershellCmdletException, "Failed to install package due to catalog signing error, use skip_publisher_check to force install" if /SkipPublisherCheck/.match?(cmd.error)
59
+ raise Chef::Exceptions::PowershellCmdletException, "Failed to install package due to catalog signing error, use skip_publisher_check to force install" if /SkipPublisherCheck/.match?(cmd.error!)
60
60
  end
61
61
  end
62
62
 
@@ -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
@@ -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
 
@@ -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
@@ -38,7 +38,7 @@ class Chef
38
38
  def define_resource_requirements
39
39
  if new_resource.checksum
40
40
  requirements.assert(:install) do |a|
41
- a.assertion { new_resource.checksum == checksum(source_location) }
41
+ a.assertion { checksum_match?(new_resource.checksum, checksum(source_location)) }
42
42
  a.failure_message Chef::Exceptions::Package, "Checksum on resource (#{short_cksum(new_resource.checksum)}) does not match checksum on content (#{short_cksum(source_location)})"
43
43
  end
44
44
  end
@@ -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
@@ -20,17 +20,28 @@
20
20
 
21
21
  require_relative "../package"
22
22
  require_relative "../../resource/zypper_package"
23
+ require_relative "zypper/version"
23
24
 
24
25
  class Chef
25
26
  class Provider
26
27
  class Package
27
28
  class Zypper < Chef::Provider::Package
28
29
  use_multipackage_api
30
+ use_package_name_for_source
29
31
  allow_nils
30
32
 
31
33
  provides :package, platform_family: "suse"
32
34
  provides :zypper_package
33
35
 
36
+ def define_resource_requirements
37
+ super
38
+ requirements.assert(:install, :upgrade) do |a|
39
+ a.assertion { source_files_exist? }
40
+ a.failure_message Chef::Exceptions::Package, "#{new_resource} source file(s) do not exist: #{missing_sources}"
41
+ a.whyrun "Assuming they would have been previously created."
42
+ end
43
+ end
44
+
34
45
  def load_current_resource
35
46
  @current_resource = Chef::Resource::ZypperPackage.new(new_resource.name)
36
47
  current_resource.package_name(new_resource.package_name)
@@ -70,7 +81,35 @@ class Chef
70
81
  end
71
82
 
72
83
  def candidate_version
73
- @candidate_version ||= package_name_array.each_with_index.map { |pkg, i| available_version(i) }
84
+ package_name_array.each_with_index.map do |pkg, i|
85
+ available_version(i)
86
+ end
87
+ end
88
+
89
+ # returns true if all sources exist. Returns false if any do not, or if no
90
+ # sources were specified.
91
+ # @return [Boolean] True if all sources exist
92
+ def source_files_exist?
93
+ if !new_resource.source.nil?
94
+ resolved_source_array.all? { |s| s && ::File.exist?(s) }
95
+ else
96
+ true
97
+ end
98
+ end
99
+
100
+ # Helper to return all the names of the missing sources for error messages.
101
+ # @return [Array<String>] Array of missing sources
102
+ def missing_sources
103
+ resolved_source_array.select { |s| s.nil? || !::File.exist?(s) }
104
+ end
105
+
106
+ def resolve_source_to_version
107
+ shell_out!("rpm -qp --queryformat '%{NAME} %{EPOCH} %{VERSION} %{RELEASE} %{ARCH}\n' #{new_resource.source}").stdout.each_line do |line|
108
+ case line
109
+ when /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/
110
+ return Version.new($1, "#{$2 == "(none)" ? "0" : $2}:#{$3}-#{$4}", $5)
111
+ end
112
+ end
74
113
  end
75
114
 
76
115
  def resolve_current_version(package_name)
@@ -119,7 +158,12 @@ class Chef
119
158
 
120
159
  def available_version(index)
121
160
  @available_version ||= []
122
- @available_version[index] ||= resolve_available_version(package_name_array[index], safe_version_array[index])
161
+
162
+ @available_version[index] ||= if new_resource.source
163
+ resolve_source_to_version
164
+ else
165
+ resolve_available_version(package_name_array[index], safe_version_array[index])
166
+ end
123
167
  @available_version[index]
124
168
  end
125
169
 
@@ -141,7 +185,7 @@ class Chef
141
185
  end
142
186
 
143
187
  def zypper_package(command, global_options, *options, names, versions)
144
- zipped_names = zip(names, versions)
188
+ zipped_names = new_resource.source || zip(names, versions)
145
189
  if zypper_version < 1.0
146
190
  shell_out!("zypper", global_options, gpg_checks, command, *options, "-y", names)
147
191
  else
@@ -20,7 +20,7 @@
20
20
 
21
21
  require_relative "simple"
22
22
  require_relative "../../win32_service_constants"
23
- if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
23
+ if RUBY_PLATFORM.match?(/mswin|mingw|windows/)
24
24
  require_relative "../../win32/error"
25
25
  require "win32/service"
26
26
  end
@@ -23,6 +23,11 @@ class Chef
23
23
  provides :user, os: "aix"
24
24
  provides :aix_user
25
25
 
26
+ # The ruby-shadow gem is not supported on aix.
27
+ def supports_ruby_shadow?
28
+ false
29
+ end
30
+
26
31
  def create_user
27
32
  shell_out!("useradd", universal_options, useradd_options, new_resource.username)
28
33
  add_password
@@ -23,6 +23,27 @@ class Chef
23
23
  provides :linux_user
24
24
  provides :user, os: "linux"
25
25
 
26
+ def load_current_resource
27
+ super
28
+ load_shadow_options
29
+ end
30
+
31
+ def compare_user
32
+ user_changed = super
33
+
34
+ @change_desc ||= []
35
+
36
+ %i{expire_date inactive}.each do |user_attrib|
37
+ new_val = new_resource.send(user_attrib)
38
+ cur_val = current_resource.send(user_attrib)
39
+ if !new_val.nil? && new_val.to_s != cur_val.to_s
40
+ @change_desc << "change #{user_attrib} from #{cur_val} to #{new_val}"
41
+ end
42
+ end
43
+
44
+ user_changed || !@change_desc.empty?
45
+ end
46
+
26
47
  def create_user
27
48
  shell_out!("useradd", universal_options, useradd_options, new_resource.username)
28
49
  end
@@ -52,7 +73,9 @@ class Chef
52
73
  def universal_options
53
74
  opts = []
54
75
  opts << "-c" << new_resource.comment if should_set?(:comment)
76
+ opts << "-e" << new_resource.expire_date if prop_is_set?(:expire_date)
55
77
  opts << "-g" << new_resource.gid if should_set?(:gid)
78
+ opts << "-f" << new_resource.inactive if prop_is_set?(:inactive)
56
79
  opts << "-p" << new_resource.password if should_set?(:password)
57
80
  opts << "-s" << new_resource.shell if should_set?(:shell)
58
81
  opts << "-u" << new_resource.uid if should_set?(:uid)
@@ -116,6 +139,12 @@ class Chef
116
139
  # FIXME: should probably go on the current_resource
117
140
  @locked
118
141
  end
142
+
143
+ def prop_is_set?(prop)
144
+ v = new_resource.send(prop.to_sym)
145
+
146
+ !v.nil? && v != ""
147
+ end
119
148
  end
120
149
  end
121
150
  end
@@ -48,7 +48,7 @@ class Chef
48
48
  if user_plist
49
49
  current_resource.uid(user_plist[:uid][0])
50
50
  current_resource.gid(user_plist[:gid][0])
51
- current_resource.home(user_plist[:home][0])
51
+ current_resource.home(user_plist[:home]&.first) # use &.first since home can be nil
52
52
  current_resource.shell(user_plist[:shell]&.first) # use &.first since shell can be nil
53
53
  current_resource.comment(user_plist[:comment][0])
54
54
 
@@ -66,14 +66,23 @@ class Chef
66
66
  end
67
67
  current_resource.comment(user_info.gecos)
68
68
 
69
- if new_resource.password && current_resource.password == "x"
70
- begin
71
- require "shadow"
72
- rescue LoadError
73
- @shadow_lib_ok = false
74
- else
75
- shadow_info = Shadow::Passwd.getspnam(new_resource.username)
76
- current_resource.password(shadow_info.sp_pwdp)
69
+ begin
70
+ require "shadow"
71
+ rescue LoadError
72
+ @shadow_lib_ok = false
73
+ else
74
+ @shadow_info = Shadow::Passwd.getspnam(new_resource.username)
75
+ # This conditional remains in place until we can sort out whether we need it.
76
+ # Currently removing it causes tests to fail, but that /seems/ to be mocking/setup issues.
77
+ # Some notes for context:
78
+ # 1. Ruby's ETC.getpwnam makes use of /etc/passwd file (https://github.com/ruby/etc/blob/master/ext/etc/etc.c),
79
+ # which returns "x" for a nil password. on AIX it returns a "*"
80
+ # (https://www.ibm.com/docs/bg/aix/7.2?topic=passwords-using-etcpasswd-file)
81
+ # 2. On AIX platforms ruby_shadow does not work as it does not
82
+ # store encrypted passwords in the /etc/passwd file but in /etc/security/passwd file.
83
+ # The AIX provider for user currently declares it does not support ruby-shadow.
84
+ if new_resource.password && current_resource.password == "x"
85
+ current_resource.password(@shadow_info.sp_pwdp)
77
86
  end
78
87
  end
79
88
 
@@ -83,6 +92,27 @@ class Chef
83
92
  current_resource
84
93
  end
85
94
 
95
+ # An overridable for platforms that do not support ruby shadow. This way we
96
+ # can verify that the platform supports ruby shadow before requiring that
97
+ # it be available.
98
+ def supports_ruby_shadow?
99
+ true
100
+ end
101
+
102
+ def load_shadow_options
103
+ unless @shadow_info.nil?
104
+ current_resource.inactive(@shadow_info.sp_inact&.to_i)
105
+ # sp_expire gives time since epoch in days till expiration. Need to convert that
106
+ # to time in seconds since epoch and output date format for comparison
107
+ expire_date = if @shadow_info.sp_expire.nil?
108
+ @shadow_info.sp_expire
109
+ else
110
+ Time.at(@shadow_info.sp_expire * 60 * 60 * 24).strftime("%Y-%m-%d")
111
+ end
112
+ current_resource.expire_date(expire_date)
113
+ end
114
+ end
115
+
86
116
  def define_resource_requirements
87
117
  requirements.assert(:create, :modify, :manage, :lock, :unlock) do |a|
88
118
  a.assertion { @group_name_resolved }
@@ -90,11 +120,17 @@ class Chef
90
120
  a.whyrun "group name #{new_resource.gid} does not exist. This will cause group assignment to fail. Assuming this group will have been created previously."
91
121
  end
92
122
  requirements.assert(:all_actions) do |a|
93
- a.assertion { @shadow_lib_ok }
123
+ a.assertion { !supports_ruby_shadow? || @shadow_lib_ok }
94
124
  a.failure_message Chef::Exceptions::MissingLibrary, "You must have ruby-shadow installed for password support!"
95
125
  a.whyrun "ruby-shadow is not installed. Attempts to set user password will cause failure. Assuming that this gem will have been previously installed." \
96
126
  "Note that user update converge may report false-positive on the basis of mismatched password. "
97
127
  end
128
+ requirements.assert(:all_actions) do |a|
129
+ # either neither linux-only value is set, or we need to be on Linux.
130
+ a.assertion { (!new_resource.expire_date && !new_resource.inactive) || linux? }
131
+ a.failure_message Chef::Exceptions::User, "Properties expire_date and inactive are not supported by this OS or have not been implemented for this OS yet."
132
+ a.whyrun "Properties expire_date and inactive are ignored as they are not supported by this OS or have not been implemented yet for this OS"
133
+ end
98
134
  requirements.assert(:modify, :lock, :unlock) do |a|
99
135
  a.assertion { @user_exists }
100
136
  a.failure_message(Chef::Exceptions::User, "Cannot modify user #{new_resource.username} - does not exist!")
data/lib/chef/provider.rb CHANGED
@@ -113,7 +113,7 @@ class Chef
113
113
  dirname = ::File.dirname(partial)
114
114
  basename = ::File.basename(partial, ".rb")
115
115
  basename = basename[1..] if basename.start_with?("_")
116
- class_eval IO.read(::File.expand_path("#{dirname}/_#{basename}.rb", ::File.dirname(caller_locations.first.absolute_path)))
116
+ class_eval IO.read(::File.expand_path("#{dirname}/_#{basename}.rb", ::File.dirname(caller_locations.first.path)))
117
117
  end
118
118
 
119
119
  # delegate to the resource
data/lib/chef/recipe.rb CHANGED
@@ -101,7 +101,7 @@ class Chef
101
101
  end
102
102
 
103
103
  def from_yaml(string)
104
- res = ::YAML.safe_load(string)
104
+ res = ::YAML.safe_load(string, permitted_classes: [Date])
105
105
  unless res.is_a?(Hash) && res.key?("resources")
106
106
  raise ArgumentError, "YAML recipe '#{source_file}' must contain a top-level 'resources' hash (YAML sequence), i.e. 'resources:'"
107
107
  end