chef 17.10.163 → 18.0.169

Sign up to get free protection for your applications and to get access to all the features.
Files changed (330) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +19 -20
  3. data/README.md +7 -7
  4. data/Rakefile +3 -22
  5. data/{chef-universal-mingw32.gemspec → chef-universal-mingw-ucrt.gemspec} +8 -7
  6. data/chef.gemspec +17 -15
  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 +182 -0
  10. data/lib/chef/compliance/input.rb +1 -1
  11. data/lib/chef/compliance/profile.rb +1 -1
  12. data/lib/chef/compliance/profile_collection.rb +0 -1
  13. data/lib/chef/compliance/waiver.rb +1 -1
  14. data/lib/chef/cookbook/syntax_check.rb +2 -2
  15. data/lib/chef/dsl/reader_helpers.rb +1 -1
  16. data/lib/chef/dsl/rest_resource.rb +77 -0
  17. data/lib/chef/event_dispatch/base.rb +3 -0
  18. data/lib/chef/exceptions.rb +8 -0
  19. data/lib/chef/http/authenticator.rb +170 -3
  20. data/lib/chef/http/ssl_policies.rb +4 -4
  21. data/lib/chef/mixin/checksum.rb +0 -6
  22. data/lib/chef/mixin/homebrew_user.rb +5 -15
  23. data/lib/chef/mixin/openssl_helper.rb +13 -17
  24. data/lib/chef/mixin/powershell_exec.rb +5 -28
  25. data/lib/chef/node/mixin/immutablize_array.rb +1 -0
  26. data/lib/chef/property.rb +5 -3
  27. data/lib/chef/provider/cron.rb +1 -5
  28. data/lib/chef/provider/file.rb +2 -2
  29. data/lib/chef/provider/group/windows.rb +1 -1
  30. data/lib/chef/provider/http_request.rb +11 -9
  31. data/lib/chef/provider/mount/linux.rb +5 -0
  32. data/lib/chef/provider/mount/mount.rb +8 -0
  33. data/lib/chef/provider/mount/windows.rb +1 -1
  34. data/lib/chef/provider/package/chocolatey.rb +1 -14
  35. data/lib/chef/provider/package/rubygems.rb +1 -1
  36. data/lib/chef/provider/package/windows/msi.rb +2 -2
  37. data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +1 -1
  38. data/lib/chef/provider/package/windows.rb +1 -1
  39. data/lib/chef/provider/package/yum/yum_helper.py +14 -2
  40. data/lib/chef/provider/package/zypper/version.rb +60 -0
  41. data/lib/chef/provider/package/zypper.rb +47 -8
  42. data/lib/chef/provider/service/windows.rb +1 -1
  43. data/lib/chef/provider/user/aix.rb +5 -0
  44. data/lib/chef/provider/user/linux.rb +29 -0
  45. data/lib/chef/provider/user/mac.rb +1 -1
  46. data/lib/chef/provider/user.rb +46 -14
  47. data/lib/chef/provider.rb +1 -1
  48. data/lib/chef/recipe.rb +1 -1
  49. data/lib/chef/resource/_rest_resource.rb +389 -0
  50. data/lib/chef/resource/alternatives.rb +0 -1
  51. data/lib/chef/resource/apt_package.rb +0 -1
  52. data/lib/chef/resource/apt_preference.rb +0 -1
  53. data/lib/chef/resource/apt_repository.rb +0 -1
  54. data/lib/chef/resource/apt_update.rb +0 -1
  55. data/lib/chef/resource/archive_file.rb +0 -1
  56. data/lib/chef/resource/bash.rb +0 -1
  57. data/lib/chef/resource/batch.rb +0 -1
  58. data/lib/chef/resource/bff_package.rb +0 -1
  59. data/lib/chef/resource/breakpoint.rb +0 -1
  60. data/lib/chef/resource/build_essential.rb +0 -1
  61. data/lib/chef/resource/cab_package.rb +0 -1
  62. data/lib/chef/resource/chef_client_config.rb +14 -18
  63. data/lib/chef/resource/chef_client_cron.rb +1 -2
  64. data/lib/chef/resource/chef_client_launchd.rb +2 -2
  65. data/lib/chef/resource/chef_client_scheduled_task.rb +3 -3
  66. data/lib/chef/resource/chef_client_systemd_timer.rb +1 -2
  67. data/lib/chef/resource/chef_client_trusted_certificate.rb +0 -1
  68. data/lib/chef/resource/chef_gem.rb +0 -1
  69. data/lib/chef/resource/chef_handler.rb +0 -1
  70. data/lib/chef/resource/chef_sleep.rb +1 -3
  71. data/lib/chef/resource/chef_vault_secret.rb +0 -1
  72. data/lib/chef/resource/chocolatey_config.rb +0 -1
  73. data/lib/chef/resource/chocolatey_feature.rb +0 -1
  74. data/lib/chef/resource/chocolatey_package.rb +0 -1
  75. data/lib/chef/resource/chocolatey_source.rb +0 -1
  76. data/lib/chef/resource/cookbook_file.rb +0 -1
  77. data/lib/chef/resource/cron/_cron_shared.rb +0 -1
  78. data/lib/chef/resource/cron/cron.rb +0 -1
  79. data/lib/chef/resource/cron/cron_d.rb +15 -1
  80. data/lib/chef/resource/cron_access.rb +0 -1
  81. data/lib/chef/resource/csh.rb +0 -1
  82. data/lib/chef/resource/directory.rb +0 -1
  83. data/lib/chef/resource/dmg_package.rb +0 -1
  84. data/lib/chef/resource/dnf_package.rb +0 -1
  85. data/lib/chef/resource/dpkg_package.rb +0 -1
  86. data/lib/chef/resource/dsc_resource.rb +0 -1
  87. data/lib/chef/resource/dsc_script.rb +0 -1
  88. data/lib/chef/resource/execute.rb +0 -1
  89. data/lib/chef/resource/file.rb +0 -1
  90. data/lib/chef/resource/freebsd_package.rb +0 -1
  91. data/lib/chef/resource/gem_package.rb +0 -1
  92. data/lib/chef/resource/group.rb +25 -2
  93. data/lib/chef/resource/habitat/habitat_package.rb +0 -1
  94. data/lib/chef/resource/habitat/habitat_sup.rb +6 -7
  95. data/lib/chef/resource/habitat/habitat_sup_windows.rb +1 -1
  96. data/lib/chef/resource/habitat_config.rb +0 -1
  97. data/lib/chef/resource/habitat_install.rb +0 -1
  98. data/lib/chef/resource/habitat_service.rb +0 -1
  99. data/lib/chef/resource/habitat_user_toml.rb +0 -1
  100. data/lib/chef/resource/homebrew_cask.rb +8 -8
  101. data/lib/chef/resource/homebrew_package.rb +1 -2
  102. data/lib/chef/resource/homebrew_tap.rb +5 -6
  103. data/lib/chef/resource/homebrew_update.rb +0 -2
  104. data/lib/chef/resource/hostname.rb +0 -1
  105. data/lib/chef/resource/http_request.rb +0 -1
  106. data/lib/chef/resource/ifconfig.rb +0 -1
  107. data/lib/chef/resource/inspec_input.rb +0 -1
  108. data/lib/chef/resource/inspec_waiver.rb +0 -1
  109. data/lib/chef/resource/inspec_waiver_file_entry.rb +2 -3
  110. data/lib/chef/resource/ips_package.rb +0 -1
  111. data/lib/chef/resource/kernel_module.rb +0 -1
  112. data/lib/chef/resource/ksh.rb +0 -1
  113. data/lib/chef/resource/launchd.rb +0 -1
  114. data/lib/chef/resource/link.rb +0 -1
  115. data/lib/chef/resource/locale.rb +2 -6
  116. data/lib/chef/resource/log.rb +0 -1
  117. data/lib/chef/resource/lwrp_base.rb +0 -4
  118. data/lib/chef/resource/macos_userdefaults.rb +5 -10
  119. data/lib/chef/resource/macosx_service.rb +0 -1
  120. data/lib/chef/resource/macports_package.rb +0 -1
  121. data/lib/chef/resource/mdadm.rb +0 -1
  122. data/lib/chef/resource/mount.rb +0 -1
  123. data/lib/chef/resource/msu_package.rb +0 -1
  124. data/lib/chef/resource/notify_group.rb +0 -2
  125. data/lib/chef/resource/ohai.rb +0 -1
  126. data/lib/chef/resource/ohai_hint.rb +0 -1
  127. data/lib/chef/resource/openbsd_package.rb +0 -1
  128. data/lib/chef/resource/openssl_dhparam.rb +0 -2
  129. data/lib/chef/resource/openssl_ec_private_key.rb +0 -2
  130. data/lib/chef/resource/openssl_ec_public_key.rb +0 -2
  131. data/lib/chef/resource/openssl_rsa_private_key.rb +0 -2
  132. data/lib/chef/resource/openssl_rsa_public_key.rb +0 -2
  133. data/lib/chef/resource/openssl_x509_certificate.rb +0 -2
  134. data/lib/chef/resource/openssl_x509_crl.rb +0 -2
  135. data/lib/chef/resource/openssl_x509_request.rb +0 -2
  136. data/lib/chef/resource/osx_profile.rb +0 -1
  137. data/lib/chef/resource/package.rb +0 -1
  138. data/lib/chef/resource/pacman_package.rb +0 -1
  139. data/lib/chef/resource/paludis_package.rb +0 -1
  140. data/lib/chef/resource/perl.rb +0 -1
  141. data/lib/chef/resource/plist.rb +7 -3
  142. data/lib/chef/resource/portage_package.rb +0 -1
  143. data/lib/chef/resource/powershell_package.rb +0 -1
  144. data/lib/chef/resource/powershell_package_source.rb +0 -1
  145. data/lib/chef/resource/powershell_script.rb +0 -1
  146. data/lib/chef/resource/python.rb +0 -1
  147. data/lib/chef/resource/reboot.rb +0 -1
  148. data/lib/chef/resource/registry_key.rb +0 -1
  149. data/lib/chef/resource/remote_directory.rb +0 -1
  150. data/lib/chef/resource/remote_file.rb +0 -1
  151. data/lib/chef/resource/rhsm_errata.rb +0 -1
  152. data/lib/chef/resource/rhsm_errata_level.rb +0 -1
  153. data/lib/chef/resource/rhsm_register.rb +0 -3
  154. data/lib/chef/resource/rhsm_repo.rb +0 -1
  155. data/lib/chef/resource/rhsm_subscription.rb +0 -1
  156. data/lib/chef/resource/route.rb +0 -1
  157. data/lib/chef/resource/rpm_package.rb +0 -1
  158. data/lib/chef/resource/ruby.rb +0 -1
  159. data/lib/chef/resource/ruby_block.rb +0 -1
  160. data/lib/chef/resource/scm/_scm.rb +0 -2
  161. data/lib/chef/resource/scm/git.rb +0 -2
  162. data/lib/chef/resource/scm/subversion.rb +0 -2
  163. data/lib/chef/resource/script.rb +0 -1
  164. data/lib/chef/resource/selinux/common_helpers.rb +47 -0
  165. data/lib/chef/resource/selinux/selinux_debian.erb +18 -0
  166. data/lib/chef/resource/selinux/selinux_default.erb +15 -0
  167. data/lib/chef/resource/selinux_boolean.rb +101 -0
  168. data/lib/chef/resource/selinux_fcontext.rb +160 -0
  169. data/lib/chef/resource/selinux_install.rb +107 -0
  170. data/lib/chef/resource/selinux_module.rb +143 -0
  171. data/lib/chef/resource/selinux_permissive.rb +64 -0
  172. data/lib/chef/resource/selinux_port.rb +118 -0
  173. data/lib/chef/resource/selinux_state.rb +166 -0
  174. data/lib/chef/resource/service.rb +0 -1
  175. data/lib/chef/resource/smartos_package.rb +0 -1
  176. data/lib/chef/resource/snap_package.rb +0 -1
  177. data/lib/chef/resource/solaris_package.rb +0 -1
  178. data/lib/chef/resource/ssh_known_hosts_entry.rb +0 -1
  179. data/lib/chef/resource/sudo.rb +0 -1
  180. data/lib/chef/resource/support/client.erb +5 -6
  181. data/lib/chef/resource/swap_file.rb +0 -1
  182. data/lib/chef/resource/sysctl.rb +1 -2
  183. data/lib/chef/resource/systemd_unit.rb +0 -1
  184. data/lib/chef/resource/template.rb +0 -1
  185. data/lib/chef/resource/timezone.rb +0 -1
  186. data/lib/chef/resource/user/aix_user.rb +0 -1
  187. data/lib/chef/resource/user/linux_user.rb +0 -1
  188. data/lib/chef/resource/user/mac_user.rb +0 -1
  189. data/lib/chef/resource/user/pw_user.rb +0 -1
  190. data/lib/chef/resource/user/solaris_user.rb +0 -1
  191. data/lib/chef/resource/user/windows_user.rb +0 -1
  192. data/lib/chef/resource/user.rb +10 -1
  193. data/lib/chef/resource/user_ulimit.rb +0 -1
  194. data/lib/chef/resource/whyrun_safe_ruby_block.rb +0 -1
  195. data/lib/chef/resource/windows_ad_join.rb +0 -2
  196. data/lib/chef/resource/windows_audit_policy.rb +0 -2
  197. data/lib/chef/resource/windows_auto_run.rb +0 -1
  198. data/lib/chef/resource/windows_defender.rb +0 -1
  199. data/lib/chef/resource/windows_defender_exclusion.rb +0 -1
  200. data/lib/chef/resource/windows_dfs_folder.rb +0 -1
  201. data/lib/chef/resource/windows_dfs_namespace.rb +0 -1
  202. data/lib/chef/resource/windows_dfs_server.rb +0 -1
  203. data/lib/chef/resource/windows_dns_record.rb +0 -1
  204. data/lib/chef/resource/windows_dns_zone.rb +0 -1
  205. data/lib/chef/resource/windows_env.rb +0 -1
  206. data/lib/chef/resource/windows_feature.rb +0 -1
  207. data/lib/chef/resource/windows_feature_dism.rb +0 -1
  208. data/lib/chef/resource/windows_feature_powershell.rb +0 -1
  209. data/lib/chef/resource/windows_firewall_profile.rb +0 -2
  210. data/lib/chef/resource/windows_firewall_rule.rb +0 -1
  211. data/lib/chef/resource/windows_font.rb +2 -3
  212. data/lib/chef/resource/windows_package.rb +0 -1
  213. data/lib/chef/resource/windows_pagefile.rb +0 -2
  214. data/lib/chef/resource/windows_path.rb +0 -1
  215. data/lib/chef/resource/windows_printer.rb +0 -1
  216. data/lib/chef/resource/windows_printer_port.rb +0 -1
  217. data/lib/chef/resource/windows_script.rb +0 -2
  218. data/lib/chef/resource/windows_security_policy.rb +0 -1
  219. data/lib/chef/resource/windows_service.rb +0 -1
  220. data/lib/chef/resource/windows_share.rb +0 -1
  221. data/lib/chef/resource/windows_shortcut.rb +1 -2
  222. data/lib/chef/resource/windows_task.rb +0 -1
  223. data/lib/chef/resource/windows_uac.rb +0 -1
  224. data/lib/chef/resource/windows_update_settings.rb +0 -1
  225. data/lib/chef/resource/windows_user_privilege.rb +0 -1
  226. data/lib/chef/resource/windows_workgroup.rb +0 -1
  227. data/lib/chef/resource/yum_package.rb +0 -1
  228. data/lib/chef/resource/yum_repository.rb +0 -1
  229. data/lib/chef/resource/zypper_package.rb +0 -1
  230. data/lib/chef/resource/zypper_repository.rb +0 -1
  231. data/lib/chef/resource.rb +12 -5
  232. data/lib/chef/resources.rb +7 -0
  233. data/lib/chef/run_context.rb +3 -3
  234. data/lib/chef/secret_fetcher/azure_key_vault.rb +1 -1
  235. data/lib/chef/version.rb +1 -1
  236. data/lib/chef/win32/handle.rb +6 -7
  237. data/lib/chef/win32/registry.rb +7 -3
  238. data/spec/data/rubygems.org/sexp_processor-info +2 -1
  239. data/spec/data/trusted_certs/example.crt +20 -29
  240. data/spec/data/trusted_certs/example_no_cn.crt +34 -30
  241. data/spec/data/trusted_certs/opscode.pem +54 -33
  242. data/spec/functional/resource/chocolatey_package_spec.rb +20 -32
  243. data/spec/functional/resource/dsc_script_spec.rb +1 -1
  244. data/spec/functional/resource/group_spec.rb +26 -42
  245. data/spec/functional/resource/link_spec.rb +8 -8
  246. data/spec/functional/resource/macos_userdefaults_spec.rb +4 -4
  247. data/spec/functional/resource/plist_spec.rb +25 -0
  248. data/spec/functional/resource/user/linux_user_spec.rb +127 -0
  249. data/spec/functional/resource/windows_certificate_spec.rb +1 -26
  250. data/spec/functional/resource/windows_font_spec.rb +12 -9
  251. data/spec/functional/resource/yum_package_spec.rb +1 -17
  252. data/spec/functional/resource/zypper_package_spec.rb +12 -10
  253. data/spec/functional/shell_spec.rb +1 -2
  254. data/spec/functional/version_spec.rb +1 -1
  255. data/spec/functional/win32/registry_spec.rb +0 -3
  256. data/spec/integration/client/client_spec.rb +82 -3
  257. data/spec/integration/client/exit_code_spec.rb +1 -1
  258. data/spec/integration/client/ipv6_spec.rb +1 -1
  259. data/spec/integration/compliance/compliance_spec.rb +1 -1
  260. data/spec/integration/recipes/accumulator_spec.rb +1 -1
  261. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +1 -1
  262. data/spec/integration/recipes/lwrp_spec.rb +1 -1
  263. data/spec/integration/recipes/notifies_spec.rb +1 -1
  264. data/spec/integration/recipes/notifying_block_spec.rb +1 -1
  265. data/spec/integration/recipes/remote_directory.rb +1 -1
  266. data/spec/integration/recipes/unified_mode_spec.rb +1 -1
  267. data/spec/integration/recipes/use_partial_spec.rb +2 -1
  268. data/spec/integration/solo/solo_spec.rb +2 -2
  269. data/spec/spec_helper.rb +1 -5
  270. data/spec/support/platform_helpers.rb +0 -4
  271. data/spec/support/ruby_installer.rb +1 -1
  272. data/spec/support/shared/functional/windows_script.rb +2 -2
  273. data/spec/unit/application/client_spec.rb +0 -10
  274. data/spec/unit/client_spec.rb +70 -2
  275. data/spec/unit/compliance/reporter/chef_server_automate_spec.rb +1 -1
  276. data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
  277. data/spec/unit/http/authenticator_spec.rb +68 -0
  278. data/spec/unit/mixin/checksum_spec.rb +0 -28
  279. data/spec/unit/mixin/homebrew_user_spec.rb +7 -30
  280. data/spec/unit/mixin/openssl_helper_spec.rb +1 -1
  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 +0 -34
  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/chocolatey_spec.rb +3 -20
  287. data/spec/unit/provider/package/rubygems_spec.rb +1 -1
  288. data/spec/unit/provider/package/zypper_spec.rb +32 -0
  289. data/spec/unit/provider/user/linux_spec.rb +51 -11
  290. data/spec/unit/provider/user_spec.rb +24 -6
  291. data/spec/unit/resource/archive_file_spec.rb +1 -1
  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 +2 -2
  296. data/spec/unit/resource/cron_d_spec.rb +37 -1
  297. data/spec/unit/resource/macos_user_defaults_spec.rb +4 -4
  298. data/spec/unit/resource/rest_resource_spec.rb +381 -0
  299. data/spec/unit/resource/selinux_boolean_spec.rb +92 -0
  300. data/spec/unit/resource/selinux_fcontext_spec.rb +65 -0
  301. data/spec/unit/resource/selinux_install_spec.rb +60 -0
  302. data/spec/unit/resource/selinux_module_spec.rb +55 -0
  303. data/spec/unit/resource/selinux_permissive_spec.rb +39 -0
  304. data/spec/unit/resource/selinux_port_spec.rb +42 -0
  305. data/spec/unit/resource/selinux_state_spec.rb +46 -0
  306. data/spec/unit/resource/sysctl_spec.rb +2 -2
  307. data/spec/unit/resource/user/linux_user_spec.rb +42 -0
  308. data/spec/unit/resource_spec.rb +8 -2
  309. data/spec/unit/util/dsc/local_configuration_manager_spec.rb +1 -1
  310. data/tasks/rspec.rb +1 -1
  311. metadata +106 -55
  312. data/spec/functional/assets/yumrepo-empty/repodata/01a3b-filelists.sqlite.bz2 +0 -0
  313. data/spec/functional/assets/yumrepo-empty/repodata/401dc-filelists.xml.gz +0 -0
  314. data/spec/functional/assets/yumrepo-empty/repodata/5dc1e-primary.sqlite.bz2 +0 -0
  315. data/spec/functional/assets/yumrepo-empty/repodata/6bf96-other.xml.gz +0 -0
  316. data/spec/functional/assets/yumrepo-empty/repodata/7c365-other.sqlite.bz2 +0 -0
  317. data/spec/functional/assets/yumrepo-empty/repodata/dabe2-primary.xml.gz +0 -0
  318. data/spec/functional/assets/yumrepo-empty/repodata/repomd.xml +0 -55
  319. data/spec/integration/client/fips_spec.rb +0 -29
  320. data/spec/integration/client/open_ssl_spec.rb +0 -20
  321. /data/spec/functional/assets/chocolatey_feed/{test-A.1.0.0.nupkg → test-A.1.0.nupkg} +0 -0
  322. /data/spec/functional/assets/chocolatey_feed/{test-A.1.5.0.nupkg → test-A.1.5.nupkg} +0 -0
  323. /data/spec/functional/assets/chocolatey_feed/{test-A.2.0.0.nupkg → test-A.2.0.nupkg} +0 -0
  324. /data/spec/functional/assets/chocolatey_feed/{test-B.1.0.0.nupkg → test-B.1.0.nupkg} +0 -0
  325. /data/spec/functional/assets/yumrepo/repodata/{01a3b-filelists.sqlite.bz2 → 4632d67cb92636e7575d911c24f0e04d3505a944e97c483abe0c3e73a7c62d33-filelists.sqlite.bz2} +0 -0
  326. /data/spec/functional/assets/yumrepo/repodata/{6bf96-other.xml.gz → 74599b793e54d877323837d2d81a1c3c594c44e4335f9528234bb490f7b9b439-other.xml.gz} +0 -0
  327. /data/spec/functional/assets/yumrepo/repodata/{5dc1e-primary.sqlite.bz2 → a845d418f919d2115ab95a56b2c76f6825ad0d0bede49181a55c04f58995d057-primary.sqlite.bz2} +0 -0
  328. /data/spec/functional/assets/yumrepo/repodata/{7c365-other.sqlite.bz2 → af9b7cf9ef23bd7b43068d74a460f3b5d06753d638e58e4a0c9edc35bfb9cdc4-other.sqlite.bz2} +0 -0
  329. /data/spec/functional/assets/yumrepo/repodata/{401dc-filelists.xml.gz → bdb4f5f1492a3b9532f22c43110a81500dd744f23da0aec5c33b2a41317c737d-filelists.xml.gz} +0 -0
  330. /data/spec/functional/assets/yumrepo/repodata/{dabe2-primary.xml.gz → c10d1d34ce99e02f12ec96ef68360543ab1bb7c3cb81a4a2bf78df7d8597e9df-primary.xml.gz} +0 -0
