chef 15.11.3-universal-mingw32 → 16.1.16-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (513) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -7
  3. data/README.md +1 -1
  4. data/Rakefile +44 -16
  5. data/chef.gemspec +6 -4
  6. data/distro/powershell/chef/chef.psm1 +3 -3
  7. data/distro/templates/powershell/chef/chef.psm1.erb +3 -3
  8. data/lib/chef/action_collection.rb +16 -5
  9. data/lib/chef/application.rb +33 -54
  10. data/lib/chef/application/apply.rb +18 -1
  11. data/lib/chef/application/base.rb +8 -3
  12. data/lib/chef/application/knife.rb +1 -1
  13. data/lib/chef/chef_class.rb +4 -4
  14. data/lib/chef/chef_fs/file_system/chef_server/acls_dir.rb +1 -1
  15. data/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb +1 -1
  16. data/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb +6 -2
  17. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +3 -3
  18. data/lib/chef/chef_fs/file_system/repository/directory.rb +1 -1
  19. data/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb +1 -1
  20. data/lib/chef/chef_fs/path_utils.rb +3 -3
  21. data/lib/chef/client.rb +16 -14
  22. data/lib/chef/config.rb +1 -1
  23. data/lib/chef/cookbook/file_system_file_vendor.rb +1 -1
  24. data/lib/chef/cookbook/gem_installer.rb +1 -1
  25. data/lib/chef/cookbook/metadata.rb +45 -22
  26. data/lib/chef/cookbook_loader.rb +1 -1
  27. data/lib/chef/cookbook_manifest.rb +1 -1
  28. data/lib/chef/cookbook_site_streaming_uploader.rb +1 -1
  29. data/lib/chef/cookbook_version.rb +38 -3
  30. data/lib/chef/data_collector.rb +1 -1
  31. data/lib/chef/data_collector/error_handlers.rb +1 -1
  32. data/lib/chef/data_collector/run_end_message.rb +7 -1
  33. data/lib/chef/decorator/lazy_array.rb +2 -2
  34. data/lib/chef/deprecated.rb +4 -0
  35. data/lib/chef/digester.rb +4 -4
  36. data/lib/chef/dist.rb +8 -0
  37. data/lib/chef/dsl/chef_vault.rb +84 -0
  38. data/lib/chef/dsl/declare_resource.rb +7 -5
  39. data/lib/chef/dsl/platform_introspection.rb +3 -2
  40. data/lib/chef/dsl/recipe.rb +7 -12
  41. data/lib/chef/dsl/universal.rb +3 -7
  42. data/lib/chef/encrypted_data_bag_item/decryptor.rb +1 -1
  43. data/lib/chef/encrypted_data_bag_item/encryptor.rb +1 -1
  44. data/lib/chef/event_dispatch/base.rb +3 -0
  45. data/lib/chef/formatters/base.rb +1 -1
  46. data/lib/chef/formatters/doc.rb +1 -1
  47. data/lib/chef/formatters/indentable_output_stream.rb +7 -16
  48. data/lib/chef/http.rb +1 -1
  49. data/lib/chef/http/decompressor.rb +1 -1
  50. data/lib/chef/http/http_request.rb +3 -2
  51. data/lib/chef/json_compat.rb +1 -1
  52. data/lib/chef/key.rb +1 -1
  53. data/lib/chef/knife.rb +2 -4
  54. data/lib/chef/knife/acl_add.rb +57 -0
  55. data/lib/chef/knife/acl_base.rb +183 -0
  56. data/lib/chef/knife/acl_bulk_add.rb +78 -0
  57. data/lib/chef/knife/acl_bulk_remove.rb +83 -0
  58. data/lib/chef/knife/acl_remove.rb +62 -0
  59. data/lib/chef/knife/acl_show.rb +56 -0
  60. data/lib/chef/knife/bootstrap.rb +84 -90
  61. data/lib/chef/knife/bootstrap/chef_vault_handler.rb +2 -2
  62. data/lib/chef/knife/bootstrap/client_builder.rb +2 -2
  63. data/lib/chef/knife/bootstrap/templates/chef-full.erb +11 -11
  64. data/lib/chef/knife/bootstrap/templates/windows-chef-client-msi.erb +12 -12
  65. data/lib/chef/knife/core/bootstrap_context.rb +63 -60
  66. data/lib/chef/knife/core/generic_presenter.rb +4 -3
  67. data/lib/chef/knife/core/hashed_command_loader.rb +1 -1
  68. data/lib/chef/knife/core/node_presenter.rb +2 -2
  69. data/lib/chef/knife/core/status_presenter.rb +5 -5
  70. data/lib/chef/knife/core/subcommand_loader.rb +1 -1
  71. data/lib/chef/knife/core/ui.rb +17 -1
  72. data/lib/chef/knife/core/windows_bootstrap_context.rb +44 -42
  73. data/lib/chef/knife/data_bag_secret_options.rb +18 -45
  74. data/lib/chef/knife/group_add.rb +55 -0
  75. data/lib/chef/knife/{cookbook_site_download.rb → group_create.rb} +21 -12
  76. data/lib/chef/knife/group_destroy.rb +53 -0
  77. data/lib/chef/knife/{cookbook_site_list.rb → group_list.rb} +14 -11
  78. data/lib/chef/knife/group_remove.rb +56 -0
  79. data/lib/chef/knife/{cookbook_site_install.rb → group_show.rb} +21 -12
  80. data/lib/chef/knife/key_create_base.rb +1 -1
  81. data/lib/chef/knife/key_edit_base.rb +1 -1
  82. data/lib/chef/knife/ssh.rb +12 -31
  83. data/lib/chef/knife/status.rb +3 -3
  84. data/lib/chef/knife/supermarket_download.rb +1 -2
  85. data/lib/chef/knife/supermarket_install.rb +2 -3
  86. data/lib/chef/knife/supermarket_list.rb +1 -2
  87. data/lib/chef/knife/supermarket_search.rb +1 -2
  88. data/lib/chef/knife/supermarket_share.rb +1 -2
  89. data/lib/chef/knife/supermarket_show.rb +1 -2
  90. data/lib/chef/knife/supermarket_unshare.rb +1 -2
  91. data/lib/chef/knife/{cookbook_site_show.rb → user_dissociate.rb} +15 -13
  92. data/lib/chef/knife/{cookbook_site_search.rb → user_invite_add.rb} +16 -13
  93. data/lib/chef/knife/user_invite_list.rb +34 -0
  94. data/lib/chef/knife/user_invite_rescind.rb +63 -0
  95. data/lib/chef/knife/yaml_convert.rb +91 -0
  96. data/lib/chef/mixin/api_version_request_handling.rb +1 -1
  97. data/lib/chef/mixin/checksum.rb +0 -1
  98. data/lib/chef/mixin/openssl_helper.rb +4 -4
  99. data/lib/chef/mixin/powershell_exec.rb +10 -1
  100. data/lib/chef/mixin/powershell_out.rb +1 -1
  101. data/lib/chef/mixin/properties.rb +16 -2
  102. data/lib/chef/mixin/shell_out.rb +1 -5
  103. data/lib/chef/monkey_patches/net_http.rb +0 -4
  104. data/lib/chef/node.rb +18 -6
  105. data/lib/chef/node/attribute.rb +2 -2
  106. data/lib/chef/node/immutable_collections.rb +1 -1
  107. data/lib/chef/node/mixin/immutablize_array.rb +4 -0
  108. data/lib/chef/node/mixin/immutablize_hash.rb +3 -0
  109. data/lib/chef/node_map.rb +5 -31
  110. data/lib/chef/platform/priority_map.rb +4 -4
  111. data/lib/chef/platform/query_helpers.rb +6 -34
  112. data/lib/chef/policy_builder/policyfile.rb +1 -1
  113. data/lib/chef/powershell.rb +14 -0
  114. data/lib/chef/property.rb +24 -6
  115. data/lib/chef/provider.rb +40 -6
  116. data/lib/chef/provider/cron.rb +2 -2
  117. data/lib/chef/provider/directory.rb +3 -3
  118. data/lib/chef/provider/dsc_resource.rb +1 -1
  119. data/lib/chef/provider/dsc_script.rb +1 -1
  120. data/lib/chef/provider/execute.rb +3 -9
  121. data/lib/chef/provider/file.rb +6 -6
  122. data/lib/chef/provider/git.rb +84 -27
  123. data/lib/chef/provider/group.rb +4 -4
  124. data/lib/chef/provider/http_request.rb +6 -6
  125. data/lib/chef/provider/ifconfig.rb +4 -4
  126. data/lib/chef/provider/launchd.rb +45 -64
  127. data/lib/chef/provider/link.rb +2 -2
  128. data/lib/chef/provider/mount.rb +5 -5
  129. data/lib/chef/provider/osx_profile.rb +7 -3
  130. data/lib/chef/provider/package.rb +2 -2
  131. data/lib/chef/provider/package/cab.rb +5 -6
  132. data/lib/chef/provider/package/chocolatey.rb +1 -3
  133. data/lib/chef/provider/package/dnf.rb +66 -10
  134. data/lib/chef/provider/package/dnf/dnf_helper.py +85 -26
  135. data/lib/chef/provider/package/dnf/python_helper.rb +79 -36
  136. data/lib/chef/provider/package/dnf/version.rb +5 -1
  137. data/lib/chef/provider/package/dpkg.rb +1 -1
  138. data/lib/chef/provider/package/freebsd/base.rb +2 -1
  139. data/lib/chef/provider/package/homebrew.rb +107 -43
  140. data/lib/chef/provider/package/macports.rb +0 -2
  141. data/lib/chef/provider/package/msu.rb +4 -1
  142. data/lib/chef/provider/package/pacman.rb +25 -34
  143. data/lib/chef/provider/package/portage.rb +1 -0
  144. data/lib/chef/provider/package/powershell.rb +1 -1
  145. data/lib/chef/provider/package/rubygems.rb +30 -3
  146. data/lib/chef/provider/package/windows.rb +29 -53
  147. data/lib/chef/provider/package/windows/msi.rb +2 -2
  148. data/lib/chef/provider/package/yum.rb +1 -9
  149. data/lib/chef/provider/package/yum/yum_cache.rb +1 -1
  150. data/lib/chef/provider/package/zypper.rb +0 -1
  151. data/lib/chef/provider/powershell_script.rb +5 -11
  152. data/lib/chef/provider/registry_key.rb +4 -4
  153. data/lib/chef/provider/remote_directory.rb +5 -5
  154. data/lib/chef/provider/remote_file/ftp.rb +3 -2
  155. data/lib/chef/provider/remote_file/local_file.rb +2 -1
  156. data/lib/chef/provider/remote_file/sftp.rb +3 -2
  157. data/lib/chef/provider/route.rb +5 -3
  158. data/lib/chef/provider/ruby_block.rb +1 -1
  159. data/lib/chef/provider/script.rb +2 -2
  160. data/lib/chef/provider/service.rb +8 -8
  161. data/lib/chef/provider/service/aixinit.rb +1 -1
  162. data/lib/chef/provider/service/arch.rb +1 -1
  163. data/lib/chef/provider/service/debian.rb +30 -28
  164. data/lib/chef/provider/service/macosx.rb +16 -10
  165. data/lib/chef/provider/service/systemd.rb +12 -12
  166. data/lib/chef/provider/service/upstart.rb +1 -1
  167. data/lib/chef/provider/service/windows.rb +5 -11
  168. data/lib/chef/provider/subversion.rb +25 -5
  169. data/lib/chef/provider/systemd_unit.rb +26 -25
  170. data/lib/chef/provider/user.rb +6 -6
  171. data/lib/chef/provider/user/aix.rb +1 -1
  172. data/lib/chef/provider/user/dscl.rb +6 -6
  173. data/lib/chef/provider/user/mac.rb +20 -15
  174. data/lib/chef/provider/whyrun_safe_ruby_block.rb +1 -1
  175. data/lib/chef/provider/windows_env.rb +3 -3
  176. data/lib/chef/provider/windows_script.rb +2 -2
  177. data/lib/chef/provider/windows_task.rb +10 -10
  178. data/lib/chef/providers.rb +0 -6
  179. data/lib/chef/recipe.rb +36 -0
  180. data/lib/chef/resource.rb +44 -57
  181. data/lib/chef/resource/action_class.rb +24 -22
  182. data/lib/chef/resource/alternatives.rb +210 -0
  183. data/lib/chef/resource/apt_package.rb +33 -3
  184. data/lib/chef/resource/apt_preference.rb +103 -7
  185. data/lib/chef/resource/apt_repository.rb +357 -18
  186. data/lib/chef/resource/apt_update.rb +58 -5
  187. data/lib/chef/resource/archive_file.rb +6 -5
  188. data/lib/chef/resource/bash.rb +3 -1
  189. data/lib/chef/resource/batch.rb +1 -1
  190. data/lib/chef/resource/bff_package.rb +10 -2
  191. data/lib/chef/resource/breakpoint.rb +1 -2
  192. data/lib/chef/resource/build_essential.rb +49 -51
  193. data/lib/chef/resource/cab_package.rb +9 -2
  194. data/lib/chef/resource/chef_client_cron.rb +228 -0
  195. data/lib/chef/resource/chef_client_scheduled_task.rb +201 -0
  196. data/lib/chef/resource/chef_client_systemd_timer.rb +180 -0
  197. data/lib/chef/resource/chef_gem.rb +15 -18
  198. data/lib/chef/resource/chef_handler.rb +5 -4
  199. data/lib/chef/resource/chef_sleep.rb +7 -5
  200. data/lib/chef/resource/chef_vault_secret.rb +135 -0
  201. data/lib/chef/resource/chocolatey_config.rb +8 -4
  202. data/lib/chef/resource/chocolatey_feature.rb +7 -4
  203. data/lib/chef/resource/chocolatey_package.rb +7 -4
  204. data/lib/chef/resource/chocolatey_source.rb +7 -4
  205. data/lib/chef/resource/cookbook_file.rb +4 -3
  206. data/lib/chef/resource/cron.rb +34 -80
  207. data/lib/chef/resource/cron_access.rb +10 -6
  208. data/lib/chef/resource/cron_d.rb +44 -95
  209. data/lib/chef/resource/csh.rb +3 -1
  210. data/lib/chef/resource/directory.rb +3 -3
  211. data/lib/chef/resource/dmg_package.rb +22 -19
  212. data/lib/chef/resource/dnf_package.rb +3 -4
  213. data/lib/chef/resource/dpkg_package.rb +3 -2
  214. data/lib/chef/resource/dsc_resource.rb +6 -4
  215. data/lib/chef/resource/dsc_script.rb +3 -2
  216. data/lib/chef/resource/execute.rb +15 -14
  217. data/lib/chef/resource/file.rb +14 -9
  218. data/lib/chef/resource/freebsd_package.rb +3 -2
  219. data/lib/chef/resource/gem_package.rb +19 -11
  220. data/lib/chef/resource/group.rb +5 -2
  221. data/lib/chef/resource/helpers/cron_validations.rb +98 -0
  222. data/lib/chef/resource/homebrew_cask.rb +3 -2
  223. data/lib/chef/resource/homebrew_package.rb +5 -3
  224. data/lib/chef/resource/homebrew_tap.rb +3 -2
  225. data/lib/chef/resource/hostname.rb +26 -20
  226. data/lib/chef/resource/http_request.rb +1 -2
  227. data/lib/chef/resource/ifconfig.rb +8 -8
  228. data/lib/chef/resource/ips_package.rb +11 -3
  229. data/lib/chef/resource/kernel_module.rb +30 -30
  230. data/lib/chef/resource/ksh.rb +3 -1
  231. data/lib/chef/resource/launchd.rb +3 -3
  232. data/lib/chef/resource/link.rb +5 -27
  233. data/lib/chef/resource/locale.rb +60 -26
  234. data/lib/chef/resource/log.rb +13 -2
  235. data/lib/chef/resource/lwrp_base.rb +1 -1
  236. data/lib/chef/resource/macos_userdefaults.rb +18 -10
  237. data/lib/chef/resource/macosx_service.rb +3 -2
  238. data/lib/chef/resource/macports_package.rb +10 -2
  239. data/lib/chef/resource/mdadm.rb +63 -3
  240. data/lib/chef/resource/mount.rb +4 -1
  241. data/lib/chef/resource/msu_package.rb +19 -2
  242. data/lib/chef/resource/notify_group.rb +8 -3
  243. data/lib/chef/resource/ohai.rb +20 -4
  244. data/lib/chef/resource/ohai_hint.rb +4 -13
  245. data/lib/chef/resource/openbsd_package.rb +10 -2
  246. data/lib/chef/resource/openssl_dhparam.rb +11 -2
  247. data/lib/chef/resource/openssl_ec_private_key.rb +24 -2
  248. data/lib/chef/resource/openssl_ec_public_key.rb +22 -2
  249. data/lib/chef/resource/openssl_rsa_private_key.rb +21 -2
  250. data/lib/chef/resource/openssl_rsa_public_key.rb +23 -2
  251. data/lib/chef/resource/openssl_x509_certificate.rb +38 -2
  252. data/lib/chef/resource/openssl_x509_crl.rb +13 -2
  253. data/lib/chef/resource/openssl_x509_request.rb +38 -2
  254. data/lib/chef/resource/osx_profile.rb +4 -3
  255. data/lib/chef/resource/package.rb +3 -2
  256. data/lib/chef/resource/pacman_package.rb +3 -2
  257. data/lib/chef/resource/paludis_package.rb +13 -4
  258. data/lib/chef/resource/perl.rb +3 -1
  259. data/lib/chef/resource/plist.rb +207 -0
  260. data/lib/chef/resource/portage_package.rb +14 -4
  261. data/lib/chef/resource/powershell_package.rb +2 -4
  262. data/lib/chef/resource/powershell_package_source.rb +4 -2
  263. data/lib/chef/resource/powershell_script.rb +8 -18
  264. data/lib/chef/resource/python.rb +3 -1
  265. data/lib/chef/resource/reboot.rb +1 -2
  266. data/lib/chef/resource/registry_key.rb +2 -3
  267. data/lib/chef/resource/remote_directory.rb +3 -1
  268. data/lib/chef/resource/remote_file.rb +3 -2
  269. data/lib/chef/resource/rhsm_errata.rb +1 -4
  270. data/lib/chef/resource/rhsm_errata_level.rb +1 -2
  271. data/lib/chef/resource/rhsm_register.rb +3 -3
  272. data/lib/chef/resource/rhsm_repo.rb +4 -3
  273. data/lib/chef/resource/rhsm_subscription.rb +5 -4
  274. data/lib/chef/resource/route.rb +6 -2
  275. data/lib/chef/resource/rpm_package.rb +13 -3
  276. data/lib/chef/resource/ruby.rb +3 -1
  277. data/lib/chef/resource/ruby_block.rb +2 -5
  278. data/lib/chef/resource/scm/_scm.rb +49 -0
  279. data/lib/chef/resource/{scm.rb → scm/git.rb} +16 -30
  280. data/lib/chef/resource/{subversion.rb → scm/subversion.rb} +10 -7
  281. data/lib/chef/resource/script.rb +7 -4
  282. data/lib/chef/resource/service.rb +7 -8
  283. data/lib/chef/resource/smartos_package.rb +10 -2
  284. data/lib/chef/resource/snap_package.rb +4 -2
  285. data/lib/chef/resource/solaris_package.rb +10 -2
  286. data/lib/chef/resource/ssh_known_hosts_entry.rb +6 -3
  287. data/lib/chef/resource/sudo.rb +11 -11
  288. data/lib/chef/resource/support/cron.d.erb +1 -1
  289. data/lib/chef/resource/support/cron_access.erb +1 -1
  290. data/lib/chef/resource/support/sudoer.erb +1 -2
  291. data/lib/chef/resource/support/ulimit.erb +41 -0
  292. data/lib/chef/resource/swap_file.rb +7 -5
  293. data/lib/chef/resource/sysctl.rb +63 -4
  294. data/lib/chef/resource/systemd_unit.rb +6 -4
  295. data/lib/chef/resource/template.rb +0 -1
  296. data/lib/chef/resource/timezone.rb +8 -19
  297. data/lib/chef/resource/user.rb +3 -5
  298. data/lib/chef/resource/user/aix_user.rb +0 -2
  299. data/lib/chef/resource/user/dscl_user.rb +1 -1
  300. data/lib/chef/resource/user/linux_user.rb +0 -2
  301. data/lib/chef/resource/user/mac_user.rb +1 -1
  302. data/lib/chef/resource/user/pw_user.rb +0 -2
  303. data/lib/chef/resource/user/solaris_user.rb +0 -2
  304. data/lib/chef/resource/user/windows_user.rb +0 -2
  305. data/lib/chef/resource/user_ulimit.rb +116 -0
  306. data/lib/chef/resource/whyrun_safe_ruby_block.rb +1 -0
  307. data/lib/chef/resource/windows_ad_join.rb +20 -7
  308. data/lib/chef/resource/windows_auto_run.rb +2 -3
  309. data/lib/chef/resource/windows_certificate.rb +3 -3
  310. data/lib/chef/resource/windows_dfs_folder.rb +1 -2
  311. data/lib/chef/resource/windows_dfs_namespace.rb +1 -2
  312. data/lib/chef/resource/windows_dfs_server.rb +2 -3
  313. data/lib/chef/resource/windows_dns_record.rb +0 -1
  314. data/lib/chef/resource/windows_dns_zone.rb +0 -1
  315. data/lib/chef/resource/windows_env.rb +12 -4
  316. data/lib/chef/resource/windows_feature.rb +59 -4
  317. data/lib/chef/resource/windows_feature_dism.rb +24 -24
  318. data/lib/chef/resource/windows_feature_powershell.rb +44 -78
  319. data/lib/chef/resource/windows_firewall_rule.rb +121 -8
  320. data/lib/chef/resource/windows_font.rb +10 -2
  321. data/lib/chef/resource/windows_package.rb +76 -7
  322. data/lib/chef/resource/windows_pagefile.rb +31 -4
  323. data/lib/chef/resource/windows_path.rb +18 -2
  324. data/lib/chef/resource/windows_printer.rb +26 -7
  325. data/lib/chef/resource/windows_printer_port.rb +29 -2
  326. data/lib/chef/resource/windows_script.rb +3 -4
  327. data/lib/chef/resource/windows_security_policy.rb +119 -0
  328. data/lib/chef/resource/windows_service.rb +46 -32
  329. data/lib/chef/resource/windows_share.rb +22 -6
  330. data/lib/chef/resource/windows_shortcut.rb +13 -3
  331. data/lib/chef/resource/windows_task.rb +129 -16
  332. data/lib/chef/resource/windows_uac.rb +20 -2
  333. data/lib/chef/resource/windows_user_privilege.rb +199 -0
  334. data/lib/chef/resource/windows_workgroup.rb +19 -4
  335. data/lib/chef/resource/yum_package.rb +91 -7
  336. data/lib/chef/resource/yum_repository.rb +30 -12
  337. data/lib/chef/resource/zypper_package.rb +32 -5
  338. data/lib/chef/resource/zypper_repository.rb +19 -6
  339. data/lib/chef/resource_builder.rb +8 -0
  340. data/lib/chef/resource_inspector.rb +3 -2
  341. data/lib/chef/resource_resolver.rb +7 -14
  342. data/lib/chef/resources.rb +11 -3
  343. data/lib/chef/run_context/cookbook_compiler.rb +29 -5
  344. data/lib/chef/scan_access_control.rb +1 -1
  345. data/lib/chef/shell.rb +22 -0
  346. data/lib/chef/shell/ext.rb +1 -1
  347. data/lib/chef/version.rb +1 -1
  348. data/lib/chef/win32/api.rb +2 -2
  349. data/lib/chef/win32/api/error.rb +3 -1
  350. data/lib/chef/win32/api/file.rb +1 -1
  351. data/lib/chef/win32/api/net.rb +1 -0
  352. data/lib/chef/win32/api/security.rb +6 -0
  353. data/lib/chef/win32/file.rb +1 -9
  354. data/lib/chef/win32/mutex.rb +1 -1
  355. data/lib/chef/win32/net.rb +1 -0
  356. data/lib/chef/win32/security.rb +40 -2
  357. data/lib/chef/win32/security/sid.rb +4 -4
  358. data/spec/functional/assets/inittest +8 -7
  359. data/spec/functional/knife/ssh_spec.rb +23 -19
  360. data/spec/functional/resource/cron_spec.rb +10 -29
  361. data/spec/functional/resource/dnf_package_spec.rb +441 -156
  362. data/spec/functional/resource/git_spec.rb +184 -134
  363. data/spec/functional/resource/insserv_spec.rb +1 -1
  364. data/spec/functional/resource/launchd_spec.rb +232 -0
  365. data/spec/functional/resource/link_spec.rb +3 -3
  366. data/spec/functional/resource/locale_spec.rb +13 -2
  367. data/spec/functional/resource/msu_package_spec.rb +5 -2
  368. data/spec/functional/resource/powershell_script_spec.rb +7 -68
  369. data/spec/functional/resource/remote_file_spec.rb +1 -1
  370. data/spec/functional/resource/windows_security_policy_spec.rb +90 -0
  371. data/spec/functional/resource/windows_task_spec.rb +4 -4
  372. data/spec/functional/resource/windows_user_privilege_spec.rb +193 -0
  373. data/spec/functional/run_lock_spec.rb +1 -1
  374. data/spec/functional/shell_spec.rb +1 -1
  375. data/spec/functional/util/powershell/cmdlet_spec.rb +1 -1
  376. data/spec/functional/version_spec.rb +1 -1
  377. data/spec/functional/win32/registry_spec.rb +0 -6
  378. data/spec/functional/win32/security_spec.rb +22 -0
  379. data/spec/integration/client/client_spec.rb +123 -2
  380. data/spec/integration/knife/cookbook_show_spec.rb +28 -26
  381. data/spec/integration/knife/data_bag_show_spec.rb +1 -1
  382. data/spec/integration/knife/raw_spec.rb +34 -6
  383. data/spec/integration/knife/redirection_spec.rb +2 -2
  384. data/spec/integration/knife/show_spec.rb +32 -3
  385. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +3 -3
  386. data/spec/integration/recipes/noop_resource_spec.rb +1 -1
  387. data/spec/integration/recipes/notifies_spec.rb +49 -20
  388. data/spec/integration/recipes/notifying_block_spec.rb +8 -5
  389. data/spec/integration/recipes/provider_choice.rb +2 -0
  390. data/spec/integration/recipes/recipe_dsl_spec.rb +45 -143
  391. data/spec/integration/recipes/resource_action_spec.rb +16 -11
  392. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +1 -1
  393. data/spec/integration/recipes/resource_load_spec.rb +133 -12
  394. data/spec/integration/recipes/use_partial_spec.rb +112 -0
  395. data/spec/integration/solo/solo_spec.rb +3 -3
  396. data/spec/spec_helper.rb +18 -3
  397. data/spec/support/chef_helpers.rb +2 -2
  398. data/spec/support/lib/chef/resource/zen_follower.rb +2 -0
  399. data/spec/support/platform_helpers.rb +2 -20
  400. data/spec/support/recipe_dsl_helper.rb +83 -0
  401. data/spec/support/shared/functional/http.rb +2 -2
  402. data/spec/support/shared/functional/windows_script.rb +3 -16
  403. data/spec/support/shared/integration/knife_support.rb +9 -6
  404. data/spec/support/shared/unit/mock_shellout.rb +1 -1
  405. data/spec/support/shared/unit/provider/useradd_based_user_provider.rb +4 -4
  406. data/spec/unit/application/apply_spec.rb +3 -0
  407. data/spec/unit/application/client_spec.rb +5 -1
  408. data/spec/unit/application_spec.rb +1 -2
  409. data/spec/unit/client_spec.rb +7 -5
  410. data/spec/unit/cookbook/gem_installer_spec.rb +2 -2
  411. data/spec/unit/cookbook/metadata_spec.rb +38 -19
  412. data/spec/unit/data_collector_spec.rb +39 -18
  413. data/spec/unit/file_access_control_spec.rb +1 -1
  414. data/spec/unit/json_compat_spec.rb +1 -1
  415. data/spec/unit/knife/bootstrap/chef_vault_handler_spec.rb +15 -15
  416. data/spec/unit/knife/bootstrap/client_builder_spec.rb +9 -9
  417. data/spec/unit/knife/bootstrap_spec.rb +20 -38
  418. data/spec/unit/knife/cookbook_show_spec.rb +1 -0
  419. data/spec/unit/knife/core/bootstrap_context_spec.rb +23 -43
  420. data/spec/unit/knife/core/ui_spec.rb +16 -0
  421. data/spec/unit/knife/core/windows_bootstrap_context_spec.rb +9 -63
  422. data/spec/unit/knife/data_bag_secret_options_spec.rb +22 -14
  423. data/spec/unit/knife/ssh_spec.rb +8 -111
  424. data/spec/unit/knife/status_spec.rb +1 -1
  425. data/spec/unit/knife_spec.rb +18 -0
  426. data/spec/unit/mixin/openssl_helper_spec.rb +4 -4
  427. data/spec/unit/mixin/powershell_exec_spec.rb +10 -0
  428. data/spec/unit/mixin/shell_out_spec.rb +25 -31
  429. data/spec/unit/node/attribute_spec.rb +3 -3
  430. data/spec/unit/node_spec.rb +24 -0
  431. data/spec/unit/platform/query_helpers_spec.rb +0 -143
  432. data/spec/unit/property/state_spec.rb +12 -7
  433. data/spec/unit/property/validation_spec.rb +25 -1
  434. data/spec/unit/property_spec.rb +12 -9
  435. data/spec/unit/provider/apt_preference_spec.rb +14 -10
  436. data/spec/unit/provider/apt_repository_spec.rb +34 -36
  437. data/spec/unit/provider/apt_update_spec.rb +12 -11
  438. data/spec/unit/provider/cookbook_file_spec.rb +4 -4
  439. data/spec/unit/provider/cron_spec.rb +2 -2
  440. data/spec/unit/provider/directory_spec.rb +4 -15
  441. data/spec/unit/provider/file_spec.rb +4 -4
  442. data/spec/unit/provider/git_spec.rb +41 -1
  443. data/spec/unit/provider/group/groupadd_spec.rb +1 -1
  444. data/spec/unit/provider/launchd_spec.rb +8 -50
  445. data/spec/unit/provider/link_spec.rb +0 -1
  446. data/spec/unit/provider/log_spec.rb +3 -3
  447. data/spec/unit/provider/mdadm_spec.rb +3 -3
  448. data/spec/unit/provider/package/dnf/python_helper_spec.rb +1 -1
  449. data/spec/unit/provider/package/homebrew_spec.rb +280 -174
  450. data/spec/unit/provider/package/pacman_spec.rb +65 -147
  451. data/spec/unit/provider/package/portage_spec.rb +2 -2
  452. data/spec/unit/provider/package/powershell_spec.rb +3 -2
  453. data/spec/unit/provider/package/rubygems_spec.rb +211 -26
  454. data/spec/unit/provider/package/windows/exe_spec.rb +1 -1
  455. data/spec/unit/provider/powershell_script_spec.rb +21 -61
  456. data/spec/unit/provider/remote_file_spec.rb +3 -4
  457. data/spec/unit/provider/service/debian_service_spec.rb +34 -13
  458. data/spec/unit/provider/service/macosx_spec.rb +210 -214
  459. data/spec/unit/provider/service/systemd_service_spec.rb +23 -23
  460. data/spec/unit/provider/subversion_spec.rb +4 -2
  461. data/spec/unit/provider/template_spec.rb +3 -4
  462. data/spec/unit/provider/zypper_repository_spec.rb +17 -17
  463. data/spec/unit/provider_resolver_spec.rb +4 -4
  464. data/spec/unit/recipe_spec.rb +68 -0
  465. data/spec/unit/resource/alternatives_spec.rb +120 -0
  466. data/spec/unit/resource/apt_preference_spec.rb +0 -18
  467. data/spec/unit/resource/apt_repository_spec.rb +0 -18
  468. data/spec/unit/resource/apt_update_spec.rb +0 -18
  469. data/spec/unit/resource/chef_client_cron_spec.rb +119 -0
  470. data/spec/unit/resource/chef_client_scheduled_task_spec.rb +102 -0
  471. data/spec/unit/resource/chef_client_systemd_timer_spec.rb +70 -0
  472. data/spec/unit/resource/chef_vault_secret_spec.rb +40 -0
  473. data/spec/unit/resource/chocolatey_source_spec.rb +2 -1
  474. data/spec/unit/resource/cron_d_spec.rb +6 -48
  475. data/spec/unit/resource/cron_spec.rb +4 -10
  476. data/spec/unit/resource/gem_package_spec.rb +3 -3
  477. data/spec/unit/resource/helpers/cron_validations_spec.rb +77 -0
  478. data/spec/unit/resource/link_spec.rb +0 -4
  479. data/spec/unit/resource/locale_spec.rb +0 -34
  480. data/spec/unit/resource/msu_package_spec.rb +4 -0
  481. data/spec/unit/resource/ohai_spec.rb +56 -2
  482. data/spec/unit/resource/plist_spec.rb +130 -0
  483. data/spec/unit/resource/powershell_script_spec.rb +0 -5
  484. data/spec/unit/resource/{git_spec.rb → scm/git_spec.rb} +50 -2
  485. data/spec/unit/resource/{scm_spec.rb → scm/scm.rb} +1 -52
  486. data/spec/unit/resource/{subversion_spec.rb → scm/subversion_spec.rb} +2 -3
  487. data/spec/unit/resource/service_spec.rb +4 -0
  488. data/spec/unit/resource/user_spec.rb +2 -2
  489. data/spec/unit/resource/user_ulimit_spec.rb +53 -0
  490. data/spec/unit/resource/windows_feature_dism_spec.rb +2 -17
  491. data/spec/unit/resource/windows_feature_powershell_spec.rb +2 -17
  492. data/spec/unit/resource/windows_firewall_rule_spec.rb +88 -41
  493. data/spec/unit/resource/windows_package_spec.rb +14 -0
  494. data/spec/unit/resource/windows_service_spec.rb +9 -0
  495. data/spec/unit/resource_reporter_spec.rb +2 -6
  496. data/spec/unit/resource_spec.rb +10 -3
  497. data/spec/unit/run_lock_spec.rb +1 -1
  498. data/spec/unit/scan_access_control_spec.rb +1 -1
  499. data/spec/unit/search/query_spec.rb +1 -1
  500. data/spec/unit/win32/registry_spec.rb +1 -1
  501. data/tasks/rspec.rb +6 -14
  502. metadata +92 -37
  503. data/lib/chef/dsl/core.rb +0 -52
  504. data/lib/chef/knife/cookbook_site_share.rb +0 -41
  505. data/lib/chef/knife/cookbook_site_unshare.rb +0 -41
  506. data/lib/chef/provider/apt_preference.rb +0 -93
  507. data/lib/chef/provider/apt_repository.rb +0 -358
  508. data/lib/chef/provider/apt_update.rb +0 -79
  509. data/lib/chef/provider/log.rb +0 -43
  510. data/lib/chef/provider/mdadm.rb +0 -85
  511. data/lib/chef/provider/ohai.rb +0 -45
  512. data/lib/chef/resource/git.rb +0 -37
  513. data/spec/unit/provider/ohai_spec.rb +0 -84
