chef 15.17.4 → 16.0.257

Sign up to get free protection for your applications and to get access to all the features.
Files changed (569) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +14 -20
  3. data/README.md +6 -6
  4. data/Rakefile +18 -23
  5. data/chef-universal-mingw32.gemspec +4 -4
  6. data/chef.gemspec +10 -26
  7. data/lib/chef/action_collection.rb +16 -5
  8. data/lib/chef/api_client/registration.rb +2 -2
  9. data/lib/chef/application.rb +33 -54
  10. data/lib/chef/application/apply.rb +20 -3
  11. data/lib/chef/application/base.rb +8 -3
  12. data/lib/chef/application/exit_code.rb +2 -2
  13. data/lib/chef/application/knife.rb +1 -1
  14. data/lib/chef/chef_class.rb +4 -4
  15. data/lib/chef/chef_fs/chef_fs_data_store.rb +3 -3
  16. data/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb +1 -1
  17. data/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb +1 -1
  18. data/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb +6 -2
  19. data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +1 -1
  20. data/lib/chef/chef_fs/file_system/repository/base_file.rb +0 -1
  21. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb +2 -2
  22. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +1 -1
  23. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +5 -5
  24. data/lib/chef/chef_fs/file_system/repository/directory.rb +1 -1
  25. data/lib/chef/chef_fs/file_system/repository/file_system_entry.rb +1 -1
  26. data/lib/chef/chef_fs/path_utils.rb +3 -3
  27. data/lib/chef/client.rb +16 -14
  28. data/lib/chef/config.rb +1 -1
  29. data/lib/chef/cookbook/file_system_file_vendor.rb +1 -1
  30. data/lib/chef/cookbook/gem_installer.rb +1 -1
  31. data/lib/chef/cookbook/metadata.rb +45 -22
  32. data/lib/chef/cookbook_version.rb +40 -5
  33. data/lib/chef/data_bag.rb +2 -2
  34. data/lib/chef/data_collector/error_handlers.rb +1 -1
  35. data/lib/chef/data_collector/run_end_message.rb +7 -1
  36. data/lib/chef/deprecated.rb +1 -9
  37. data/lib/chef/dist.rb +8 -0
  38. data/lib/chef/dsl/chef_vault.rb +84 -0
  39. data/lib/chef/dsl/declare_resource.rb +7 -5
  40. data/lib/chef/dsl/platform_introspection.rb +2 -3
  41. data/lib/chef/dsl/recipe.rb +7 -12
  42. data/lib/chef/dsl/universal.rb +3 -7
  43. data/lib/chef/environment.rb +2 -2
  44. data/lib/chef/event_dispatch/base.rb +3 -0
  45. data/lib/chef/exceptions.rb +0 -3
  46. data/lib/chef/formatters/doc.rb +1 -1
  47. data/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb +2 -2
  48. data/lib/chef/formatters/error_inspectors/registration_error_inspector.rb +7 -7
  49. data/lib/chef/formatters/indentable_output_stream.rb +7 -16
  50. data/lib/chef/http.rb +1 -2
  51. data/lib/chef/http/http_request.rb +3 -2
  52. data/lib/chef/knife.rb +1 -3
  53. data/lib/chef/knife/acl_add.rb +57 -0
  54. data/lib/chef/knife/acl_base.rb +183 -0
  55. data/lib/chef/knife/acl_bulk_add.rb +78 -0
  56. data/lib/chef/knife/acl_bulk_remove.rb +83 -0
  57. data/lib/chef/knife/acl_remove.rb +62 -0
  58. data/lib/chef/knife/acl_show.rb +56 -0
  59. data/lib/chef/knife/bootstrap.rb +93 -97
  60. data/lib/chef/knife/bootstrap/chef_vault_handler.rb +1 -1
  61. data/lib/chef/knife/bootstrap/client_builder.rb +1 -1
  62. data/lib/chef/knife/bootstrap/templates/chef-full.erb +20 -20
  63. data/lib/chef/knife/bootstrap/templates/windows-chef-client-msi.erb +13 -15
  64. data/lib/chef/knife/bootstrap/train_connector.rb +0 -1
  65. data/lib/chef/knife/cookbook_download.rb +1 -1
  66. data/lib/chef/knife/cookbook_metadata.rb +1 -1
  67. data/lib/chef/knife/core/bootstrap_context.rb +63 -60
  68. data/lib/chef/knife/core/gem_glob_loader.rb +1 -1
  69. data/lib/chef/knife/core/generic_presenter.rb +4 -3
  70. data/lib/chef/knife/core/hashed_command_loader.rb +2 -3
  71. data/lib/chef/knife/core/node_presenter.rb +2 -2
  72. data/lib/chef/knife/core/status_presenter.rb +5 -5
  73. data/lib/chef/knife/core/subcommand_loader.rb +1 -1
  74. data/lib/chef/knife/core/ui.rb +17 -1
  75. data/lib/chef/knife/core/windows_bootstrap_context.rb +45 -58
  76. data/lib/chef/knife/data_bag_secret_options.rb +18 -45
  77. data/lib/chef/knife/environment_compare.rb +1 -1
  78. data/lib/chef/knife/exec.rb +2 -2
  79. data/lib/chef/knife/group_add.rb +55 -0
  80. data/lib/chef/knife/{cookbook_site_download.rb → group_create.rb} +21 -12
  81. data/lib/chef/knife/group_destroy.rb +53 -0
  82. data/lib/chef/knife/{cookbook_site_list.rb → group_list.rb} +14 -11
  83. data/lib/chef/knife/group_remove.rb +56 -0
  84. data/lib/chef/knife/{cookbook_site_install.rb → group_show.rb} +21 -12
  85. data/lib/chef/knife/list.rb +1 -1
  86. data/lib/chef/knife/ssh.rb +12 -50
  87. data/lib/chef/knife/status.rb +3 -3
  88. data/lib/chef/knife/supermarket_download.rb +1 -2
  89. data/lib/chef/knife/supermarket_install.rb +1 -2
  90. data/lib/chef/knife/supermarket_list.rb +1 -2
  91. data/lib/chef/knife/supermarket_search.rb +1 -2
  92. data/lib/chef/knife/supermarket_share.rb +1 -2
  93. data/lib/chef/knife/supermarket_show.rb +1 -2
  94. data/lib/chef/knife/supermarket_unshare.rb +1 -2
  95. data/lib/chef/knife/{cookbook_site_show.rb → user_dissociate.rb} +15 -13
  96. data/lib/chef/knife/{cookbook_site_search.rb → user_invite_add.rb} +16 -13
  97. data/lib/chef/knife/user_invite_list.rb +34 -0
  98. data/lib/chef/knife/user_invite_recind.rb +63 -0
  99. data/lib/chef/knife/yaml_convert.rb +91 -0
  100. data/lib/chef/log.rb +1 -1
  101. data/lib/chef/mixin/create_path.rb +8 -8
  102. data/lib/chef/mixin/openssl_helper.rb +3 -26
  103. data/lib/chef/mixin/powershell_exec.rb +10 -1
  104. data/lib/chef/mixin/powershell_out.rb +1 -1
  105. data/lib/chef/mixin/properties.rb +13 -1
  106. data/lib/chef/mixin/shell_out.rb +0 -4
  107. data/lib/chef/mixin/template.rb +0 -1
  108. data/lib/chef/monkey_patches/net_http.rb +0 -4
  109. data/lib/chef/node.rb +18 -6
  110. data/lib/chef/node/mixin/deep_merge_cache.rb +7 -7
  111. data/lib/chef/node/mixin/immutablize_array.rb +4 -0
  112. data/lib/chef/node/mixin/immutablize_hash.rb +3 -0
  113. data/lib/chef/node_map.rb +7 -36
  114. data/lib/chef/platform/priority_map.rb +4 -4
  115. data/lib/chef/platform/query_helpers.rb +6 -34
  116. data/lib/chef/powershell.rb +14 -0
  117. data/lib/chef/property.rb +22 -4
  118. data/lib/chef/provider.rb +40 -6
  119. data/lib/chef/provider/cron.rb +2 -2
  120. data/lib/chef/provider/directory.rb +2 -2
  121. data/lib/chef/provider/dsc_resource.rb +1 -1
  122. data/lib/chef/provider/dsc_script.rb +1 -1
  123. data/lib/chef/provider/execute.rb +2 -8
  124. data/lib/chef/provider/file.rb +5 -5
  125. data/lib/chef/provider/git.rb +84 -27
  126. data/lib/chef/provider/group.rb +4 -4
  127. data/lib/chef/provider/http_request.rb +6 -6
  128. data/lib/chef/provider/ifconfig.rb +4 -4
  129. data/lib/chef/provider/launchd.rb +36 -51
  130. data/lib/chef/provider/link.rb +2 -2
  131. data/lib/chef/provider/mount.rb +5 -5
  132. data/lib/chef/provider/mount/solaris.rb +1 -0
  133. data/lib/chef/provider/osx_profile.rb +7 -3
  134. data/lib/chef/provider/package.rb +2 -2
  135. data/lib/chef/provider/package/cab.rb +3 -4
  136. data/lib/chef/provider/package/chocolatey.rb +1 -3
  137. data/lib/chef/provider/package/dnf.rb +66 -10
  138. data/lib/chef/provider/package/dnf/dnf_helper.py +84 -30
  139. data/lib/chef/provider/package/dnf/python_helper.rb +79 -36
  140. data/lib/chef/provider/package/dnf/version.rb +5 -1
  141. data/lib/chef/provider/package/freebsd/pkgng.rb +1 -3
  142. data/lib/chef/provider/package/homebrew.rb +106 -42
  143. data/lib/chef/provider/package/msu.rb +3 -1
  144. data/lib/chef/provider/package/pacman.rb +25 -34
  145. data/lib/chef/provider/package/powershell.rb +2 -6
  146. data/lib/chef/provider/package/rubygems.rb +29 -2
  147. data/lib/chef/provider/package/snap.rb +27 -96
  148. data/lib/chef/provider/package/windows.rb +3 -2
  149. data/lib/chef/provider/package/windows/msi.rb +2 -2
  150. data/lib/chef/provider/package/yum.rb +0 -8
  151. data/lib/chef/provider/package/yum/yum_helper.py +0 -4
  152. data/lib/chef/provider/package/zypper.rb +1 -1
  153. data/lib/chef/provider/powershell_script.rb +4 -10
  154. data/lib/chef/provider/registry_key.rb +4 -4
  155. data/lib/chef/provider/remote_directory.rb +3 -3
  156. data/lib/chef/provider/remote_file/ftp.rb +3 -2
  157. data/lib/chef/provider/remote_file/local_file.rb +2 -1
  158. data/lib/chef/provider/remote_file/sftp.rb +3 -2
  159. data/lib/chef/provider/route.rb +5 -3
  160. data/lib/chef/provider/ruby_block.rb +1 -1
  161. data/lib/chef/provider/script.rb +2 -2
  162. data/lib/chef/provider/service.rb +8 -8
  163. data/lib/chef/provider/service/aixinit.rb +1 -1
  164. data/lib/chef/provider/service/arch.rb +2 -2
  165. data/lib/chef/provider/service/debian.rb +31 -29
  166. data/lib/chef/provider/service/gentoo.rb +2 -2
  167. data/lib/chef/provider/service/macosx.rb +7 -12
  168. data/lib/chef/provider/service/openbsd.rb +1 -1
  169. data/lib/chef/provider/service/redhat.rb +2 -2
  170. data/lib/chef/provider/service/simple.rb +3 -3
  171. data/lib/chef/provider/service/systemd.rb +12 -12
  172. data/lib/chef/provider/service/upstart.rb +1 -1
  173. data/lib/chef/provider/service/windows.rb +5 -11
  174. data/lib/chef/provider/subversion.rb +25 -5
  175. data/lib/chef/provider/systemd_unit.rb +26 -25
  176. data/lib/chef/provider/user.rb +6 -6
  177. data/lib/chef/provider/user/dscl.rb +3 -3
  178. data/lib/chef/provider/user/mac.rb +10 -9
  179. data/lib/chef/provider/whyrun_safe_ruby_block.rb +1 -1
  180. data/lib/chef/provider/windows_env.rb +3 -3
  181. data/lib/chef/provider/windows_script.rb +2 -2
  182. data/lib/chef/provider/windows_task.rb +7 -9
  183. data/lib/chef/provider/yum_repository.rb +1 -1
  184. data/lib/chef/provider/zypper_repository.rb +11 -31
  185. data/lib/chef/providers.rb +0 -6
  186. data/lib/chef/recipe.rb +36 -0
  187. data/lib/chef/resource.rb +41 -56
  188. data/lib/chef/resource/action_class.rb +24 -22
  189. data/lib/chef/resource/alternatives.rb +149 -0
  190. data/lib/chef/resource/apt_package.rb +2 -1
  191. data/lib/chef/resource/apt_preference.rb +69 -2
  192. data/lib/chef/resource/apt_repository.rb +337 -5
  193. data/lib/chef/resource/apt_update.rb +52 -1
  194. data/lib/chef/resource/archive_file.rb +9 -29
  195. data/lib/chef/resource/bash.rb +2 -0
  196. data/lib/chef/resource/bff_package.rb +9 -1
  197. data/lib/chef/resource/breakpoint.rb +0 -1
  198. data/lib/chef/resource/build_essential.rb +42 -48
  199. data/lib/chef/resource/cab_package.rb +8 -1
  200. data/lib/chef/resource/chef_client_cron.rb +225 -0
  201. data/lib/chef/resource/chef_client_scheduled_task.rb +198 -0
  202. data/lib/chef/resource/chef_client_systemd_timer.rb +177 -0
  203. data/lib/chef/resource/chef_gem.rb +9 -16
  204. data/lib/chef/resource/chef_handler.rb +2 -1
  205. data/lib/chef/resource/chef_sleep.rb +0 -1
  206. data/lib/chef/resource/chef_vault_secret.rb +135 -0
  207. data/lib/chef/resource/chocolatey_config.rb +3 -1
  208. data/lib/chef/resource/chocolatey_feature.rb +2 -1
  209. data/lib/chef/resource/chocolatey_package.rb +2 -1
  210. data/lib/chef/resource/chocolatey_source.rb +2 -1
  211. data/lib/chef/resource/cookbook_file.rb +1 -1
  212. data/lib/chef/resource/cron.rb +22 -68
  213. data/lib/chef/resource/cron_access.rb +8 -15
  214. data/lib/chef/resource/cron_d.rb +9 -75
  215. data/lib/chef/resource/csh.rb +2 -0
  216. data/lib/chef/resource/directory.rb +2 -2
  217. data/lib/chef/resource/dmg_package.rb +4 -4
  218. data/lib/chef/resource/dnf_package.rb +2 -3
  219. data/lib/chef/resource/dpkg_package.rb +2 -1
  220. data/lib/chef/resource/dsc_resource.rb +6 -4
  221. data/lib/chef/resource/dsc_script.rb +3 -2
  222. data/lib/chef/resource/execute.rb +13 -12
  223. data/lib/chef/resource/file.rb +3 -1
  224. data/lib/chef/resource/freebsd_package.rb +2 -1
  225. data/lib/chef/resource/gem_package.rb +14 -6
  226. data/lib/chef/resource/group.rb +4 -1
  227. data/lib/chef/resource/helpers/cron_validations.rb +98 -0
  228. data/lib/chef/resource/homebrew_cask.rb +5 -4
  229. data/lib/chef/resource/homebrew_package.rb +4 -2
  230. data/lib/chef/resource/homebrew_tap.rb +2 -1
  231. data/lib/chef/resource/hostname.rb +41 -36
  232. data/lib/chef/resource/http_request.rb +0 -1
  233. data/lib/chef/resource/ifconfig.rb +1 -1
  234. data/lib/chef/resource/ips_package.rb +10 -2
  235. data/lib/chef/resource/kernel_module.rb +29 -29
  236. data/lib/chef/resource/ksh.rb +2 -0
  237. data/lib/chef/resource/launchd.rb +6 -6
  238. data/lib/chef/resource/link.rb +1 -23
  239. data/lib/chef/resource/locale.rb +58 -24
  240. data/lib/chef/resource/log.rb +12 -1
  241. data/lib/chef/resource/lwrp_base.rb +1 -8
  242. data/lib/chef/resource/macos_userdefaults.rb +9 -6
  243. data/lib/chef/resource/macosx_service.rb +2 -1
  244. data/lib/chef/resource/macports_package.rb +10 -2
  245. data/lib/chef/resource/mdadm.rb +62 -2
  246. data/lib/chef/resource/mount.rb +3 -0
  247. data/lib/chef/resource/msu_package.rb +13 -1
  248. data/lib/chef/resource/notify_group.rb +8 -3
  249. data/lib/chef/resource/ohai.rb +19 -3
  250. data/lib/chef/resource/ohai_hint.rb +3 -12
  251. data/lib/chef/resource/openbsd_package.rb +9 -1
  252. data/lib/chef/resource/openssl_dhparam.rb +10 -1
  253. data/lib/chef/resource/openssl_ec_private_key.rb +23 -1
  254. data/lib/chef/resource/openssl_ec_public_key.rb +21 -1
  255. data/lib/chef/resource/openssl_rsa_private_key.rb +20 -1
  256. data/lib/chef/resource/openssl_rsa_public_key.rb +22 -1
  257. data/lib/chef/resource/openssl_x509_certificate.rb +37 -1
  258. data/lib/chef/resource/openssl_x509_crl.rb +12 -1
  259. data/lib/chef/resource/openssl_x509_request.rb +37 -1
  260. data/lib/chef/resource/osx_profile.rb +3 -2
  261. data/lib/chef/resource/package.rb +2 -1
  262. data/lib/chef/resource/pacman_package.rb +2 -1
  263. data/lib/chef/resource/paludis_package.rb +12 -3
  264. data/lib/chef/resource/perl.rb +2 -0
  265. data/lib/chef/resource/plist.rb +207 -0
  266. data/lib/chef/resource/portage_package.rb +13 -3
  267. data/lib/chef/resource/powershell_package.rb +1 -3
  268. data/lib/chef/resource/powershell_package_source.rb +3 -1
  269. data/lib/chef/resource/powershell_script.rb +7 -17
  270. data/lib/chef/resource/python.rb +2 -0
  271. data/lib/chef/resource/reboot.rb +0 -1
  272. data/lib/chef/resource/registry_key.rb +1 -2
  273. data/lib/chef/resource/remote_directory.rb +2 -0
  274. data/lib/chef/resource/remote_file.rb +2 -0
  275. data/lib/chef/resource/rhsm_errata.rb +0 -1
  276. data/lib/chef/resource/rhsm_errata_level.rb +0 -1
  277. data/lib/chef/resource/rhsm_register.rb +2 -1
  278. data/lib/chef/resource/rhsm_repo.rb +3 -1
  279. data/lib/chef/resource/rhsm_subscription.rb +4 -1
  280. data/lib/chef/resource/route.rb +5 -1
  281. data/lib/chef/resource/rpm_package.rb +9 -2
  282. data/lib/chef/resource/ruby.rb +2 -0
  283. data/lib/chef/resource/ruby_block.rb +1 -1
  284. data/lib/chef/resource/scm/_scm.rb +48 -0
  285. data/lib/chef/resource/{scm.rb → scm/git.rb} +16 -30
  286. data/lib/chef/resource/{subversion.rb → scm/subversion.rb} +8 -5
  287. data/lib/chef/resource/script.rb +6 -3
  288. data/lib/chef/resource/service.rb +6 -7
  289. data/lib/chef/resource/smartos_package.rb +9 -1
  290. data/lib/chef/resource/snap_package.rb +3 -1
  291. data/lib/chef/resource/solaris_package.rb +9 -1
  292. data/lib/chef/resource/ssh_known_hosts_entry.rb +6 -3
  293. data/lib/chef/resource/sudo.rb +9 -9
  294. data/lib/chef/resource/support/cron.d.erb +1 -1
  295. data/lib/chef/resource/support/cron_access.erb +1 -1
  296. data/lib/chef/resource/support/sudoer.erb +1 -2
  297. data/lib/chef/resource/support/ulimit.erb +41 -0
  298. data/lib/chef/resource/swap_file.rb +5 -3
  299. data/lib/chef/resource/sysctl.rb +2 -2
  300. data/lib/chef/resource/systemd_unit.rb +4 -2
  301. data/lib/chef/resource/template.rb +0 -1
  302. data/lib/chef/resource/timezone.rb +7 -18
  303. data/lib/chef/resource/user.rb +1 -3
  304. data/lib/chef/resource/user/aix_user.rb +0 -2
  305. data/lib/chef/resource/user/dscl_user.rb +1 -1
  306. data/lib/chef/resource/user/linux_user.rb +0 -2
  307. data/lib/chef/resource/user/mac_user.rb +1 -1
  308. data/lib/chef/resource/user/pw_user.rb +0 -2
  309. data/lib/chef/resource/user/solaris_user.rb +0 -2
  310. data/lib/chef/resource/user/windows_user.rb +0 -2
  311. data/lib/chef/resource/user_ulimit.rb +114 -0
  312. data/lib/chef/resource/whyrun_safe_ruby_block.rb +1 -0
  313. data/lib/chef/resource/windows_ad_join.rb +19 -6
  314. data/lib/chef/resource/windows_auto_run.rb +0 -1
  315. data/lib/chef/resource/windows_certificate.rb +1 -1
  316. data/lib/chef/resource/windows_dfs_folder.rb +0 -1
  317. data/lib/chef/resource/windows_dfs_namespace.rb +0 -1
  318. data/lib/chef/resource/windows_dfs_server.rb +0 -1
  319. data/lib/chef/resource/windows_dns_record.rb +0 -1
  320. data/lib/chef/resource/windows_dns_zone.rb +0 -1
  321. data/lib/chef/resource/windows_env.rb +2 -3
  322. data/lib/chef/resource/windows_feature.rb +2 -2
  323. data/lib/chef/resource/windows_feature_dism.rb +9 -22
  324. data/lib/chef/resource/windows_feature_powershell.rb +17 -82
  325. data/lib/chef/resource/windows_firewall_rule.rb +119 -10
  326. data/lib/chef/resource/windows_font.rb +1 -3
  327. data/lib/chef/resource/windows_package.rb +13 -4
  328. data/lib/chef/resource/windows_pagefile.rb +0 -1
  329. data/lib/chef/resource/windows_path.rb +0 -1
  330. data/lib/chef/resource/windows_printer.rb +0 -1
  331. data/lib/chef/resource/windows_printer_port.rb +0 -1
  332. data/lib/chef/resource/windows_script.rb +3 -4
  333. data/lib/chef/resource/windows_security_policy.rb +90 -0
  334. data/lib/chef/resource/windows_service.rb +45 -31
  335. data/lib/chef/resource/windows_share.rb +3 -7
  336. data/lib/chef/resource/windows_shortcut.rb +0 -1
  337. data/lib/chef/resource/windows_task.rb +14 -15
  338. data/lib/chef/resource/windows_uac.rb +0 -1
  339. data/lib/chef/resource/windows_user_privilege.rb +157 -0
  340. data/lib/chef/resource/windows_workgroup.rb +0 -1
  341. data/lib/chef/resource/yum_package.rb +3 -1
  342. data/lib/chef/resource/yum_repository.rb +2 -1
  343. data/lib/chef/resource/zypper_package.rb +3 -2
  344. data/lib/chef/resource/zypper_repository.rb +2 -1
  345. data/lib/chef/resource_builder.rb +8 -0
  346. data/lib/chef/resource_inspector.rb +6 -6
  347. data/lib/chef/resource_resolver.rb +7 -14
  348. data/lib/chef/resources.rb +11 -3
  349. data/lib/chef/role.rb +2 -2
  350. data/lib/chef/run_context/cookbook_compiler.rb +29 -5
  351. data/lib/chef/shell.rb +23 -32
  352. data/lib/chef/shell/shell_session.rb +0 -2
  353. data/lib/chef/util/diff.rb +1 -1
  354. data/lib/chef/util/dsc/configuration_generator.rb +1 -1
  355. data/lib/chef/util/dsc/lcm_output_parser.rb +3 -3
  356. data/lib/chef/util/powershell/cmdlet.rb +1 -1
  357. data/lib/chef/version.rb +2 -2
  358. data/lib/chef/version_string.rb +1 -1
  359. data/lib/chef/win32/api/file.rb +18 -18
  360. data/lib/chef/win32/api/security.rb +6 -0
  361. data/lib/chef/win32/file.rb +3 -11
  362. data/lib/chef/win32/process.rb +2 -2
  363. data/lib/chef/win32/security.rb +40 -2
  364. data/spec/functional/assets/inittest +8 -7
  365. data/spec/functional/knife/ssh_spec.rb +27 -23
  366. data/spec/functional/resource/aix_service_spec.rb +1 -0
  367. data/spec/functional/resource/aixinit_service_spec.rb +8 -7
  368. data/spec/functional/resource/apt_package_spec.rb +1 -0
  369. data/spec/functional/resource/bff_spec.rb +2 -2
  370. data/spec/functional/resource/cookbook_file_spec.rb +1 -1
  371. data/spec/functional/resource/cron_spec.rb +11 -29
  372. data/spec/functional/resource/dnf_package_spec.rb +441 -156
  373. data/spec/functional/resource/dsc_resource_spec.rb +1 -1
  374. data/spec/functional/resource/git_spec.rb +184 -134
  375. data/spec/functional/resource/insserv_spec.rb +6 -5
  376. data/spec/functional/resource/link_spec.rb +17 -17
  377. data/spec/functional/resource/locale_spec.rb +13 -2
  378. data/spec/functional/resource/powershell_script_spec.rb +7 -68
  379. data/spec/functional/resource/rpm_spec.rb +2 -2
  380. data/spec/functional/resource/user/dscl_spec.rb +2 -2
  381. data/spec/functional/resource/user/mac_user_spec.rb +2 -2
  382. data/spec/functional/resource/windows_certificate_spec.rb +3 -3
  383. data/spec/functional/resource/windows_security_policy_spec.rb +90 -0
  384. data/spec/functional/resource/windows_task_spec.rb +8 -8
  385. data/spec/functional/resource/windows_user_privilege_spec.rb +193 -0
  386. data/spec/functional/run_lock_spec.rb +1 -2
  387. data/spec/functional/shell_spec.rb +6 -6
  388. data/spec/functional/util/powershell/cmdlet_spec.rb +1 -1
  389. data/spec/functional/version_spec.rb +1 -1
  390. data/spec/functional/win32/registry_spec.rb +0 -6
  391. data/spec/functional/win32/security_spec.rb +22 -0
  392. data/spec/functional/win32/service_manager_spec.rb +1 -1
  393. data/spec/integration/client/client_spec.rb +123 -2
  394. data/spec/integration/knife/cookbook_show_spec.rb +28 -26
  395. data/spec/integration/knife/data_bag_show_spec.rb +1 -1
  396. data/spec/integration/knife/raw_spec.rb +30 -2
  397. data/spec/integration/knife/show_spec.rb +32 -3
  398. data/spec/integration/recipes/accumulator_spec.rb +1 -1
  399. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +5 -5
  400. data/spec/integration/recipes/lwrp_spec.rb +1 -1
  401. data/spec/integration/recipes/noop_resource_spec.rb +1 -1
  402. data/spec/integration/recipes/notifies_spec.rb +50 -21
  403. data/spec/integration/recipes/notifying_block_spec.rb +9 -6
  404. data/spec/integration/recipes/provider_choice.rb +2 -0
  405. data/spec/integration/recipes/recipe_dsl_spec.rb +46 -144
  406. data/spec/integration/recipes/resource_action_spec.rb +16 -11
  407. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +1 -3
  408. data/spec/integration/recipes/resource_load_spec.rb +133 -13
  409. data/spec/integration/recipes/unified_mode_spec.rb +1 -1
  410. data/spec/integration/recipes/use_partial_spec.rb +112 -0
  411. data/spec/integration/solo/solo_spec.rb +3 -3
  412. data/spec/scripts/ssl-serve.rb +1 -1
  413. data/spec/spec_helper.rb +11 -14
  414. data/spec/support/chef_helpers.rb +2 -2
  415. data/spec/support/lib/chef/resource/zen_follower.rb +2 -0
  416. data/spec/support/platform_helpers.rb +44 -19
  417. data/spec/support/platforms/win32/spec_service.rb +1 -1
  418. data/spec/support/recipe_dsl_helper.rb +83 -0
  419. data/spec/support/shared/functional/directory_resource.rb +1 -1
  420. data/spec/support/shared/functional/execute_resource.rb +1 -1
  421. data/spec/support/shared/functional/file_resource.rb +3 -3
  422. data/spec/support/shared/functional/win32_service.rb +1 -1
  423. data/spec/support/shared/functional/windows_script.rb +5 -18
  424. data/spec/support/shared/integration/knife_support.rb +14 -8
  425. data/spec/unit/application/apply_spec.rb +3 -0
  426. data/spec/unit/application/client_spec.rb +5 -1
  427. data/spec/unit/application_spec.rb +1 -9
  428. data/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb +4 -2
  429. data/spec/unit/client_spec.rb +7 -5
  430. data/spec/unit/cookbook/gem_installer_spec.rb +3 -4
  431. data/spec/unit/cookbook/metadata_spec.rb +38 -19
  432. data/spec/unit/data_bag_spec.rb +1 -1
  433. data/spec/unit/data_collector_spec.rb +38 -17
  434. data/spec/unit/dsl/platform_introspection_spec.rb +0 -1
  435. data/spec/unit/environment_spec.rb +7 -7
  436. data/spec/unit/event_dispatch/dispatcher_spec.rb +0 -3
  437. data/spec/unit/file_access_control_spec.rb +1 -1
  438. data/spec/unit/knife/bootstrap/chef_vault_handler_spec.rb +15 -15
  439. data/spec/unit/knife/bootstrap/client_builder_spec.rb +9 -9
  440. data/spec/unit/knife/bootstrap_spec.rb +36 -54
  441. data/spec/unit/knife/cookbook_download_spec.rb +4 -4
  442. data/spec/unit/knife/cookbook_metadata_from_file_spec.rb +1 -1
  443. data/spec/unit/knife/cookbook_show_spec.rb +1 -0
  444. data/spec/unit/knife/cookbook_upload_spec.rb +6 -5
  445. data/spec/unit/knife/core/bootstrap_context_spec.rb +23 -43
  446. data/spec/unit/knife/core/hashed_command_loader_spec.rb +3 -3
  447. data/spec/unit/knife/core/ui_spec.rb +16 -0
  448. data/spec/unit/knife/core/windows_bootstrap_context_spec.rb +8 -68
  449. data/spec/unit/knife/data_bag_secret_options_spec.rb +22 -14
  450. data/spec/unit/knife/role_env_run_list_add_spec.rb +6 -6
  451. data/spec/unit/knife/role_env_run_list_clear_spec.rb +4 -4
  452. data/spec/unit/knife/role_env_run_list_remove_spec.rb +4 -4
  453. data/spec/unit/knife/role_env_run_list_replace_spec.rb +4 -4
  454. data/spec/unit/knife/role_env_run_list_set_spec.rb +4 -4
  455. data/spec/unit/knife/role_run_list_add_spec.rb +6 -6
  456. data/spec/unit/knife/role_run_list_clear_spec.rb +4 -4
  457. data/spec/unit/knife/role_run_list_remove_spec.rb +4 -4
  458. data/spec/unit/knife/role_run_list_replace_spec.rb +4 -4
  459. data/spec/unit/knife/role_run_list_set_spec.rb +4 -4
  460. data/spec/unit/knife/ssh_spec.rb +10 -113
  461. data/spec/unit/knife/status_spec.rb +1 -1
  462. data/spec/unit/knife/supermarket_share_spec.rb +3 -5
  463. data/spec/unit/knife_spec.rb +18 -0
  464. data/spec/unit/lwrp_spec.rb +4 -4
  465. data/spec/unit/mixin/powershell_exec_spec.rb +10 -0
  466. data/spec/unit/mixin/securable_spec.rb +1 -0
  467. data/spec/unit/mixin/user_context_spec.rb +9 -1
  468. data/spec/unit/node/attribute_spec.rb +2 -2
  469. data/spec/unit/node_spec.rb +24 -0
  470. data/spec/unit/platform/query_helpers_spec.rb +0 -143
  471. data/spec/unit/property/state_spec.rb +12 -7
  472. data/spec/unit/property/validation_spec.rb +25 -1
  473. data/spec/unit/property_spec.rb +18 -15
  474. data/spec/unit/provider/apt_preference_spec.rb +14 -10
  475. data/spec/unit/provider/apt_repository_spec.rb +9 -11
  476. data/spec/unit/provider/apt_update_spec.rb +12 -11
  477. data/spec/unit/provider/cookbook_file_spec.rb +4 -4
  478. data/spec/unit/provider/cron_spec.rb +2 -2
  479. data/spec/unit/provider/directory_spec.rb +4 -15
  480. data/spec/unit/provider/file_spec.rb +4 -4
  481. data/spec/unit/provider/git_spec.rb +44 -4
  482. data/spec/unit/provider/link_spec.rb +0 -1
  483. data/spec/unit/provider/log_spec.rb +3 -3
  484. data/spec/unit/provider/mdadm_spec.rb +3 -3
  485. data/spec/unit/provider/osx_profile_spec.rb +2 -2
  486. data/spec/unit/provider/package/dnf/python_helper_spec.rb +2 -2
  487. data/spec/unit/provider/package/freebsd/pkgng_spec.rb +1 -1
  488. data/spec/unit/provider/package/homebrew_spec.rb +280 -174
  489. data/spec/unit/provider/package/msu_spec.rb +3 -3
  490. data/spec/unit/provider/package/pacman_spec.rb +65 -147
  491. data/spec/unit/provider/package/powershell_spec.rb +88 -96
  492. data/spec/unit/provider/package/rubygems_spec.rb +221 -31
  493. data/spec/unit/provider/package/snap_spec.rb +1 -1
  494. data/spec/unit/provider/package/windows/exe_spec.rb +1 -1
  495. data/spec/unit/provider/package/windows_spec.rb +53 -30
  496. data/spec/unit/provider/powershell_script_spec.rb +21 -61
  497. data/spec/unit/provider/remote_file_spec.rb +3 -4
  498. data/spec/unit/provider/service/arch_service_spec.rb +2 -3
  499. data/spec/unit/provider/service/debian_service_spec.rb +35 -14
  500. data/spec/unit/provider/service/gentoo_service_spec.rb +8 -8
  501. data/spec/unit/provider/service/macosx_spec.rb +210 -214
  502. data/spec/unit/provider/service/redhat_spec.rb +2 -2
  503. data/spec/unit/provider/service/systemd_service_spec.rb +23 -23
  504. data/spec/unit/provider/service/upstart_service_spec.rb +3 -3
  505. data/spec/unit/provider/service/windows_spec.rb +6 -2
  506. data/spec/unit/provider/subversion_spec.rb +4 -2
  507. data/spec/unit/provider/systemd_unit_spec.rb +24 -28
  508. data/spec/unit/provider/template_spec.rb +3 -4
  509. data/spec/unit/provider/zypper_repository_spec.rb +25 -75
  510. data/spec/unit/provider_resolver_spec.rb +11 -11
  511. data/spec/unit/provider_spec.rb +0 -1
  512. data/spec/unit/recipe_spec.rb +68 -0
  513. data/spec/unit/resource/alternatives_spec.rb +120 -0
  514. data/spec/unit/resource/apt_preference_spec.rb +0 -18
  515. data/spec/unit/resource/apt_repository_spec.rb +0 -18
  516. data/spec/unit/resource/apt_update_spec.rb +0 -18
  517. data/spec/unit/resource/archive_file_spec.rb +2 -11
  518. data/spec/unit/resource/chef_client_cron_spec.rb +119 -0
  519. data/spec/unit/resource/chef_client_scheduled_task_spec.rb +102 -0
  520. data/spec/unit/resource/chef_client_systemd_timer_spec.rb +70 -0
  521. data/spec/unit/resource/chef_vault_secret_spec.rb +40 -0
  522. data/spec/unit/resource/chocolatey_source_spec.rb +2 -1
  523. data/spec/unit/resource/cron_d_spec.rb +6 -48
  524. data/spec/unit/resource/cron_spec.rb +4 -10
  525. data/spec/unit/resource/gem_package_spec.rb +3 -3
  526. data/spec/unit/resource/helpers/cron_validations_spec.rb +77 -0
  527. data/spec/unit/resource/link_spec.rb +0 -4
  528. data/spec/unit/resource/locale_spec.rb +0 -34
  529. data/spec/unit/resource/ohai_spec.rb +56 -2
  530. data/spec/unit/resource/plist_spec.rb +130 -0
  531. data/spec/unit/resource/powershell_script_spec.rb +0 -5
  532. data/spec/unit/resource/{git_spec.rb → scm/git_spec.rb} +50 -2
  533. data/spec/unit/resource/{scm_spec.rb → scm/scm.rb} +1 -52
  534. data/spec/unit/resource/{subversion_spec.rb → scm/subversion_spec.rb} +2 -3
  535. data/spec/unit/resource/service_spec.rb +4 -0
  536. data/spec/unit/resource/user_spec.rb +2 -2
  537. data/spec/unit/resource/user_ulimit_spec.rb +53 -0
  538. data/spec/unit/resource/windows_dns_record_spec.rb +3 -3
  539. data/spec/unit/resource/windows_dns_zone_spec.rb +2 -2
  540. data/spec/unit/resource/windows_feature_dism_spec.rb +2 -17
  541. data/spec/unit/resource/windows_feature_powershell_spec.rb +6 -47
  542. data/spec/unit/resource/windows_firewall_rule_spec.rb +88 -41
  543. data/spec/unit/resource/windows_package_spec.rb +4 -1
  544. data/spec/unit/resource/windows_service_spec.rb +9 -0
  545. data/spec/unit/resource/windows_task_spec.rb +1 -1
  546. data/spec/unit/resource/windows_uac_spec.rb +2 -2
  547. data/spec/unit/resource/yum_repository_spec.rb +21 -21
  548. data/spec/unit/resource_reporter_spec.rb +1 -5
  549. data/spec/unit/resource_spec.rb +11 -4
  550. data/spec/unit/role_spec.rb +11 -11
  551. data/spec/unit/run_context/cookbook_compiler_spec.rb +1 -1
  552. data/spec/unit/run_context_spec.rb +1 -1
  553. data/spec/unit/search/query_spec.rb +1 -1
  554. data/spec/unit/util/threaded_job_queue_spec.rb +0 -9
  555. data/spec/unit/win32/security_spec.rb +3 -4
  556. data/tasks/rspec.rb +1 -1
  557. metadata +110 -75
  558. data/lib/chef/dsl/core.rb +0 -52
  559. data/lib/chef/knife/cookbook_site_share.rb +0 -41
  560. data/lib/chef/knife/cookbook_site_unshare.rb +0 -41
  561. data/lib/chef/provider/apt_preference.rb +0 -93
  562. data/lib/chef/provider/apt_repository.rb +0 -358
  563. data/lib/chef/provider/apt_update.rb +0 -79
  564. data/lib/chef/provider/log.rb +0 -43
  565. data/lib/chef/provider/mdadm.rb +0 -85
  566. data/lib/chef/provider/ohai.rb +0 -45
  567. data/lib/chef/resource/git.rb +0 -37
  568. data/spec/functional/resource/windows_font_spec.rb +0 -49
  569. data/spec/unit/provider/ohai_spec.rb +0 -84