@@ -0,0 +1,77 @@
1
+ #
2
+ # Copyright:: Copyright 2008-2016, Chef, 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
+ require "chef/constants" unless defined?(NOT_PASSED)
19
+
20
+ class Chef
21
+ module DSL
22
+ module RestResource
23
+ def rest_property_map(rest_property_map = NOT_PASSED)
24
+ if rest_property_map != NOT_PASSED
25
+ rest_property_map = rest_property_map.to_h { |k| [k.to_sym, k] } if rest_property_map.is_a? Array
26
+
27
+ @rest_property_map = rest_property_map
28
+ end
29
+ @rest_property_map
30
+ end
31
+
32
+ # URL to collection
33
+ def rest_api_collection(rest_api_collection = NOT_PASSED)
34
+ if rest_api_collection != NOT_PASSED
35
+ raise ArgumentError, "You must pass an absolute path to rest_api_collection" unless rest_api_collection.start_with? "/"
36
+
37
+ @rest_api_collection = rest_api_collection
38
+ end
39
+
40
+ @rest_api_collection
41
+ end
42
+
43
+ # RFC6570-Templated URL to document
44
+ def rest_api_document(rest_api_document = NOT_PASSED, first_element_only: false)
45
+ if rest_api_document != NOT_PASSED
46
+ raise ArgumentError, "You must pass an absolute path to rest_api_document" unless rest_api_document.start_with? "/"
47
+
48
+ @rest_api_document = rest_api_document
49
+ @rest_api_document_first_element_only = first_element_only
50
+ end
51
+ @rest_api_document
52
+ end
53
+
54
+ # Explicit REST document identity mapping
55
+ def rest_identity_map(rest_identity_map = NOT_PASSED)
56
+ @rest_identity_map = rest_identity_map if rest_identity_map != NOT_PASSED
57
+ @rest_identity_map
58
+ end
59
+
60
+ # Mark up properties for POST only, not PATCH/PUT
61
+ def rest_post_only_properties(rest_post_only_properties = NOT_PASSED)
62
+ if rest_post_only_properties != NOT_PASSED
63
+ @rest_post_only_properties = Array(rest_post_only_properties).map(&:to_sym)
64
+ end
65
+ @rest_post_only_properties || []
66
+ end
67
+
68
+ def rest_api_document_first_element_only(rest_api_document_first_element_only = NOT_PASSED)
69
+ if rest_api_document_first_element_only != NOT_PASSED
70
+ @rest_api_document_first_element_only = rest_api_document_first_element_only
71
+ end
72
+ @rest_api_document_first_element_only
73
+ end
74
+
75
+ end
76
+ end
77
+ end
@@ -273,6 +273,9 @@ class Chef
273
273
  # Called if the converge phase fails