@@ -21,7 +21,6 @@ require_relative "../resource"
21
21
  class Chef
22
22
  class Resource
23
23
  class WindowsDnsRecord < Chef::Resource
24
- resource_name :windows_dns_record
25
24
  provides :windows_dns_record
26
25
 
27
26
  description "The windows_dns_record resource creates a DNS record for the given domain."
@@ -21,7 +21,6 @@ require_relative "../resource"
21
21
  class Chef
22
22
  class Resource
23
23
  class WindowsDnsZone < Chef::Resource
24
- resource_name :windows_dns_zone
25
24
  provides :windows_dns_zone
26
25
 
27
26
  description "The windows_dns_zone resource creates an Active Directory Integrated DNS Zone on the local server."
@@ -22,22 +22,30 @@ require_relative "../resource"
22
22
  class Chef
23
23
  class Resource
24
24
  class WindowsEnv < Chef::Resource
25
- resource_name :windows_env
26
25
  provides :windows_env
27
26
  provides :env # backwards compat with the pre-Chef 14 resource name
28
27
 
29
- description "Use the windows_env resource to manage environment keys in Microsoft Windows. After an environment key is set, Microsoft Windows must be restarted before the environment key will be available to the Task Scheduler."
28
+ description "Use the **windows_env** resource to manage environment keys in Microsoft Windows. After an environment key is set, Microsoft Windows must be restarted before the environment key will be available to the Task Scheduler."
29
+ examples <<~DOC
30
+ **Set an environment variable**:
31
+
32
+ ```ruby
33
+ windows_env 'ComSpec' do
34
+ value 'C:\\Windows\\system32\\cmd.exe'
35
+ end
36
+ ```
37
+ DOC
30
38
 