data/lib/chef/property.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  #
2
2
  # Author:: John Keiser <jkeiser@chef.io>
3
- # Copyright:: Copyright 2015-2016, John Keiser.
3
+ # Copyright:: Copyright 2015-2016, John Keiser
4
+ # Copyright:: Copyright (c) Chef Software Inc.
4
5
  # License:: Apache License, Version 2.0
5
6
  #
6
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -140,6 +141,10 @@ class Chef
140
141
  raise ArgumentError, "A property cannot be both a name_property/name_attribute and have a default value. Use one or the other on property #{self}"
141
142
  end
142
143
 
144
+ if options[:name_property]
145
+ options[:desired_state] = false unless options.key?(:desired_state)
146
+ end
147
+
143
148
  # Recursively freeze the default if it isn't a lazy value.
144
149
  unless default.is_a?(DelayedEvaluator)
145
150
  visitor = lambda do |obj|
@@ -244,6 +249,15 @@ class Chef
244
249
  options[:default_description]
245
250
  end
246
251
 
252
+ #
253
+ # The equal_to field of this property.
254
+ #
255
+ # @return [Array, NilClass]
256
+ #
257
+ def equal_to
258
+ options[:equal_to]
259
+ end
260
+
247
261
  #
248
262
  # Whether this is part of the resource's natural identity or not.