274
274
  def converge_failed(exception); end
275
275
 
276
+ # Called when migrating from a pem on disk to a pem stored in Keychain or Windows Certstore
277
+ def key_migration_status(key_migrated = false); end
278
+
276
279
  # TODO: need events for notification resolve?
277
280
  # def notifications_resolved
278
281
  # end
@@ -561,5 +561,13 @@ class Chef
561
561
  super "before subscription from #{notification.resource} resource cannot be setup to #{notification.notifying_resource} resource, which has already fired while in unified mode"
562
562
  end
563
563
  end
564
+
565
+ class RestError < RuntimeError; end
566
+
567
+ class RestTargetError < RestError; end
568
+
569
+ class RestTimeout < RestError; end
570
+
571
+ class RestOperationFailed < RestError; end
564
572
  end
565
573
  end
@@ -16,16 +16,19 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
+ require "chef/mixin/powershell_exec"
19
20
  require_relative "auth_credentials"
20
21
  require_relative "../exceptions"
22
+ require_relative "../win32/registry"
21
23
  autoload :OpenSSL, "openssl"
22
24
 
23
25
  class Chef
24
26
  class HTTP
25
27
  class Authenticator
26
-
27
28
  DEFAULT_SERVER_API_VERSION = "2".freeze
28
29
 