31
39
  default_action :create
32
40
  allowed_actions :create, :delete, :modify
33
41
 
34
42
  property :key_name, String,
35
43
  description: "An optional property to set the name of the key that is to be created, deleted, or modified if it differs from the resource block's name.",
36
- identity: true, name_property: true
44
+ name_property: true
37
45
 
38
46
  property :value, String,
39
47
  description: "The value of the environmental variable to set.",
40
- required: true
48
+ required: %i{create modify}
41
49
 
42
50
  property :delim, [ String, nil, false ],
43
51
  description: "The delimiter that is used to separate multiple values for a single key.",
@@ -21,11 +21,65 @@ require_relative "../resource"
21
21
  class Chef
22
22
  class Resource
23
23
  class WindowsFeature < Chef::Resource
24
- resource_name :windows_feature
25
24
  provides(:windows_feature) { true }
26
25
 
27
- description "Use the windows_feature resource to add, remove or entirely delete Windows features and roles. This resource calls the 'windows_feature_dism' or 'windows_feature_powershell' resources depending on the specified installation method, and defaults to DISM, which is available on both Workstation and Server editions of Windows."
26
+ description "Use the **windows_feature** resource to add, remove or entirely delete Windows features and roles. This resource calls the 'windows_feature_dism' or 'windows_feature_powershell' resources depending on the specified installation method, and defaults to DISM, which is available on both Workstation and Server editions of Windows."
28
27
  introduced "14.0"