249
263
  #
@@ -289,8 +303,12 @@ class Chef
289
303
  #
290
304
  # @return [Boolean]
291
305
  #
292
- def required?
293
- options[:required]
306
+ def required?(action = nil)
307
+ if !action.nil? && options[:required].is_a?(Array)
308
+ options[:required].include?(action)
309
+ else
310
+ !!options[:required]
311
+ end
294
312
  end
295
313
 
296
314
  #
@@ -543,7 +561,7 @@ class Chef
543
561
  modified_options.key?(:default)
544
562
  options = options.reject { |k, v| k == :name_attribute || k == :name_property || k == :default }
545
563
  end
546
- self.class.new(options.merge(modified_options))
564
+ self.class.new(**options.merge(modified_options))
547
565
  end
548
566
 
549
567
  #
data/lib/chef/provider.rb CHANGED
@@ -23,7 +23,7 @@ require_relative "mixin/enforce_ownership_and_permissions"
23
23
  require_relative "mixin/why_run"
24
24
  require_relative "mixin/shell_out"
25
25
  require_relative "mixin/provides"
26
- require_relative "dsl/core"
26
+ require_relative "dsl/recipe"
27
27
  require_relative "platform/service_helpers"
28
28
  require_relative "node_map"
29
29
  require "forwardable" unless defined?(Forwardable)