30
+ extend Chef::Mixin::PowershellExec
31
+
29
32
  attr_reader :signing_key_filename
30
33
  attr_reader :raw_key
31
34
  attr_reader :attr_names
@@ -83,13 +86,69 @@ class Chef
83
86
  @auth_credentials.client_name
84
87
  end
85
88
 
89
+ def detect_certificate_key(client_name)
90
+ self.class.detect_certificate_key(client_name)
91
+ end
92
+
93
+ def check_certstore_for_key(client_name)
94
+ self.class.check_certstore_for_key(client_name)
95
+ end
96
+
97
+ def retrieve_certificate_key(client_name)
98
+ self.class.retrieve_certificate_key(client_name)
99
+ end
100
+
101
+ def get_cert_password
102
+ self.class.get_cert_password
103
+ end
104
+
105
+ def encrypt_pfx_pass
106
+ self.class.encrypt_pfx_pass
107
+ end
108
+
109
+ def decrypt_pfx_pass
110
+ self.class.decrypt_pfx_pass
111
+ end
112
+
113
+ # Detects if a private key exists in a certificate repository like Keychain (macOS) or Certificate Store (Windows)
114
+ #
115
+ # @param client_name - we're using the node name to store and retrieve any keys
116
+ # Returns true if a key is found, false if not. False will trigger a registration event which will lead to a certificate based key being created
117
+ #
118
+ def self.detect_certificate_key(client_name)
119
+ if ChefUtils.windows?
120
+ check_certstore_for_key(client_name)
121
+ else # generic return for Mac and LInux clients
122
+ false
123
+ end
124
+ end
125
+
126
+ def self.check_certstore_for_key(client_name)
127
+ powershell_code = <<~CODE
128
+ $cert = Get-ChildItem -path cert:\\LocalMachine\\My -Recurse -Force | Where-Object { $_.Subject -Match "chef-#{client_name}" } -ErrorAction Stop
129
+ if (($cert.HasPrivateKey -eq $true) -and ($cert.PrivateKey.Key.ExportPolicy -ne "NonExportable")) {
130
+ return $true
131
+ }
132
+ else{
133
+ return $false
134
+ }
135
+ CODE
136
+ powershell_exec!(powershell_code).result
137
+ end
138
+
86
139
  def load_signing_key(key_file, raw_key = nil)