28
+ examples <<~DOC
29
+ **Install the DHCP Server feature**:
30
+
31
+ ```ruby
32
+ windows_feature 'DHCPServer' do
33
+ action :install
34
+ end
35
+ ```
36
+
37
+ **Install the .Net 3.5.1 feature using repository files on DVD**:
38
+
39
+ ```ruby
40
+ windows_feature "NetFx3" do
41
+ action :install
42
+ source 'd:\\sources\\sxs'
43
+ end
44
+ ```
45
+
46
+ **Remove Telnet Server and Client features**:
47
+
48
+ ```ruby
49
+ windows_feature %w(TelnetServer TelnetClient) do
50
+ action :remove
51
+ end
52
+ ```
53
+
54
+ **Add the SMTP Server feature using the PowerShell provider**:
55
+
56
+ ```ruby
57
+ windows_feature 'smtp-server' do
58
+ action :install
59
+ all true
60
+ install_method :windows_feature_powershell
61
+ end
62
+ ```
63
+
64
+ **Install multiple features using one resource with the PowerShell provider**:
65
+
66
+ ```ruby
67
+ windows_feature %w(Web-Asp-Net45 Web-Net-Ext45) do
68
+ action :install
69
+ install_method :windows_feature_powershell
70
+ end
71
+ ```
72
+
73
+ **Install the Network Policy and Access Service feature, including the management tools**:
74
+
75
+ ```ruby
76
+ windows_feature 'NPAS' do
77
+ action :install
78
+ management_tools true
79
+ install_method :windows_feature_powershell
80
+ end
81
+ ```
82
+ DOC
29
83
 