@@ -35,6 +35,7 @@ class Chef
35
35
 
36
36
  attr_accessor :new_resource
37
37
  attr_accessor :current_resource
38
+ attr_accessor :after_resource
38
39
  attr_accessor :run_context
39
40
 
40
41
  attr_reader :recipe_name
@@ -44,8 +45,7 @@ class Chef
44
45
  extend Chef::Mixin::Provides
45
46
  extend Forwardable
46
47
 
47
- # includes the "core" DSL and not the "recipe" DSL by design
48
- include Chef::DSL::Core
48
+ include Chef::DSL::Recipe
49
49
  # the class only gets the Universal DSL (no resource_collection at class parsing time)
50
50
  extend Chef::DSL::Universal
51
51
 
@@ -64,7 +64,7 @@ class Chef
64
64
  #
65
65
  # @return [void]
66
66
  def self.action(name, &block)
67
- # We need the block directly in a method so that `super` works.
67
+ # We need the block directly in a method so that `return` works.
68
68
  define_method("compile_action_#{name}", &block)
69
69
  class_eval <<-EOM
70
70
  def action_#{name}
@@ -81,6 +81,20 @@ class Chef
81
81
  # Chef.deprecated(:use_inline_resources, "The use_inline_resources mode is no longer optional and the line enabling it can be removed")