87
- if !!key_file
140
+ results = retrieve_certificate_key(Chef::Config[:node_name])
141
+
142
+ if !!results
143
+ @raw_key = results
144
+ elsif key_file == nil? && raw_key == nil?
145
+ puts "\nNo key detected\n"
146
+ elsif !!key_file
88
147
  @raw_key = IO.read(key_file).strip
89
148
  elsif !!raw_key
90
149
  @raw_key = raw_key.strip
91
150
  else
92
- return nil
151
+ return
93
152
  end
94
153
  # Pass in '' as the passphrase to avoid OpenSSL prompting on the TTY if
95
154
  # given an encrypted key. This also helps if using a single file for
@@ -104,6 +163,114 @@ class Chef
104
163
  raise Chef::Exceptions::InvalidPrivateKey, msg
105
164
  end
106
165
 
166
+ def self.get_cert_password
167
+ @win32registry = Chef::Win32::Registry.new
168
+ path = "HKEY_LOCAL_MACHINE\\Software\\Progress\\Authentication"
169
+ # does the registry key even exist?
170
+ present = @win32registry.get_values(path)
171
+ if present.nil? || present.empty?
172
+ raise Chef::Exceptions::Win32RegKeyMissing
173
+ end
174
+
175
+ present.each do |secret|
176
+ if secret[:name] == "PfxPass"
177
+ password = decrypt_pfx_pass(secret[:data])
178
+ return password
179
+ end
180
+ end
181
+
182
+ raise Chef::Exceptions::Win32RegKeyMissing
183
+
184
+ rescue Chef::Exceptions::Win32RegKeyMissing
185
+ # if we don't have a password, log that and generate one
186
+ Chef::Log.warn "Authentication Hive and values not present in registry, creating them now"
187
+ new_path = "HKEY_LOCAL_MACHINE\\Software\\Progress\\Authentication"
188
+ unless @win32registry.key_exists?(new_path)
189
+ @win32registry.create_key(new_path, true)
190
+ end
191
+ require "securerandom" unless defined?(SecureRandom)
192
+ size = 14
193
+ password = SecureRandom.alphanumeric(size)
194
+ encrypted_pass = encrypt_pfx_pass(password)
195
+ values = { name: "PfxPass", type: :string, data: encrypted_pass }
196
+ @win32registry.set_value(new_path, values)
197
+ password
198
+ end
199
+
200
+ def self.encrypt_pfx_pass(password)
201
+ powershell_code = <<~CODE
202
+ $encrypted_string = ConvertTo-SecureString "#{password}" -AsPlainText -Force
203
+ $secure_string = ConvertFrom-SecureString $encrypted_string
204
+ return $secure_string
205
+ CODE
206
+ powershell_exec!(powershell_code).result
207
+ end
208
+
209
+ def self.decrypt_pfx_pass(password)
210
+ powershell_code = <<~CODE
211
+ $secure_string = "#{password}" | ConvertTo-SecureString
212
+ $string = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR((($secure_string))))
213
+ return $string
214
+ CODE
215
+ powershell_exec!(powershell_code).result
216
+ end
217
+
218
+ def self.retrieve_certificate_key(client_name)
219
+ require "openssl" unless defined?(OpenSSL)
220
+
221
+ if ChefUtils.windows?
222
+ password = get_cert_password
223
+ return false unless password
224
+
225
+ if check_certstore_for_key(client_name)
226
+ ps_blob = powershell_exec!(get_the_key_ps(client_name, password)).result
227
+ file_path = ps_blob["PSPath"].split("::")[1]
228
+ pkcs = OpenSSL::PKCS12.new(File.binread(file_path), password)
229
+
230
+ # We check the pfx we just extracted the private key from
231
+ # if that cert is expiring in 7 days or less we generate a new pfx/p12 object
232
+ # then we post the new public key from that to the client endpoint on
233
+ # chef server.
234
+ File.delete(file_path)
235
+ key_expiring = is_certificate_expiring?(pkcs)
236
+ if key_expiring
237
+ powershell_exec!(delete_old_key_ps(client_name))
238
+ ::Chef::Client.update_key_and_register(Chef::Config[:client_name], pkcs)
239
+ end
240
+
241
+ return pkcs.key.private_to_pem
242
+ end
243
+ end
244
+
245
+ false
246
+ end
247
+
248
+ def self.is_certificate_expiring?(pkcs)
249
+ today = Date.parse(Time.now.utc.iso8601)
250
+ future = Date.parse(pkcs.certificate.not_after.iso8601)
251
+ future.mjd - today.mjd <= 7
252
+ end
253
+
254
+ def self.get_the_key_ps(client_name, password)
255
+ powershell_code = <<~CODE
256
+ Try {
257
+ $my_pwd = ConvertTo-SecureString -String "#{password}" -Force -AsPlainText;
258
+ $cert = Get-ChildItem -path cert:\\LocalMachine\\My -Recurse | Where-Object { $_.Subject -match "chef-#{client_name}$" } -ErrorAction Stop;
259
+ $tempfile = [System.IO.Path]::GetTempPath() + "export_pfx.pfx";
260
+ Export-PfxCertificate -Cert $cert -Password $my_pwd -FilePath $tempfile;
261
+ }
262
+ Catch {
263
+ return $false
264
+ }
265
+ CODE
266
+ end
267
+
268
+ def self.delete_old_key_ps(client_name)
269
+ powershell_code = <<~CODE
270
+ Get-ChildItem -path cert:\\LocalMachine\\My -Recurse | Where-Object { $_.Subject -match "chef-#{client_name}$" } | Remove-Item -ErrorAction Stop;
271
+ CODE
272
+ end
273
+
107
274
  def authentication_headers(method, url, json_body = nil, headers = nil)