30
84
  property :feature_name, [Array, String],
31
85
  description: "The name of the feature(s) or role(s) to install if they differ from the resource block's name. The same feature may have different names depending on the underlying installation method being used (ie DHCPServer vs DHCP; DNS-Server-Full-Role vs DNS).",
@@ -43,13 +97,14 @@ class Chef
43
97
  default: false
44
98
 
45
99
  property :install_method, Symbol,
46
- description: "The underlying installation method to use for feature installation. Specify ':windows_feature_dism' for DISM or ':windows_feature_powershell' for PowerShell.",
100
+ description: "The underlying installation method to use for feature installation. Specify `:windows_feature_dism` for DISM or `:windows_feature_powershell` for PowerShell.",
47
101
  equal_to: %i{windows_feature_dism windows_feature_powershell windows_feature_servermanagercmd},
48
102
  default: :windows_feature_dism
49
103
 
50
104
  property :timeout, Integer,
51
105
  description: "Specifies a timeout (in seconds) for the feature installation.",
52
- default: 600
106
+ default: 600,
107
+ desired_state: false
53
108
 
54
109
  action :install do
55
110
  description "Install a Windows role/feature"
@@ -22,11 +22,23 @@ require_relative "../platform/query_helpers"
22
22
  class Chef
23
23
  class Resource
24
24
  class WindowsFeatureDism < Chef::Resource
25
- resource_name :windows_feature_dism
26
25
  provides(:windows_feature_dism) { true }
27
26
 
28
- description "Use the windows_feature_dism resource to add, remove, or entirely delete Windows features and roles using DISM."
27
+ description "Use the **windows_feature_dism** resource to add, remove, or entirely delete Windows features and roles using DISM."
29
28
  introduced "14.0"
29
+ examples <<~DOC
30
+ **Installing the TelnetClient service**:
31
+
32
+ ```ruby
33
+ windows_feature_dism "TelnetClient"
34
+ ```
35
+
36
+ **Installing two features by using an array**:
37
+
38
+ ```ruby
39
+ windows_feature_dism %w(TelnetClient TFTP)
40
+ ```
41
+ DOC
30
42
 