82
82
  end
83
83
 
84
+ # Use a partial code fragment. This can be used for code sharing between multiple resources.
85
+ #
86
+ # Do not wrap the code fragment in a class or module. It also does not support the use of super
87
+ # to subclass any methods defined in the fragment, the methods will just be overwritten.
88
+ #
89
+ # @param partial [String] the code fragment to eval against the class
90
+ #
91
+ def self.use(partial)
92
+ dirname = ::File.dirname(partial)
93
+ basename = ::File.basename(partial, ".rb")
94
+ basename = basename[1..-1] if basename.start_with?("_")
95
+ class_eval IO.read(::File.expand_path("#{dirname}/_#{basename}.rb", ::File.dirname(caller_locations.first.absolute_path)))
96
+ end
97
+
84
98
  # delegate to the resource
85
99
  #
86
100
  def_delegators :@new_resource, :property_is_set?
@@ -95,6 +109,7 @@ class Chef
95
109
  @new_resource = new_resource
96
110
  @action = action
97
111
  @current_resource = nil
112
+ @after_resource = nil
98
113
  @run_context = run_context
99
114
  @converge_actions = nil
100
115
 
@@ -137,6 +152,7 @@ class Chef
137
152
  new_resource.cookbook_name
138
153
  end
139
154
 