108
275
  request_params = {
109
276
  http_method: method,
@@ -88,10 +88,10 @@ class Chef
88
88
  certs = Dir.glob(::File.join(Chef::Util::PathHelper.escape_glob_dir(config.trusted_certs_dir), "*.{crt,pem}"))
89
89
  certs.each do |cert_file|
90
90
  cert = begin
91
- OpenSSL::X509::Certificate.new(::File.binread(cert_file))
91
+ OpenSSL::X509::Certificate.new(::File.binread(cert_file))
92
92
  rescue OpenSSL::X509::CertificateError => e
93
93
  raise Chef::Exceptions::ConfigurationError, "Error reading cert file '#{cert_file}', original error '#{e.class}: #{e.message}'"
94
- end
94
+ end
95
95
  add_trusted_cert(cert)
96
96
  end
97
97
  end
@@ -103,10 +103,10 @@ class Chef
103
103
  unless config[:ssl_client_cert] && config[:ssl_client_key]
104
104
  raise Chef::Exceptions::ConfigurationError, "You must configure ssl_client_cert and ssl_client_key together"
105
105
  end
106
- unless ::File.exist?(config[:ssl_client_cert])
106
+ unless ::File.exists?(config[:ssl_client_cert])
107
107
  raise Chef::Exceptions::ConfigurationError, "The configured ssl_client_cert #{config[:ssl_client_cert]} does not exist"
108
108
  end
109
- unless ::File.exist?(config[:ssl_client_key])
109
+ unless ::File.exists?(config[:ssl_client_key])
110
110
  raise Chef::Exceptions::ConfigurationError, "The configured ssl_client_key #{config[:ssl_client_key]} does not exist"
111
111
  end
112
112
 
@@ -31,12 +31,6 @@ class Chef
31
31
 
32
32
  checksum.slice(0, 6)
33
33
  end
34
-
35
- def checksum_match?(ref_checksum, diff_checksum)
36
- return false if ref_checksum.nil? || diff_checksum.nil?
37
-
38
- ref_checksum.casecmp?(diff_checksum)
39
- end
40
34
  end
41
35
  end
42
36
  end
@@ -57,28 +57,18 @@ class Chef
57
57
  @homebrew_owner_username
58
58
  end
59
59
 
60
- def homebrew_bin_path(brew_bin_path = nil)
61
- if brew_bin_path && ::File.exist?(brew_bin_path)
62
- brew_bin_path
63
- else
64
- [which("brew"), "/opt/homebrew/bin/brew", "/usr/local/bin/brew", "/home/linuxbrew/.linuxbrew/bin/brew"].uniq.select do |x|
65
- next if x == false
66
-
67
- ::File.exist?(x) && ::File.executable?(x)
68
- end.first || nil
69
- end
70
- end
71
-
72
60
  private
73
61
 
74
62
  def calculate_owner
75
- brew_path = homebrew_bin_path
76
- if brew_path
63
+ default_brew_path = "/usr/local/bin/brew"
64
+ if ::File.exist?(default_brew_path)
77
65
  # By default, this follows symlinks which is what we want
66
+ owner = ::File.stat(default_brew_path).uid
67
+ elsif (brew_path = shell_out("which brew").stdout.strip) && !brew_path.empty?
78
68
  owner = ::File.stat(brew_path).uid
79
69
  else
80
70
  raise Chef::Exceptions::CannotDetermineHomebrewOwner,
81
- 'Could not find the "brew" executable anywhere on the path.'
71
+ 'Could not find the "brew" executable in /usr/local/bin or anywhere on the path.'
82
72
  end
83
73
 
84
74
  Chef::Log.debug "Found Homebrew owner #{Etc.getpwuid(owner).name}; executing `brew` commands as them"
@@ -157,7 +157,7 @@ class Chef
157
157
  raise TypeError, "curve must be a string" unless curve.is_a?(String)
158
158
  raise ArgumentError, "Specified curve is not available on this system" unless %w{prime256v1 secp384r1 secp521r1}.include?(curve)
159
159
 
160
- ::OpenSSL::PKey::EC.generate(curve)
160
+ ::OpenSSL::PKey::EC.new(curve).generate_key
161
161
  end
162
162
 
163
163
  # generate pem format of the public key given a private key
@@ -170,22 +170,18 @@ class Chef
170
170
  key_content = ::File.exist?(priv_key) ? File.read(priv_key) : priv_key
171
171
  key = ::OpenSSL::PKey::EC.new key_content, priv_key_password
172
172
 
173
- if windows? || macos? || aix?
174
- # Get curve type (prime256v1...)
175
- group = ::OpenSSL::PKey::EC::Group.new(key.group.curve_name)
176
- # Get Generator point & public point (priv * generator)
177
- generator = group.generator
178
- pub_point = generator.mul(key.private_key)
179
- key.public_key = pub_point
180
-
181
- # Public Key in pem
182
- public_key = ::OpenSSL::PKey::EC.new
183
- public_key.group = group
184
- public_key.public_key = pub_point
185
- public_key.to_pem
186
- else
187
- key.public_to_pem
188
- end
173
+ # Get curve type (prime256v1...)
174
+ group = ::OpenSSL::PKey::EC::Group.new(key.group.curve_name)
175
+ # Get Generator point & public point (priv * generator)
176
+ generator = group.generator
177
+ pub_point = generator.mul(key.private_key)
178
+ key.public_key = pub_point
179
+
180
+ # Public Key in pem
181
+ public_key = ::OpenSSL::PKey::EC.new
182
+ public_key.group = group
183
+ public_key.public_key = pub_point
184
+ public_key.to_pem
189
185
  end
190
186
 
191
187
  # generate a pem file given a cipher, key, an optional key_password
@@ -15,9 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require_relative "../powershell"
19
- require_relative "../pwsh"
20
-
21
18
  # The powershell_exec mixin provides in-process access to the PowerShell engine.
22
19
  #
23
20
  # powershell_exec is initialized with a string that should be set to the script
@@ -94,35 +91,15 @@ require_relative "../pwsh"
94
91
  # - It is not possible to impersonate another user running powershell, the
95
92
  # credentials of the user running Chef Client are used.
96
93
  #
94
+ if ChefUtils.windows?
95
+ require "chef-powershell"
96
+ end
97
97
 
98
98
  class Chef
99
99
  module Mixin
100
100
  module PowershellExec
101
- # Run a command under PowerShell via a managed (.NET) API.
102
- #
103
- # Requires: .NET Framework 4.0 or higher on the target machine.
104
- #
105
- # @param script [String] script to run
106
- # @param interpreter [Symbol] the interpreter type, `:powershell` or `:pwsh`
107
- # @param timeout [Integer, nil] timeout in seconds.
108
- # @return [Chef::PowerShell] output
109
- def powershell_exec(script, interpreter = :powershell, timeout: -1)
110
- case interpreter
111
- when :powershell
112
- Chef::PowerShell.new(script, timeout: timeout)
113
- when :pwsh
114
- Chef::Pwsh.new(script, timeout: timeout)
115
- else
116
- raise ArgumentError, "Expected interpreter of :powershell or :pwsh"
117
- end
118
- end
119
-
120
- # The same as the #powershell_exec method except this will raise
121
- # Chef::PowerShell::CommandFailed if the command fails
122
- def powershell_exec!(script, interpreter = :powershell, **options)
123
- cmd = powershell_exec(script, interpreter, **options)
124
- cmd.error!
125
- cmd
101
+ if ChefUtils.windows?
102
+ include ChefPowerShell::ChefPowerShellModule::PowerShellExec
126
103
  end
127
104
  end
128
105
  end
@@ -73,6 +73,7 @@ class Chef
73
73
  include?
74
74
  index
75
75
  inject
76
+ intersect?
76
77
  intersection
77
78
  join
78
79
  last
data/lib/chef/property.rb CHANGED
@@ -113,9 +113,11 @@ class Chef
113
113
  # and the transformed value returned as output. Lazy values will *not*
114
114
  # be passed to this method until after they are evaluated. Called in the
115
115
  # context of the resource (meaning you can access other properties).
116
- # @option options [Boolean] :required `true` if this property
117
- # must be present; `false` otherwise. This is checked after the resource
118
- # is fully initialized.
116
+ # @option options [Boolean, Array<Symbol>] :required `true` if this property
117
+ # must be present for *all* actions; `false` otherwise. Alternatively
118
+ # you may specify a list of actions the property is required for, when
119
+ # the property is only required for a subset of actions. This is checked
120
+ # after the resource is fully initialized.
119
121
  # @option options [String] :deprecated If set, this property is deprecated and
120
122
  # will create a deprecation warning.
121
123
  #
@@ -88,11 +88,7 @@ class Chef
88
88
 
89
89
  def cron_different?
90
90
  CRON_ATTRIBUTES.any? do |cron_var|
91
- if new_resource.send(cron_var).class == current_resource.send(cron_var).class
92
- new_resource.send(cron_var) != current_resource.send(cron_var)
93
- else
94
- new_resource.send(cron_var).to_s != current_resource.send(cron_var).to_s
95
- end
91
+ new_resource.send(cron_var) != current_resource.send(cron_var)
96
92
  end
97
93
  end
98
94
 
@@ -336,7 +336,7 @@ class Chef
336
336
  end
337
337
 
338
338
  def do_validate_content
339
- if new_resource.checksum && tempfile && !checksum_match?(new_resource.checksum, tempfile_checksum)
339
+ if new_resource.checksum && tempfile && ( new_resource.checksum != tempfile_checksum )
340
340
  raise Chef::Exceptions::ChecksumMismatch.new(short_cksum(new_resource.checksum), short_cksum(tempfile_checksum))
341
341
  end
342
342
 
@@ -450,7 +450,7 @@ class Chef
450
450
 
451
451
  def contents_changed?
452
452
  logger.trace "calculating checksum of #{tempfile.path} to compare with #{current_resource.checksum}"
453
- !checksum_match?(tempfile_checksum, current_resource.checksum)
453
+ tempfile_checksum != current_resource.checksum
454
454
  end
455
455
 
456
456
  def tempfile
@@ -17,7 +17,7 @@
17
17
  #
18
18
 
19
19
  require_relative "../user"
20
- if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
20
+ if RUBY_PLATFORM.match?(/mswin|mingw|windows/)
21
21
  require_relative "../../util/windows/net_group"
22
22
  end
23
23
 
@@ -25,18 +25,20 @@ class Chef
25
25
 
26
26
  provides :http_request
27
27
 
28
- attr_accessor :http
28
+ attr_writer :http
29
29
 
30
- def load_current_resource
31
- @http = Chef::HTTP::Simple.new(new_resource.url)
30
+ def http
31
+ @http ||= Chef::HTTP::Simple.new(new_resource.url)
32
32
  end
33
33
 
34
+ def load_current_resource; end
35
+
34
36
  # Send a HEAD request to new_resource.url
35
37
  action :head do
36
38
  message = check_message(new_resource.message)
37
39
  # CHEF-4762: we expect a nil return value from Chef::HTTP for a "200 Success" response
38
40
  # and false for a "304 Not Modified" response
39
- modified = @http.head(
41
+ modified = http.head(
40
42
  (new_resource.url).to_s,
41
43
  new_resource.headers
42
44
  )
@@ -53,7 +55,7 @@ class Chef
53
55
  converge_by("#{new_resource} GET to #{new_resource.url}") do
54
56
 
55
57
  message = check_message(new_resource.message)
56
- body = @http.get(
58
+ body = http.get(
57
59
  (new_resource.url).to_s,
58
60
  new_resource.headers
59
61
  )
@@ -66,7 +68,7 @@ class Chef
66
68
  action :patch do
67
69
  converge_by("#{new_resource} PATCH to #{new_resource.url}") do
68
70
  message = check_message(new_resource.message)
69
- body = @http.patch(
71
+ body = http.patch(
70
72
  (new_resource.url).to_s,
71
73
  message,
72
74
  new_resource.headers
@@ -80,7 +82,7 @@ class Chef
80
82
  action :put do
81
83
  converge_by("#{new_resource} PUT to #{new_resource.url}") do
82
84
  message = check_message(new_resource.message)
83
- body = @http.put(
85
+ body = http.put(
84
86
  (new_resource.url).to_s,
85
87
  message,
86
88
  new_resource.headers
@@ -94,7 +96,7 @@ class Chef
94
96
  action :post do
95
97
  converge_by("#{new_resource} POST to #{new_resource.url}") do
96
98
  message = check_message(new_resource.message)
97
- body = @http.post(
99
+ body = http.post(
98
100
  (new_resource.url).to_s,
99
101
  message,
100
102
  new_resource.headers
@@ -107,7 +109,7 @@ class Chef
107
109
  # Send a DELETE request to new_resource.url
108
110
  action :delete do
109
111
  converge_by("#{new_resource} DELETE to #{new_resource.url}") do
110
- body = @http.delete(
112
+ body = http.delete(
111
113
  (new_resource.url).to_s,
112
114
  new_resource.headers
113
115
  )
@@ -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