31
43
  property :feature_name, [Array, String],
32
44
  description: "The name of the feature(s) or role(s) to install if they differ from the resource name.",
@@ -37,19 +49,18 @@ class Chef
37
49
  description: "Specify a local repository for the feature install."
38
50
 
39
51
  property :all, [TrueClass, FalseClass],
40
- description: "Install all sub-features. When set to 'true', this is the equivalent of specifying the /All switch to dism.exe",
52
+ description: "Install all sub-features. When set to `true`, this is the equivalent of specifying the `/All` switch to `dism.exe`",
41
53
  default: false
42
54
 
43
55
  property :timeout, Integer,
44
56
  description: "Specifies a timeout (in seconds) for the feature installation.",
45
- default: 600
57
+ default: 600,
58
+ desired_state: false
46
59
 
47
- # @return [Array] lowercase the array unless we're on < Windows 2012
60
+ # @return [Array] lowercase the array
48
61
  def to_formatted_array(x)
49
62
  x = x.split(/\s*,\s*/) if x.is_a?(String) # split multiple forms of a comma separated list
50
-
51
- # feature installs on windows < 2012 are case sensitive so only downcase when on 2012+
52
- older_than_win_2012_or_8? ? x : x.map(&:downcase)
63
+ x.map(&:downcase)
53
64
  end
54
65
 
55
66
  action :install do
@@ -98,8 +109,6 @@ class Chef
98
109
  action :delete do
99
110
  description "Remove a Windows role/feature from the image using DISM"
100
111
 
101
- raise_if_delete_unsupported
102
-
103
112
  reload_cached_dism_data unless node["dism_features_cache"]
104
113
 
105
114
  fail_if_unavailable # fail if the features don't exist
@@ -193,27 +202,18 @@ class Chef
193
202
  logger.trace("The cache contains\n#{node["dism_features_cache"]}")
194
203
  end
195
204
 
196
- # parse the feature string and add the values to the appropriate array
197
- # in the
198
- # strips trailing whitespace characters then split on n number of spaces
199
- # + | + n number of spaces
205
+ # parse the feature string and add the values to the appropriate array in the strips
206
+ # trailing whitespace characters then split on n number of spaces + | + n number of spaces
200
207
  # @return [void]
201
208
  def add_to_feature_mash(feature_type, feature_string)
202
209
  feature_details = feature_string.strip.split(/\s+[|]\s+/).first
203
210
 
204
- # dism on windows 2012+ isn't case sensitive so it's best to compare
205
- # lowercase lists so the user input doesn't need to be case sensitive
206
- # @todo when we're ready to remove windows 2008R2 the gating here can go away
207
- feature_details.downcase! unless older_than_win_2012_or_8?
211
+ # dism isn't case sensitive so it's best to compare lowercase lists so the
212
+ # user input doesn't need to be case sensitive
213
+ feature_details.downcase!
208
214
  node.override["dism_features_cache"][feature_type] << feature_details
209
215
  end
210
216
 
211
- # Fail unless we're on windows 8+ / 2012+ where deleting a feature is supported
212
- # @return [void]
213
- def raise_if_delete_unsupported
214
- raise Chef::Exceptions::UnsupportedAction, "#{self} :delete action not supported on Windows releases before Windows 8/2012. Cannot continue!" if older_than_win_2012_or_8?
215
- end
216
-
217
217
  def required_parent_feature?(error_message)
218
218
  error_message.include?("Error: 50") && error_message.include?("required parent feature")
219
219
  end
@@ -16,7 +16,6 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require_relative "../mixin/powershell_out"
20
19
  require_relative "../json_compat"
21
20
  require_relative "../resource"
22
21
  require_relative "../platform/query_helpers"
@@ -24,11 +23,37 @@ require_relative "../platform/query_helpers"
24
23
  class Chef
25
24
  class Resource
26
25
  class WindowsFeaturePowershell < Chef::Resource
27
- resource_name :windows_feature_powershell
28
26
  provides(:windows_feature_powershell) { true }
29
27
 
30
- description "Use the windows_feature_powershell resource to add, remove, or entirely delete Windows features and roles using PowerShell. This resource offers significant speed benefits over the windows_feature_dism resource, but requires installation of the Remote Server Administration Tools on non-server releases of Windows."
28
+ description "Use the **windows_feature_powershell** resource to add, remove, or entirely delete Windows features and roles using PowerShell. This resource offers significant speed benefits over the windows_feature_dism resource, but requires installation of the Remote Server Administration Tools on non-server releases of Windows."
31
29
  introduced "14.0"
30
+ examples <<~DOC
31
+ **Add the SMTP Server feature**:
32
+
33
+ ```ruby
34
+ windows_feature_powershell "smtp-server" do
35
+ action :install
36
+ all true
37
+ end
38
+ ```
39
+
40
+ **Install multiple features using one resource**:
41
+
42
+ ```ruby
43
+ windows_feature_powershell ['Web-Asp-Net45', 'Web-Net-Ext45'] do
44
+ action :install
45
+ end
46
+ ```
47
+
48
+ **Install the Network Policy and Access Service feature**:
49
+
50
+ ```ruby
51
+ windows_feature_powershell 'NPAS' do
52
+ action :install
53
+ management_tools true
54
+ end
55
+ ```
56
+ DOC
32
57
 
33
58
  property :feature_name, [Array, String],
34
59
  description: "The name of the feature(s) or role(s) to install if they differ from the resource block's name.",
@@ -39,31 +64,28 @@ class Chef
39
64
  description: "Specify a local repository for the feature install."
40
65
 
41
66
  property :all, [TrueClass, FalseClass],
42
- description: "Install all subfeatures. When set to 'true', this is the equivalent of specifying the '-InstallAllSubFeatures' switch with 'Add-WindowsFeature'.",
67
+ description: "Install all subfeatures. When set to `true`, this is the equivalent of specifying the `-InstallAllSubFeatures` switch with `Add-WindowsFeature`.",
43
68
  default: false
44
69
 
45
70
  property :timeout, Integer,
46
71
  description: "Specifies a timeout (in seconds) for the feature installation.",
47
- default: 600
72
+ default: 600,
73
+ desired_state: false
48
74
 
49
75
  property :management_tools, [TrueClass, FalseClass],
50
76
  description: "Install all applicable management tools for the roles, role services, or features.",
51
77
  default: false
52
78
 
53
- # Converts strings of features into an Array. Array objects are lowercased unless we're on < 8/2k12+.
79
+ # Converts strings of features into an Array. Array objects are lowercased
54
80
  # @return [Array] array of features
55
81
  def to_formatted_array(x)
56
82
  x = x.split(/\s*,\s*/) if x.is_a?(String) # split multiple forms of a comma separated list
57
83
 
58
- # feature installs on windows < 8/2012 are case sensitive so only downcase when on 2012+
59
- older_than_win_2012_or_8? ? x : x.map(&:downcase)
84
+ # features aren't case sensitive so let's compare in lowercase
85
+ x.map(&:downcase)
60
86
  end
61
87
 
62
- include Chef::Mixin::PowershellOut
63
-
64
88
  action :install do
65
- raise_on_old_powershell
66
-
67
89
  reload_cached_powershell_data unless node["powershell_features_cache"]
68
90
  fail_if_unavailable # fail if the features don't exist
69
91
  fail_if_removed # fail if the features are in removed state
@@ -71,14 +93,10 @@ class Chef
71
93
  Chef::Log.debug("Windows features needing installation: #{features_to_install.empty? ? "none" : features_to_install.join(",")}")
72
94
  unless features_to_install.empty?
73
95
  converge_by("install Windows feature#{"s" if features_to_install.count > 1} #{features_to_install.join(",")}") do
74
- install_command = "#{install_feature_cmdlet} #{features_to_install.join(",")}"
75
- install_command << " -IncludeAllSubFeature" if new_resource.all
76
- if older_than_win_2012_or_8? && (new_resource.source || new_resource.management_tools)
77
- Chef::Log.warn("The 'source' and 'management_tools' properties are only available on Windows 8/2012 or greater. Skipping these properties!")
78
- else
79
- install_command << " -Source \"#{new_resource.source}\"" if new_resource.source
80
- install_command << " -IncludeManagementTools" if new_resource.management_tools
81
- end
96
+ install_command = "Install-WindowsFeature #{features_to_install.join(",")}"
97
+ install_command << " -IncludeAllSubFeature" if new_resource.all
98
+ install_command << " -Source \"#{new_resource.source}\"" if new_resource.source
99
+ install_command << " -IncludeManagementTools" if new_resource.management_tools
82
100
 