155
+ # hook that subclasses can use to do lazy validation for where properties aren't flexibile enough
140
156
  def check_resource_semantics!; end
141
157
 
142
158
  # a simple placeholder method that will be called / raise if a resource tries to
@@ -149,6 +165,13 @@ class Chef
149
165
 
150
166
  def cleanup_after_converge; end
151
167
 
168
+ def load_after_resource
169
+ # This is a backwards compatible hack, custom resources properly wire up a new after_resource
170
+ # via load_current_value. It is acceptible for old style resources that cannot be easily made
171
+ # into custom resources to override this method and provide a proper after_resource.
172
+ @after_resource = @new_resource
173
+ end
174
+
152
175
  # the :nothing action which is available on all resources by default
153
176
  def action_nothing
154
177
  logger.trace("Doing nothing for #{@new_resource}")
@@ -159,12 +182,20 @@ class Chef
159
182
  run_context.events
160
183
  end
161
184
 
185
+ def validate_required_properties!
186
+ # all we do is run through all the required properties for this action and vivify them
187
+ new_resource.class.properties.each { |name, property| property.required?(action) && property.get(new_resource) }
188
+ end
189
+
162
190
  def run_action(action = nil)
163
191
  @action = action unless action.nil?
164
192
 
165
- # @todo it would be preferable to get the action to be executed in the constructor...
193
+ # hook that subclasses can use to do lazy validation for where properties aren't flexibile enough
166
194
  check_resource_semantics!
167
195
 
196
+ # force the validation of required properties
197
+ validate_required_properties!
198
+
168
199
  # user-defined LWRPs may include unsafe load_current_resource methods that cannot be run in whyrun mode
169
200
  if whyrun_mode? && !whyrun_supported?
170
201
  events.resource_current_state_load_bypassed(@new_resource, @action, @current_resource)
@@ -192,6 +223,9 @@ class Chef
192
223
  set_updated_status
193
224
 
194
225
  cleanup_after_converge
226
+
227
+ load_after_resource
228
+ events.resource_after_state_loaded(@new_resource, @action, @after_resource)
195
229
  end
196
230
 
197
231
  def process_resource_requirements
@@ -334,7 +368,7 @@ class Chef
334
368
  end
335
369
 
336
370
  def self.provides(short_name, opts = {}, &block)
337
- Chef.provider_handler_map.set(short_name, self, opts, &block)
371
+ Chef.provider_handler_map.set(short_name, self, **opts, &block)
338
372
  end
339
373
 
340
374
  def self.provides?(node, resource)
@@ -95,7 +95,7 @@ class Chef
95
95
  end
96
96
  end
97
97
 
98
- def action_create
98
+ action :create do
99
99
  crontab = ""
100
100
  newcron = ""
101
101
  cron_found = false
@@ -155,7 +155,7 @@ class Chef
155
155
  end
156
156
  end
157
157
 
158
- def action_delete
158
+ action :delete do
159
159
  if @cron_exists
160
160
  crontab = ""
161
161
  cron_found = false
@@ -121,7 +121,7 @@ class Chef
121
121
  end
122
122
  end
123
123
 
124
- def action_create
124
+ action :create do
125
125
  unless ::File.exists?(new_resource.path)
126
126
  converge_by("create new directory #{new_resource.path}") do
127
127
  if new_resource.recursive == true
@@ -137,7 +137,7 @@ class Chef
137
137
  load_resource_attributes_from_file(new_resource) unless Chef::Config[:why_run]
138
138
  end
139
139
 
140
- def action_delete
140
+ action :delete do
141
141
  if ::File.exists?(new_resource.path)
142
142
  converge_by("delete existing directory #{new_resource.path}") do
143
143
  if new_resource.recursive == true
@@ -33,7 +33,7 @@ class Chef
33
33
  @reboot_resource = nil
34
34
  end
35
35
 
36
- def action_run
36
+ action :run do
37
37
  unless test_resource
38
38
  converge_by(generate_description) do
39
39
  result = set_resource
@@ -40,7 +40,7 @@ class Chef
40
40
  end }
41
41
  end
42
42
 
43
- def action_run
43
+ action :run do
44
44
  unless @resource_converged
45
45
  converge_by(generate_description) do
46
46
  run_configuration(:set)
@@ -27,7 +27,7 @@ class Chef
27
27
 
28
28
  provides :execute, target_mode: true
29
29
 
30
- def_delegators :new_resource, :command, :returns, :environment, :user, :domain, :password, :group, :cwd, :umask, :creates, :elevated, :default_env
30
+ def_delegators :new_resource, :command, :returns, :environment, :user, :domain, :password, :group, :cwd, :umask, :creates, :elevated, :default_env, :timeout
31
31
 
32
32
  def load_current_resource
33
33
  current_resource = Chef::Resource::Execute.new(new_resource.name)
@@ -41,13 +41,7 @@ class Chef
41
41
  end
42
42
  end
43
43
 
44
- def timeout
45
- # original implementation did not specify a timeout, but ShellOut
46
- # *always* times out. So, set a very long default timeout
47
- new_resource.timeout || 3600
48
- end
49
-
50
- def action_run
44
+ action :run do
51
45
  if creates && sentinel_file.exist?
52
46
  logger.debug("#{new_resource} sentinel file #{sentinel_file} exists - nothing to do")
53
47
  return false
@@ -137,7 +137,7 @@ class Chef
137
137
  end
138
138
  end
139
139
 
140
- def action_create
140
+ action :create do
141
141
  do_generate_content
142
142
  do_validate_content
143
143
  do_unlink
@@ -148,7 +148,7 @@ class Chef
148
148
  load_resource_attributes_from_file(new_resource) unless Chef::Config[:why_run]
149
149
  end
150
150
 
151
- def action_create_if_missing
151
+ action :create_if_missing do
152
152
  unless ::File.exist?(new_resource.path)
153
153
  action_create
154
154
  else
@@ -156,7 +156,7 @@ class Chef
156
156
  end
157
157
  end
158
158
 
159
- def action_delete
159
+ action :delete do
160
160
  if ::File.exists?(new_resource.path)
161
161
  converge_by("delete file #{new_resource.path}") do
162
162
  do_backup unless file_class.symlink?(new_resource.path)
@@ -166,7 +166,7 @@ class Chef
166
166
  end
167
167
  end
168
168
 
169
- def action_touch
169
+ action :touch do
170
170
  action_create
171
171
  converge_by("update utime on file #{new_resource.path}") do
172
172
  time = Time.now
@@ -381,7 +381,7 @@ class Chef
381
381
 
382
382
  def update_file_contents
383
383
  do_backup unless needs_creating?
384
- deployment_strategy.deploy(tempfile.path, ::File.realpath(new_resource.path))
384
+ deployment_strategy.deploy(tempfile.path, ::File.realpath(new_resource.path).force_encoding(Chef::Config[:ruby_encoding]))
385
385
  logger.info("#{new_resource} updated file contents #{new_resource.path}")
386
386
  if managing_content?
387
387
  # save final checksum for reporting.
@@ -41,13 +41,27 @@ class Chef
41
41
  end
42
42
 
43
43
  def define_resource_requirements
44
+ unless new_resource.user.nil?
45
+ requirements.assert(:all_actions) do |a|
46
+ a.assertion do
47
+ begin
48
+ get_homedir(new_resource.user)
49
+ rescue ArgumentError
50
+ false
51
+ end
52
+ end
53
+ a.whyrun("User #{new_resource.user} does not exist, this run will fail unless it has been previously created. Assuming it would have been created.")
54
+ a.failure_message(Chef::Exceptions::User, "#{new_resource.user} required by resource #{new_resource.name} does not exist")
55
+ end
56
+ end
57
+
44
58
  # Parent directory of the target must exist.
45
59
  requirements.assert(:checkout, :sync) do |a|
46
60
  dirname = ::File.dirname(cwd)
47
61
  a.assertion { ::File.directory?(dirname) }