83
101
  cmd = powershell_out!(install_command, timeout: new_resource.timeout)
84
102
  Chef::Log.info(cmd.stdout)
@@ -89,15 +107,13 @@ class Chef
89
107
  end
90
108
 
91
109
  action :remove do
92
- raise_on_old_powershell
93
-
94
110
  reload_cached_powershell_data unless node["powershell_features_cache"]
95
111
 
96
112
  Chef::Log.debug("Windows features needing removal: #{features_to_remove.empty? ? "none" : features_to_remove.join(",")}")
97
113
 
98
114
  unless features_to_remove.empty?
99
115
  converge_by("remove Windows feature#{"s" if features_to_remove.count > 1} #{features_to_remove.join(",")}") do
100
- cmd = powershell_out!("#{remove_feature_cmdlet} #{features_to_remove.join(",")}", timeout: new_resource.timeout)
116
+ cmd = powershell_out!("Uninstall-WindowsFeature #{features_to_remove.join(",")}", timeout: new_resource.timeout)
101
117
  Chef::Log.info(cmd.stdout)
102
118
 
103
119
  reload_cached_powershell_data # Reload cached powershell feature state
@@ -106,9 +122,6 @@ class Chef
106
122
  end
107
123
 
108
124
  action :delete do
109
- raise_on_old_powershell
110
- raise_if_delete_unsupported
111
-
112
125
  reload_cached_powershell_data unless node["powershell_features_cache"]
113
126
 
114
127
  fail_if_unavailable # fail if the features don't exist
@@ -126,41 +139,6 @@ class Chef
126
139
  end
127
140
 
128
141
  action_class do
129
- # shellout to determine the actively installed version of powershell
130
- # we have this same data in ohai, but it doesn't get updated if powershell is installed mid run
131
- # @return [Integer] the powershell version or 0 for nothing
132
- def powershell_version
133
- cmd = powershell_out("$PSVersionTable.psversion.major")
134
- return 1 if cmd.stdout.empty? # PowerShell 1.0 doesn't have a $PSVersionTable
135
-
136
- Regexp.last_match(1).to_i if cmd.stdout =~ /^(\d+)/
137
- rescue Errno::ENOENT
138
- 0 # zero as in nothing is installed
139
- end
140
-
141
- # raise if we're running powershell less than 3.0 since we need convertto-json
142
- # check the powershell version via ohai data and if we're < 3.0 also shellout to make sure as
143
- # a newer version could be installed post ohai run. Yes we're double checking. It's fine.
144
- # @todo this can go away when we fully remove support for Windows 2008 R2
145
- # @raise [RuntimeError] Raise if powershell is < 3.0
146
- def raise_on_old_powershell
147
- # be super defensive about the powershell lang plugin not being there
148
- return if node["languages"] && node["languages"]["powershell"] && node["languages"]["powershell"]["version"].to_i >= 3
149
- raise "The windows_feature_powershell resource requires PowerShell 3.0 or later. Please install PowerShell 3.0+ before running this resource." if powershell_version < 3
150
- end
151
-
152
- # The appropriate cmdlet to install a windows feature based on windows release
153
- # @return [String]
154
- def install_feature_cmdlet
155
- older_than_win_2012_or_8? ? "Add-WindowsFeature" : "Install-WindowsFeature"
156
- end
157
-
158
- # The appropriate cmdlet to remove a windows feature based on windows release
159
- # @return [String]
160
- def remove_feature_cmdlet
161
- older_than_win_2012_or_8? ? "Remove-WindowsFeature" : "Uninstall-WindowsFeature"
162
- end
163
-
164
142
  # @return [Array] features the user has requested to install which need installation
165
143
  def features_to_install
166
144
  # the intersection of the features to install & disabled features are what needs installing
@@ -224,13 +202,8 @@ class Chef
224
202
 
225
203
  # fetch the list of available feature names and state in JSON and parse the JSON
226
204
  def parsed_feature_list
227
- # Grab raw feature information from dism command line
228
- # Windows < 2012 doesn't present a state value so we have to check if the feature is installed or not
229
- raw_list_of_features = if older_than_win_2012_or_8? # make the older format look like the new format, warts and all
230
- powershell_out!('Get-WindowsFeature | Select-Object -Property Name, @{Name="InstallState"; Expression = {If ($_.Installed) { 1 } Else { 0 }}} | ConvertTo-Json -Compress', timeout: new_resource.timeout).stdout
231
- else
232
- powershell_out!("Get-WindowsFeature | Select-Object -Property Name,InstallState | ConvertTo-Json -Compress", timeout: new_resource.timeout).stdout
233
- end
205
+ # Grab raw feature information from WindowsFeature
206
+ raw_list_of_features = powershell_out!("Get-WindowsFeature | Select-Object -Property Name,InstallState | ConvertTo-Json -Compress", timeout: new_resource.timeout).stdout
234
207
 
235
208
  Chef::JSONCompat.from_json(raw_list_of_features)
236
209
  end
@@ -238,26 +211,19 @@ class Chef
238
211
  # add the features values to the appropriate array
239
212
  # @return [void]
240
213
  def add_to_feature_mash(feature_type, feature_details)
241
- # add the lowercase feature name to the mash unless we're on < 2012 where they're case sensitive
242
- node.override["powershell_features_cache"][feature_type] << (older_than_win_2012_or_8? ? feature_details : feature_details.downcase)
214
+ # add the lowercase feature name to the mash so we can compare it lowercase later
215
+ node.override["powershell_features_cache"][feature_type] << feature_details.downcase
243
216
  end
244
217
 
245
218
  # Fail if any of the packages are in a removed state
246
219
  # @return [void]
247
220
  def fail_if_removed
248
221
  return if new_resource.source # if someone provides a source then all is well
222
+ return if registry_key_exists?('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing') && registry_value_exists?('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing', name: "LocalSourcePath") # if source is defined in the registry, still fine
249
223
 
250
- if node["platform_version"].to_f > 6.2 # 2012R2 or later
251
- return if registry_key_exists?('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing') && registry_value_exists?('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing', name: "LocalSourcePath") # if source is defined in the registry, still fine
252
- end
253
224
  removed = new_resource.feature_name & node["powershell_features_cache"]["removed"]
254
225
  raise "The Windows feature#{"s" if removed.count > 1} #{removed.join(",")} #{removed.count > 1 ? "are" : "is"} removed from the host and cannot be installed." unless removed.empty?
255
226
  end
256
-
257
- # Fail unless we're on windows 8+ / 2012+ where deleting a feature is supported
258
- def raise_if_delete_unsupported
259
- raise Chef::Exceptions::UnsupportedAction, "#{self} :delete action not supported on Windows releases before Windows 8/2012. Cannot continue!" if older_than_win_2012_or_8?
260
- end
261
227
  end
262
228
  end
263
229
  end
@@ -24,19 +24,71 @@ require_relative "../json_compat"
24
24
  class Chef
25
25
  class Resource
26
26
  class WindowsFirewallRule < Chef::Resource
27
- resource_name :windows_firewall_rule
27
+ provides :windows_firewall_rule
28
28
 
29
- description "Use the windows_firewall_rule resource to create, change or remove windows firewall rules."
29
+ description "Use the **windows_firewall_rule** resource to create, change or remove Windows firewall rules."
30
30
  introduced "14.7"
31
+ examples <<~DOC
32
+ **Allowing port 80 access**:
33
+
34
+ ```ruby
35
+ windows_firewall_rule 'IIS' do
36
+ local_port '80'
37
+ protocol 'TCP'
38
+ firewall_action :allow
39
+ end
40
+ ```
41
+
42
+ **Allow protocol ICMPv6 with ICMP Type**:
43
+
44
+ ```ruby
45
+ windows_firewall_rule 'CoreNet-Rule' do
46
+ rule_name 'CoreNet-ICMP6-LR2-In'
47
+ display_name 'Core Networking - Multicast Listener Report v2 (ICMPv6-In)'
48
+ local_port 'RPC'
49
+ protocol 'ICMPv6'
50
+ icmp_type '8'
51
+ end
52
+ ```
53
+
54
+ **Blocking WinRM over HTTP on a particular IP**:
55
+
56
+ ```ruby
57
+ windows_firewall_rule 'Disable WinRM over HTTP' do
58
+ local_port '5985'
59
+ protocol 'TCP'
60
+ firewall_action :block
61
+ local_address '192.168.1.1'
62
+ end
63
+ ```
64
+
65
+ **Deleting an existing rule**
66
+
67
+ ```ruby
68
+ windows_firewall_rule 'Remove the SSH rule' do
69
+ rule_name 'ssh'
70
+ action :delete
71
+ end
72
+ ```
73
+ DOC
31
74
 