48
62
  a.whyrun("Directory #{dirname} does not exist, this run will fail unless it has been previously created. Assuming it would have been created.")
49
63
  a.failure_message(Chef::Exceptions::MissingParentDirectory,
50
- "Cannot clone #{new_resource} to #{cwd}, the enclosing directory #{dirname} does not exist")
64
+ "Cannot clone #{new_resource} to #{cwd}, the enclosing directory #{dirname} does not exist")
51
65
  end
52
66
 
53
67
  requirements.assert(:all_actions) do |a|
@@ -71,7 +85,7 @@ class Chef
71
85
  end
72
86
  end
73
87
 
74
- def action_checkout
88
+ action :checkout do
75
89
  if target_dir_non_existent_or_empty?
76
90
  clone
77
91
  if new_resource.enable_checkout
@@ -84,14 +98,14 @@ class Chef
84
98
  end
85
99
  end
86
100
 
87
- def action_export
101
+ action :export do
88
102
  action_checkout
89
103
  converge_by("complete the export by removing #{cwd}.git after checkout") do
90
104
  FileUtils.rm_rf(::File.join(cwd, ".git"))
91
105
  end
92
106
  end
93
107
 
94
- def action_sync
108
+ action :sync do
95
109
  if existing_git_clone?
96
110
  logger.trace "#{new_resource} current revision: #{current_resource.revision} target revision: #{target_revision}"
97
111
  unless current_revision_matches_target_revision?
@@ -168,13 +182,24 @@ class Chef
168
182
  end
169
183
 
170
184
  def checkout
171
- sha_ref = target_revision
172
-
173
- converge_by("checkout ref #{sha_ref} branch #{new_resource.revision}") do
185
+ converge_by("checkout ref #{target_revision} branch #{new_resource.revision}") do
174
186
  # checkout into a local branch rather than a detached HEAD
175
- git("branch", "-f", new_resource.checkout_branch, sha_ref, cwd: cwd)
176
- git("checkout", new_resource.checkout_branch, cwd: cwd)
177
- logger.info "#{new_resource} checked out branch: #{new_resource.revision} onto: #{new_resource.checkout_branch} reference: #{sha_ref}"
187
+ if new_resource.checkout_branch
188
+ # check out to a local branch
189
+ git("branch", "-f", new_resource.checkout_branch, target_revision, cwd: cwd)
190
+ git("checkout", new_resource.checkout_branch, cwd: cwd)
191
+ logger.info "#{new_resource} checked out branch: #{new_resource.revision} onto: #{new_resource.checkout_branch} reference: #{target_revision}"
192
+ elsif sha_hash?(new_resource.revision) || !is_branch?
193
+ # detached head
194
+ git("checkout", target_revision, cwd: cwd)
195
+ logger.info "#{new_resource} checked out reference: #{target_revision}"
196
+ else
197
+ # need a branch with a tracking branch
198
+ git("branch", "-f", new_resource.revision, target_revision, cwd: cwd)
199
+ git("checkout", new_resource.revision, cwd: cwd)
200
+ git("branch", "-u", "#{new_resource.remote}/#{new_resource.revision}", cwd: cwd)
201
+ logger.info "#{new_resource} checked out branch: #{new_resource.revision} reference: #{target_revision}"
202
+ end
178
203
  end
179
204
  end
180
205
 
@@ -197,7 +222,19 @@ class Chef
197
222
  logger.trace "Fetching updates from #{new_resource.remote} and resetting to revision #{target_revision}"
198
223
  git("fetch", "--prune", new_resource.remote, cwd: cwd)
199
224
  git("fetch", new_resource.remote, "--tags", cwd: cwd)
200
- git("reset", "--hard", target_revision, cwd: cwd)
225
+ if new_resource.checkout_branch
226
+ # check out to a local branch
227
+ git("branch", "-f", new_resource.checkout_branch, target_revision, cwd: cwd)
228
+ git("checkout", new_resource.checkout_branch, cwd: cwd)
229
+ elsif sha_hash?(new_resource.revision) || is_tag?
230
+ # detached head
231
+ git("reset", "--hard", target_revision, cwd: cwd)
232
+ else
233
+ # need a branch with a tracking branch
234
+ git("branch", "-f", new_resource.revision, target_revision, cwd: cwd)
235
+ git("checkout", new_resource.revision, cwd: cwd)
236
+ git("branch", "-u", "#{new_resource.remote}/#{new_resource.revision}", cwd: cwd)
237
+ end
201
238
  end
202
239
  end
203
240
 
@@ -273,9 +310,18 @@ class Chef
273
310
 
274
311
  def find_revision(refs, revision, suffix = "")
275
312
  found = refs_search(refs, rev_match_pattern("refs/tags/", revision) + suffix)
276
- found = refs_search(refs, rev_match_pattern("refs/heads/", revision) + suffix) if found.empty?
277
- found = refs_search(refs, revision + suffix) if found.empty?
278
- found
313
+ if !found.empty?
314
+ @is_tag = true
315
+ found
316
+ else
317
+ found = refs_search(refs, rev_match_pattern("refs/heads/", revision) + suffix)
318
+ if !found.empty?
319
+ @is_branch = true
320
+ found
321
+ else
322
+ refs_search(refs, revision + suffix)
323
+ end
324
+ end
279
325
  end
280
326
 
281
327
  def rev_match_pattern(prefix, revision)
@@ -306,6 +352,14 @@ class Chef
306
352
 
307
353
  private
308
354
 
355
+ def is_branch?
356
+ !!@is_branch
357
+ end
358
+
359
+ def is_tag?
360
+ !!@is_tag
361
+ end
362
+
309
363
  def run_options(run_opts = {})
310
364
  env = {}
311
365
  if new_resource.user
@@ -313,18 +367,7 @@ class Chef
313
367
  # Certain versions of `git` misbehave if git configuration is
314
368
  # inaccessible in $HOME. We need to ensure $HOME matches the
315
369
  # user who is executing `git` not the user running Chef.
316
- env["HOME"] =
317
- begin
318
- require "etc" unless defined?(Etc)
319
- case new_resource.user
320
- when Integer
321
- Etc.getpwuid(new_resource.user).dir
322
- else
323
- Etc.getpwnam(new_resource.user.to_s).dir
324
- end
325
- rescue ArgumentError # user not found
326
- raise Chef::Exceptions::User, "Could not determine HOME for specified user '#{new_resource.user}' for resource '#{new_resource.name}'"
327
- end
370
+ env["HOME"] = get_homedir(new_resource.user)
328
371
  end
329
372
  run_opts[:group] = new_resource.group if new_resource.group
330
373
  env["GIT_SSH"] = new_resource.ssh_wrapper if new_resource.ssh_wrapper
@@ -338,7 +381,7 @@ class Chef
338
381
  def git(*args, **run_opts)
339
382
  git_command = ["git", args].compact.join(" ")
340
383
  logger.trace "running #{git_command}"
341
- shell_out!(git_command, run_options(run_opts))
384
+ shell_out!(git_command, **run_options(run_opts))
342
385
  end
343
386
 
344
387
  def sha_hash?(string)
@@ -355,6 +398,20 @@ class Chef
355
398
  new_resource.repository
356
399
  end
357
400
  end
401
+
402
+ # Returns the home directory of the user
403
+ # @param [String] user must be a string.
404
+ # @return [String] the home directory of the user.
405
+ #
406
+ def get_homedir(user)
407
+ require "etc" unless defined?(Etc)
408
+ case user
409
+ when Integer
410
+ Etc.getpwuid(user).dir
411
+ else
412
+ Etc.getpwnam(user.to_s).dir
413
+ end
414
+ end
358
415
  end
359
416
  end
360
417
  end