32
75
  property :rule_name, String,
33
76
  name_property: true,
34
77
  description: "An optional property to set the name of the firewall rule to assign if it differs from the resource block's name."
35
78
 
36
79
  property :description, String,
37
- default: "Firewall rule",
38
80
  description: "The description to assign to the firewall rule."
39
81
 
82
+ property :displayname, String,
83
+ description: "The displayname to assign to the firewall rule.",
84
+ default: lazy { rule_name },
85
+ default_description: "The rule_name property value.",
86
+ introduced: "16.0"
87
+
88
+ property :group, String,
89
+ description: "Specifies that only matching firewall rules of the indicated group association are copied.",
90
+ introduced: "16.0"
91
+
40
92
  property :local_address, String,
41
93
  description: "The local address the firewall rule applies to."
42
94
 
@@ -62,6 +114,11 @@ class Chef
62
114
  default: "TCP",
63
115
  description: "The protocol the firewall rule applies to."
64
116
 
117
+ property :icmp_type, [String, Integer],
118
+ description: "Specifies the ICMP Type parameter for using a protocol starting with ICMP",
119
+ default: "Any",
120
+ introduced: "16.0"
121
+
65
122
  property :firewall_action, [Symbol, String],
66
123
  default: :allow, equal_to: %i{allow block notconfigured},
67
124
  description: "The action of the firewall rule.",
@@ -110,12 +167,16 @@ class Chef
110
167
  # Need to reverse `$rule.Profile.ToString()` in powershell command
111
168
  current_profiles = state["profile"].split(", ").map(&:to_sym)
112
169
 
170
+ description state["description"]
171
+ displayname state["displayname"]
172
+ group state["group"]
113
173
  local_address state["local_address"]
114
174
  local_port Array(state["local_port"]).sort
115
175
  remote_address state["remote_address"]
116
176
  remote_port Array(state["remote_port"]).sort
117
177
  direction state["direction"]
118
178
  protocol state["protocol"]
179
+ icmp_type state["icmp_type"]
119
180
  firewall_action state["firewall_action"]
120
181
  profile current_profiles
121
182
  program state["program"]
@@ -126,13 +187,18 @@ class Chef
126
187
 
127
188
  action :create do
128
189
  description "Create a Windows firewall entry."
129
-
130
190
  if current_resource
131
- converge_if_changed :rule_name, :local_address, :local_port, :remote_address, :remote_port, :direction,
132
- :protocol, :firewall_action, :profile, :program, :service, :interface_type, :enabled do
191
+ converge_if_changed :rule_name, :description, :displayname, :local_address, :local_port, :remote_address,
192
+ :remote_port, :direction, :protocol, :icmp_type, :firewall_action, :profile, :program, :service,
193
+ :interface_type, :enabled do
133
194
  cmd = firewall_command("Set")
134
195
  powershell_out!(cmd)
135
196
  end
197
+ converge_if_changed :group do
198
+ powershell_out!("Remove-NetFirewallRule -Name '#{new_resource.rule_name}'")
199
+ cmd = firewall_command("New")
200
+ powershell_out!(cmd)
201
+ end
136
202
  else
137
203
  converge_by("create firewall rule #{new_resource.rule_name}") do
138
204
  cmd = firewall_command("New")
@@ -158,7 +224,9 @@ class Chef
158
224
  # @return [String] firewall create command
159
225
  def firewall_command(cmdlet_type)
160
226
  cmd = "#{cmdlet_type}-NetFirewallRule -Name '#{new_resource.rule_name}'"
161
- cmd << " -DisplayName '#{new_resource.rule_name}'" if cmdlet_type == "New"
227
+ cmd << " -DisplayName '#{new_resource.displayname}'" if new_resource.displayname && cmdlet_type == "New"
228
+ cmd << " -NewDisplayName '#{new_resource.displayname}'" if new_resource.displayname && cmdlet_type == "Set"
229
+ cmd << " -Group '#{new_resource.group}'" if new_resource.group && cmdlet_type == "New"
162
230
  cmd << " -Description '#{new_resource.description}'" if new_resource.description
163
231
  cmd << " -LocalAddress '#{new_resource.local_address}'" if new_resource.local_address
164
232
  cmd << " -LocalPort '#{new_resource.local_port.join("', '")}'" if new_resource.local_port
@@ -166,6 +234,7 @@ class Chef
166
234
  cmd << " -RemotePort '#{new_resource.remote_port.join("', '")}'" if new_resource.remote_port
167
235
  cmd << " -Direction '#{new_resource.direction}'" if new_resource.direction
168
236
  cmd << " -Protocol '#{new_resource.protocol}'" if new_resource.protocol
237
+ cmd << " -IcmpType '#{new_resource.icmp_type}'"
169
238
  cmd << " -Action '#{new_resource.firewall_action}'" if new_resource.firewall_action
170
239
  cmd << " -Profile '#{new_resource.profile.join("', '")}'" if new_resource.profile
171
240
  cmd << " -Program '#{new_resource.program}'" if new_resource.program
@@ -175,12 +244,53 @@ class Chef
175
244
 
176
245
  cmd
177
246
  end
247
+
248
+ def define_resource_requirements
249
+ requirements.assert(:create) do |a|
250
+ a.assertion do
251
+ if new_resource.icmp_type.is_a?(String)
252
+ !new_resource.icmp_type.empty?
253
+ elsif new_resource.icmp_type.is_a?(Integer)
254
+ !new_resource.icmp_type.nil?
255
+ end
256
+ end
257
+ a.failure_message("The :icmp_type property can not be empty in #{new_resource.rule_name}")
258
+ end
259
+
260
+ requirements.assert(:create) do |a|
261
+ a.assertion do
262
+ if new_resource.icmp_type.is_a?(Integer)
263
+ new_resource.protocol.start_with?("ICMP")
264
+ elsif new_resource.icmp_type.is_a?(String) && !new_resource.protocol.start_with?("ICMP")
265
+ new_resource.icmp_type == "Any"
266
+ else
267
+ true
268
+ end
269
+ end
270
+ a.failure_message("The :icmp_type property has a value of #{new_resource.icmp_type} set, but is not allowed for :protocol #{new_resource.protocol} in #{new_resource.rule_name}")
271
+ end
272
+
273
+ requirements.assert(:create) do |a|
274
+ a.assertion do
275
+ if new_resource.icmp_type.is_a?(Integer)
276
+ (0..255).include?(new_resource.icmp_type)
277
+ elsif new_resource.icmp_type.is_a?(String) && !new_resource.icmp_type.include?(":") && new_resource.protocol.start_with?("ICMP")
278
+ (0..255).include?(new_resource.icmp_type.to_i)
279
+ elsif new_resource.icmp_type.is_a?(String) && new_resource.icmp_type.include?(":") && new_resource.protocol.start_with?("ICMP")
280
+ new_resource.icmp_type.split(":").all? { |type| (0..255).include?(type.to_i) }
281
+ else
282
+ true
283
+ end
284
+ end
285
+ a.failure_message("Can not set :icmp_type to #{new_resource.icmp_type} as one value is out of range (0 to 255) in #{new_resource.rule_name}")
286
+ end
287
+ end
178
288
  end
179
289
 
180
290
  private
181
291
 
182
292
  # build the command to load the current resource
183
- # # @return [String] current firewall state
293
+ # @return [String] current firewall state
184
294
  def load_firewall_state(rule_name)
185
295
  <<-EOH
186
296
  Remove-TypeData System.Array # workaround for PS bug here: https://bit.ly/2SRMQ8M
@@ -193,12 +303,15 @@ class Chef
193
303
  ([PSCustomObject]@{
194
304
  rule_name = $rule.Name
195
305
  description = $rule.Description
306
+ displayname = $rule.DisplayName
307
+ group = $rule.Group
196
308
  local_address = $addressFilter.LocalAddress
197
309
  local_port = $portFilter.LocalPort
198
310
  remote_address = $addressFilter.RemoteAddress
199
311
  remote_port = $portFilter.RemotePort
200
312
  direction = $rule.Direction.ToString()
201
313
  protocol = $portFilter.Protocol
314
+ icmp_type = $portFilter.IcmpType
202
315
  firewall_action = $rule.Action.ToString()
203
316
  profile = $rule.Profile.ToString()
204
317
  program = $applicationFilter.Program