chef 16.5.64 → 16.8.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (317) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -14
  3. data/README.md +1 -1
  4. data/Rakefile +21 -14
  5. data/chef-universal-mingw32.gemspec +1 -1
  6. data/chef.gemspec +3 -2
  7. data/lib/chef/application.rb +2 -2
  8. data/lib/chef/application/base.rb +1 -1
  9. data/lib/chef/application/client.rb +7 -2
  10. data/lib/chef/application/knife.rb +1 -1
  11. data/lib/chef/application/solo.rb +1 -1
  12. data/lib/chef/chef_fs/chef_fs_data_store.rb +1 -1
  13. data/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb +1 -1
  14. data/lib/chef/chef_fs/file_pattern.rb +1 -1
  15. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +1 -1
  16. data/lib/chef/client.rb +6 -32
  17. data/lib/chef/compliance/default_attributes.rb +89 -0
  18. data/lib/chef/compliance/fetcher/automate.rb +69 -0
  19. data/lib/chef/compliance/fetcher/chef_server.rb +134 -0
  20. data/lib/chef/compliance/reporter/automate.rb +202 -0
  21. data/lib/chef/compliance/reporter/chef_server_automate.rb +94 -0
  22. data/lib/chef/compliance/reporter/compliance_enforcer.rb +20 -0
  23. data/lib/chef/compliance/reporter/json_file.rb +19 -0
  24. data/lib/chef/compliance/runner.rb +261 -0
  25. data/lib/chef/cookbook/gem_installer.rb +1 -1
  26. data/lib/chef/cookbook_manifest.rb +2 -1
  27. data/lib/chef/cookbook_site_streaming_uploader.rb +1 -1
  28. data/lib/chef/cookbook_version.rb +2 -5
  29. data/lib/chef/data_collector.rb +1 -1
  30. data/lib/chef/encrypted_data_bag_item/assertions.rb +1 -1
  31. data/lib/chef/environment.rb +1 -1
  32. data/lib/chef/event_loggers/windows_eventlog.rb +1 -1
  33. data/lib/chef/exceptions.rb +5 -1
  34. data/lib/chef/file_access_control/windows.rb +1 -4
  35. data/lib/chef/file_content_management/tempfile.rb +1 -1
  36. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +2 -2
  37. data/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb +5 -5
  38. data/lib/chef/formatters/indentable_output_stream.rb +2 -2
  39. data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +28 -39
  40. data/lib/chef/http.rb +2 -12
  41. data/lib/chef/http/basic_client.rb +1 -1
  42. data/lib/chef/http/http_request.rb +1 -1
  43. data/lib/chef/http/socketless_chef_zero_client.rb +1 -1
  44. data/lib/chef/http/ssl_policies.rb +6 -0
  45. data/lib/chef/json_compat.rb +2 -7
  46. data/lib/chef/key.rb +1 -1
  47. data/lib/chef/knife/bootstrap.rb +2 -1
  48. data/lib/chef/knife/bootstrap/templates/windows-chef-client-msi.erb +2 -2
  49. data/lib/chef/knife/bootstrap/train_connector.rb +1 -1
  50. data/lib/chef/knife/config_show.rb +1 -1
  51. data/lib/chef/knife/core/cookbook_scm_repo.rb +1 -1
  52. data/lib/chef/knife/core/gem_glob_loader.rb +1 -1
  53. data/lib/chef/knife/core/ui.rb +5 -2
  54. data/lib/chef/knife/core/windows_bootstrap_context.rb +7 -4
  55. data/lib/chef/knife/node_policy_set.rb +2 -2
  56. data/lib/chef/knife/node_run_list_add.rb +1 -1
  57. data/lib/chef/knife/node_run_list_remove.rb +1 -1
  58. data/lib/chef/knife/node_run_list_set.rb +1 -1
  59. data/lib/chef/knife/role_env_run_list_add.rb +1 -1
  60. data/lib/chef/knife/role_env_run_list_set.rb +1 -1
  61. data/lib/chef/knife/role_run_list_add.rb +1 -1
  62. data/lib/chef/knife/role_run_list_set.rb +1 -1
  63. data/lib/chef/knife/search.rb +0 -1
  64. data/lib/chef/knife/ssh.rb +5 -3
  65. data/lib/chef/knife/tag_create.rb +1 -1
  66. data/lib/chef/knife/tag_delete.rb +1 -1
  67. data/lib/chef/local_mode.rb +1 -1
  68. data/lib/chef/mixin/convert_to_class_name.rb +0 -56
  69. data/lib/chef/mixin/openssl_helper.rb +1 -1
  70. data/lib/chef/mixin/powershell_exec.rb +24 -10
  71. data/lib/chef/mixin/powershell_out.rb +12 -5
  72. data/lib/chef/mixin/properties.rb +2 -0
  73. data/lib/chef/mixin/template.rb +1 -1
  74. data/lib/chef/mixin/unformatter.rb +1 -1
  75. data/lib/chef/mixin/uris.rb +3 -1
  76. data/lib/chef/node/attribute_collections.rb +2 -6
  77. data/lib/chef/node/mixin/immutablize_hash.rb +2 -0
  78. data/lib/chef/node_map.rb +2 -2
  79. data/lib/chef/platform/query_helpers.rb +4 -4
  80. data/lib/chef/policy_builder/dynamic.rb +2 -0
  81. data/lib/chef/powershell.rb +10 -4
  82. data/lib/chef/property.rb +1 -1
  83. data/lib/chef/provider.rb +1 -1
  84. data/lib/chef/provider/cron.rb +2 -13
  85. data/lib/chef/provider/dsc_resource.rb +12 -24
  86. data/lib/chef/provider/dsc_script.rb +16 -20
  87. data/lib/chef/provider/file.rb +1 -1
  88. data/lib/chef/provider/git.rb +5 -5
  89. data/lib/chef/provider/group.rb +14 -6
  90. data/lib/chef/provider/group/windows.rb +12 -1
  91. data/lib/chef/provider/ifconfig.rb +8 -8
  92. data/lib/chef/provider/ifconfig/debian.rb +38 -22
  93. data/lib/chef/provider/ifconfig/redhat.rb +54 -18
  94. data/lib/chef/provider/launchd.rb +1 -11
  95. data/lib/chef/provider/link.rb +0 -9
  96. data/lib/chef/provider/mount.rb +18 -1
  97. data/lib/chef/provider/mount/linux.rb +4 -0
  98. data/lib/chef/provider/mount/mount.rb +41 -43
  99. data/lib/chef/provider/package.rb +3 -0
  100. data/lib/chef/provider/package/apt.rb +1 -1
  101. data/lib/chef/provider/package/chocolatey.rb +6 -6
  102. data/lib/chef/provider/package/dpkg.rb +3 -12
  103. data/lib/chef/provider/package/freebsd/base.rb +3 -2
  104. data/lib/chef/provider/package/freebsd/pkgng.rb +1 -1
  105. data/lib/chef/provider/package/homebrew.rb +1 -1
  106. data/lib/chef/provider/package/ips.rb +1 -1
  107. data/lib/chef/provider/package/powershell.rb +2 -3
  108. data/lib/chef/provider/package/rubygems.rb +1 -1
  109. data/lib/chef/provider/package/snap.rb +1 -3
  110. data/lib/chef/provider/package/solaris.rb +0 -2
  111. data/lib/chef/provider/package/yum/rpm_utils.rb +1 -1
  112. data/lib/chef/provider/package/zypper.rb +98 -71
  113. data/lib/chef/provider/powershell_script.rb +12 -1
  114. data/lib/chef/provider/registry_key.rb +4 -3
  115. data/lib/chef/provider/route.rb +2 -2
  116. data/lib/chef/provider/service/debian.rb +2 -1
  117. data/lib/chef/provider/service/redhat.rb +1 -1
  118. data/lib/chef/provider/user.rb +17 -9
  119. data/lib/chef/provider/user/aix.rb +1 -1
  120. data/lib/chef/provider/user/dscl.rb +2 -2
  121. data/lib/chef/provider/user/mac.rb +14 -6
  122. data/lib/chef/provider/user/solaris.rb +1 -1
  123. data/lib/chef/provider/user/windows.rb +10 -3
  124. data/lib/chef/providers.rb +0 -3
  125. data/lib/chef/pwsh.rb +71 -0
  126. data/lib/chef/resource.rb +1 -1
  127. data/lib/chef/resource/apt_repository.rb +6 -5
  128. data/lib/chef/resource/bash.rb +119 -1
  129. data/lib/chef/resource/batch.rb +1 -1
  130. data/lib/chef/resource/breakpoint.rb +3 -1
  131. data/lib/chef/resource/build_essential.rb +5 -8
  132. data/lib/chef/resource/chef_client_config.rb +313 -0
  133. data/lib/chef/resource/chef_client_cron.rb +5 -5
  134. data/lib/chef/resource/chef_client_scheduled_task.rb +4 -4
  135. data/lib/chef/resource/chef_client_systemd_timer.rb +5 -5
  136. data/lib/chef/resource/chef_handler.rb +1 -0
  137. data/lib/chef/resource/chef_sleep.rb +1 -1
  138. data/lib/chef/resource/cron/_cron_shared.rb +1 -0
  139. data/lib/chef/resource/cron/cron_d.rb +2 -2
  140. data/lib/chef/resource/csh.rb +2 -2
  141. data/lib/chef/resource/dsc_script.rb +8 -1
  142. data/lib/chef/resource/execute.rb +6 -4
  143. data/lib/chef/resource/file.rb +2 -2
  144. data/lib/chef/resource/homebrew_update.rb +4 -1
  145. data/lib/chef/resource/hostname.rb +5 -5
  146. data/lib/chef/resource/ifconfig.rb +52 -5
  147. data/lib/chef/resource/kernel_module.rb +1 -1
  148. data/lib/chef/resource/ksh.rb +3 -3
  149. data/lib/chef/resource/launchd.rb +15 -15
  150. data/lib/chef/resource/lwrp_base.rb +3 -5
  151. data/lib/chef/resource/mount.rb +8 -2
  152. data/lib/chef/resource/perl.rb +2 -2
  153. data/lib/chef/resource/plist.rb +2 -6
  154. data/lib/chef/resource/powershell_package_source.rb +19 -18
  155. data/lib/chef/resource/powershell_script.rb +14 -11
  156. data/lib/chef/resource/python.rb +2 -2
  157. data/lib/chef/resource/registry_key.rb +93 -2
  158. data/lib/chef/resource/route.rb +1 -1
  159. data/lib/chef/resource/ruby.rb +2 -2
  160. data/lib/chef/resource/scm/_scm.rb +2 -1
  161. data/lib/chef/resource/scm/git.rb +82 -1
  162. data/lib/chef/resource/scm/subversion.rb +12 -0
  163. data/lib/chef/resource/script.rb +2 -2
  164. data/lib/chef/resource/solaris_package.rb +0 -2
  165. data/lib/chef/resource/sudo.rb +1 -1
  166. data/lib/chef/resource/support/client.erb +64 -0
  167. data/lib/chef/resource/systemd_unit.rb +42 -1
  168. data/lib/chef/resource/template.rb +2 -2
  169. data/lib/chef/resource/windows_ad_join.rb +9 -9
  170. data/lib/chef/resource/windows_audit_policy.rb +26 -24
  171. data/lib/chef/resource/windows_certificate.rb +13 -7
  172. data/lib/chef/resource/windows_dfs_server.rb +7 -4
  173. data/lib/chef/resource/windows_env.rb +173 -0
  174. data/lib/chef/resource/windows_feature.rb +2 -0
  175. data/lib/chef/resource/windows_firewall_profile.rb +7 -12
  176. data/lib/chef/resource/windows_firewall_rule.rb +9 -11
  177. data/lib/chef/resource/windows_font.rb +1 -1
  178. data/lib/chef/resource/windows_package.rb +1 -0
  179. data/lib/chef/resource/windows_path.rb +38 -0
  180. data/lib/chef/resource/windows_security_policy.rb +5 -5
  181. data/lib/chef/resource/windows_service.rb +108 -0
  182. data/lib/chef/resource/windows_share.rb +18 -18
  183. data/lib/chef/resource/windows_task.rb +629 -28
  184. data/lib/chef/resource/windows_workgroup.rb +6 -4
  185. data/lib/chef/resource/yum_repository.rb +1 -1
  186. data/lib/chef/resource_collection/resource_set.rb +2 -6
  187. data/lib/chef/resource_inspector.rb +77 -75
  188. data/lib/chef/resource_reporter.rb +0 -2
  189. data/lib/chef/resources.rb +1 -0
  190. data/lib/chef/run_lock.rb +2 -2
  191. data/lib/chef/search/query.rb +3 -1
  192. data/lib/chef/server_api.rb +0 -4
  193. data/lib/chef/shell/ext.rb +1 -1
  194. data/lib/chef/util/backup.rb +1 -1
  195. data/lib/chef/util/dsc/configuration_generator.rb +52 -11
  196. data/lib/chef/util/dsc/lcm_output_parser.rb +4 -7
  197. data/lib/chef/util/dsc/local_configuration_manager.rb +18 -15
  198. data/lib/chef/util/dsc/resource_store.rb +5 -11
  199. data/lib/chef/version.rb +1 -1
  200. data/lib/chef/win32/api/file.rb +4 -0
  201. data/lib/chef/win32/file.rb +1 -1
  202. data/lib/chef/win32/security/sid.rb +1 -1
  203. data/lib/chef/win32/unicode.rb +1 -1
  204. data/spec/functional/mixin/powershell_out_spec.rb +11 -3
  205. data/spec/functional/resource/apt_package_spec.rb +4 -6
  206. data/spec/functional/resource/chocolatey_package_spec.rb +3 -3
  207. data/spec/functional/resource/cron_spec.rb +3 -3
  208. data/spec/functional/resource/dsc_script_spec.rb +6 -9
  209. data/spec/functional/resource/mount_spec.rb +10 -2
  210. data/spec/functional/resource/powershell_package_source_spec.rb +107 -0
  211. data/spec/functional/resource/powershell_script_spec.rb +57 -14
  212. data/spec/functional/resource/windows_certificate_spec.rb +10 -6
  213. data/spec/functional/resource/windows_firewall_rule_spec.rb +93 -0
  214. data/spec/functional/resource/windows_package_spec.rb +36 -10
  215. data/spec/functional/resource/windows_share_spec.rb +103 -0
  216. data/spec/functional/resource/windows_task_spec.rb +2 -3
  217. data/spec/functional/resource/zypper_package_spec.rb +11 -0
  218. data/spec/integration/client/client_spec.rb +2 -1
  219. data/spec/integration/compliance/compliance_spec.rb +81 -0
  220. data/spec/integration/knife/client_key_create_spec.rb +1 -1
  221. data/spec/integration/knife/node_create_spec.rb +1 -1
  222. data/spec/integration/knife/node_environment_set_spec.rb +1 -1
  223. data/spec/integration/knife/node_run_list_add_spec.rb +4 -4
  224. data/spec/integration/knife/node_run_list_remove_spec.rb +1 -1
  225. data/spec/integration/knife/node_run_list_set_spec.rb +1 -1
  226. data/spec/integration/knife/node_show_spec.rb +1 -1
  227. data/spec/integration/recipes/notifies_spec.rb +1 -1
  228. data/spec/integration/recipes/provider_choice.rb +2 -2
  229. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -0
  230. data/spec/spec_helper.rb +3 -4
  231. data/spec/support/lib/chef/resource/cat.rb +1 -1
  232. data/spec/support/lib/chef/resource/one_two_three_four.rb +1 -1
  233. data/spec/support/mock/platform.rb +24 -16
  234. data/spec/support/platform_helpers.rb +11 -4
  235. data/spec/support/shared/unit/knife_shared.rb +1 -1
  236. data/spec/support/shared/unit/script_resource.rb +4 -4
  237. data/spec/support/shared/unit/windows_script_resource.rb +1 -1
  238. data/spec/unit/chef_fs/config_spec.rb +1 -1
  239. data/spec/unit/chef_fs/data_handler/data_bag_item_data_handler.rb +1 -1
  240. data/spec/unit/client_spec.rb +17 -0
  241. data/spec/unit/compliance/fetcher/automate_spec.rb +134 -0
  242. data/spec/unit/compliance/fetcher/chef_server_spec.rb +93 -0
  243. data/spec/unit/compliance/reporter/automate_spec.rb +427 -0
  244. data/spec/unit/compliance/reporter/chef_server_automate_spec.rb +177 -0
  245. data/spec/unit/compliance/reporter/compliance_enforcer_spec.rb +48 -0
  246. data/spec/unit/compliance/runner_spec.rb +140 -0
  247. data/spec/unit/data_collector_spec.rb +0 -4
  248. data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +11 -11
  249. data/spec/unit/http/ssl_policies_spec.rb +11 -0
  250. data/spec/unit/knife/client_create_spec.rb +2 -2
  251. data/spec/unit/knife/configure_client_spec.rb +5 -5
  252. data/spec/unit/knife/configure_spec.rb +3 -3
  253. data/spec/unit/knife/cookbook_delete_spec.rb +2 -2
  254. data/spec/unit/knife/cookbook_download_spec.rb +2 -2
  255. data/spec/unit/knife/cookbook_list_spec.rb +2 -2
  256. data/spec/unit/knife/cookbook_metadata_spec.rb +3 -3
  257. data/spec/unit/knife/core/node_editor_spec.rb +1 -1
  258. data/spec/unit/knife/environment_compare_spec.rb +3 -3
  259. data/spec/unit/knife/supermarket_download_spec.rb +8 -8
  260. data/spec/unit/knife/supermarket_list_spec.rb +3 -3
  261. data/spec/unit/knife/supermarket_search_spec.rb +1 -1
  262. data/spec/unit/knife/tag_create_spec.rb +1 -1
  263. data/spec/unit/knife/tag_delete_spec.rb +1 -1
  264. data/spec/unit/knife/user_create_spec.rb +1 -1
  265. data/spec/unit/mixin/powershell_exec_spec.rb +41 -4
  266. data/spec/unit/mixin/powershell_out_spec.rb +14 -0
  267. data/spec/unit/mixin/which.rb +1 -1
  268. data/spec/unit/platform/query_helpers_spec.rb +11 -12
  269. data/spec/unit/provider/dsc_resource_spec.rb +10 -27
  270. data/spec/unit/provider/dsc_script_spec.rb +1 -1
  271. data/spec/unit/provider/group/windows_spec.rb +6 -0
  272. data/spec/unit/provider/group_spec.rb +1 -1
  273. data/spec/unit/provider/mount/linux_spec.rb +10 -0
  274. data/spec/unit/provider/mount/mount_spec.rb +21 -10
  275. data/spec/unit/provider/mount/solaris_spec.rb +1 -1
  276. data/spec/unit/provider/mount/windows_spec.rb +1 -0
  277. data/spec/unit/provider/mount_spec.rb +31 -0
  278. data/spec/unit/provider/package/chocolatey_spec.rb +1 -2
  279. data/spec/unit/provider/package/powershell_spec.rb +87 -95
  280. data/spec/unit/provider/package/zypper_spec.rb +0 -25
  281. data/spec/unit/provider/package_spec.rb +2 -2
  282. data/spec/unit/provider/powershell_script_spec.rb +11 -0
  283. data/spec/unit/provider/subversion_spec.rb +0 -3
  284. data/spec/unit/provider/systemd_unit_spec.rb +1 -1
  285. data/spec/unit/provider/user_spec.rb +7 -1
  286. data/spec/unit/provider/windows_env_spec.rb +18 -34
  287. data/spec/unit/provider/windows_path_spec.rb +6 -11
  288. data/spec/unit/provider/windows_task_spec.rb +7 -6
  289. data/spec/unit/resource/breakpoint_spec.rb +1 -1
  290. data/spec/unit/resource/build_essential_spec.rb +0 -12
  291. data/spec/unit/resource/chef_client_config_spec.rb +137 -0
  292. data/spec/unit/resource/ifconfig_spec.rb +2 -10
  293. data/spec/unit/resource/mount_spec.rb +18 -5
  294. data/spec/unit/resource/powershell_package_source_spec.rb +20 -20
  295. data/spec/unit/resource/powershell_script_spec.rb +4 -74
  296. data/spec/unit/resource/service_spec.rb +2 -2
  297. data/spec/unit/resource/solaris_package_spec.rb +8 -10
  298. data/spec/unit/resource/windows_certificate_spec.rb +12 -0
  299. data/spec/unit/resource_inspector_spec.rb +3 -3
  300. data/spec/unit/shell_spec.rb +2 -2
  301. data/spec/unit/util/dsc/configuration_generator_spec.rb +79 -0
  302. data/spec/unit/util/dsc/local_configuration_manager_spec.rb +27 -35
  303. data/tasks/rspec.rb +1 -1
  304. metadata +47 -24
  305. data/lib/chef/monkey_patches/net_http.rb +0 -22
  306. data/lib/chef/provider/windows_env.rb +0 -210
  307. data/lib/chef/provider/windows_path.rb +0 -61
  308. data/lib/chef/provider/windows_task.rb +0 -631
  309. data/lib/chef/util/powershell/cmdlet.rb +0 -175
  310. data/lib/chef/util/powershell/cmdlet_result.rb +0 -61
  311. data/spec/functional/util/powershell/cmdlet_spec.rb +0 -111
  312. data/spec/support/mock/constant.rb +0 -52
  313. data/spec/unit/monkey_patches/uri_spec.rb +0 -34
  314. data/spec/unit/provider_resolver_spec.rb +0 -885
  315. data/spec/unit/resource/data/InstallHistory_with_CLT.plist +0 -92
  316. data/spec/unit/resource/data/InstallHistory_without_CLT.plist +0 -38
  317. data/spec/unit/util/powershell/cmdlet_spec.rb +0 -106
@@ -25,7 +25,7 @@ class Chef
25
25
  class User
26
26
  class Solaris < Chef::Provider::User
27
27
  provides :solaris_user
28
- provides :user, os: %w{openindiana opensolaris illumos omnios solaris2 smartos}
28
+ provides :user, os: %w{openindiana illumos omnios solaris2 smartos}
29
29
 
30
30
  PASSWORD_FILE = "/etc/shadow".freeze
31
31
 
@@ -61,13 +61,20 @@ class Chef
61
61
  # <true>:: If a change is required
62
62
  # <false>:: If the users are identical
63
63
  def compare_user
64
+ @change_desc = []
64
65
  unless @net_user.validate_credentials(new_resource.password)
65
- logger.trace("#{new_resource} password has changed")
66
- return true
66
+ @change_desc << "update password"
67
67
  end
68
+
68
69
  %i{uid comment home shell full_name}.any? do |user_attrib|
69
- !new_resource.send(user_attrib).nil? && new_resource.send(user_attrib) != current_resource.send(user_attrib)
70
+ new_val = new_resource.send(user_attrib)
71
+ cur_val = current_resource.send(user_attrib)
72
+ if !new_val.nil? && new_val != cur_val
73
+ @change_desc << "change #{user_attrib} from #{cur_val} to #{new_val}"
74
+ end
70
75
  end
76
+
77
+ !@change_desc.empty?
71
78
  end
72
79
 
73
80
  def create_user
@@ -47,11 +47,8 @@ require_relative "provider/systemd_unit"
47
47
  require_relative "provider/template"
48
48
  require_relative "provider/user"
49
49
  require_relative "provider/whyrun_safe_ruby_block"
50
- require_relative "provider/windows_env"
51
50
  require_relative "provider/yum_repository"
52
- require_relative "provider/windows_task"
53
51
  require_relative "provider/zypper_repository"
54
- require_relative "provider/windows_path"
55
52
 
56
53
  require_relative "provider/package/apt"
57
54
  require_relative "provider/package/chocolatey"
@@ -0,0 +1,71 @@
1
+ #
2
+ # Author:: Matt Wrock (<mwrock@chef.io>)
3
+ # Copyright:: Copyright (c) Chef Software Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ class Chef
19
+ class Pwsh < Chef::PowerShell
20
+
21
+ # Run a command under pwsh (powershell core) via FFI
22
+ # This implementation requires the managed dll, native wrapper and a
23
+ # published, self contained dotnet core directory tree to exist in the
24
+ # bindir directory.
25
+ #
26
+ # @param script [String] script to run
27
+ # @return [Object] output
28
+ def initialize(script)
29
+ @dll = Pwsh.dll
30
+ super
31
+ end
32
+
33
+ protected
34
+
35
+ def exec(script)
36
+ # Note that we need to override the location of the shared dotnet core library
37
+ # location. With most .net core applications, you can simply publish them as a
38
+ # "self-contained" application allowing consumers of the application to run them
39
+ # and use its own stand alone version of the .net core runtime. However because
40
+ # this is simply a dll and not an exe, it will look for the runtime in the shared
41
+ # .net core installation folder. By setting DOTNET_MULTILEVEL_LOOKUP to 0 we can
42
+ # override that folder's location with DOTNET_ROOT. To avoid the possibility of
43
+ # interfering with other .net core processes that might rely on the common shared
44
+ # location, we revert these variables after the script completes.
45
+ original_dml = ENV["DOTNET_MULTILEVEL_LOOKUP"]
46
+ original_dotnet_root = ENV["DOTNET_ROOT"]
47
+ original_dotnet_root_x86 = ENV["DOTNET_ROOT(x86)"]
48
+
49
+ ENV["DOTNET_MULTILEVEL_LOOKUP"] = "0"
50
+ ENV["DOTNET_ROOT"] = RbConfig::CONFIG["bindir"]
51
+ ENV["DOTNET_ROOT(x86)"] = RbConfig::CONFIG["bindir"]
52
+
53
+ super
54
+ ensure
55
+ ENV["DOTNET_MULTILEVEL_LOOKUP"] = original_dml
56
+ ENV["DOTNET_ROOT"] = original_dotnet_root
57
+ ENV["DOTNET_ROOT(x86)"] = original_dotnet_root_x86
58
+ end
59
+
60
+ def self.dll
61
+ # This Powershell DLL source lives here: https://github.com/chef/chef-powershell-shim
62
+ # Every merge into that repo triggers a Habitat build and promotion. Running
63
+ # the rake :update_chef_exec_dll task in this (chef/chef) repo will pull down
64
+ # the built packages and copy the binaries to distro/ruby_bin_folder. Bundle install
65
+ # ensures that the correct architecture binaries are installed into the path.
66
+ # Also note that the version of pwsh is determined by which assemblies the dll was
67
+ # built with. To update powershell, those dependencies must be bumped.
68
+ @dll ||= Dir.glob("#{RbConfig::CONFIG["bindir"]}/**/Chef.PowerShell.Wrapper.Core.dll").last
69
+ end
70
+ end
71
+ end
@@ -1480,7 +1480,7 @@ class Chef
1480
1480
  def self.use(partial)
1481
1481
  dirname = ::File.dirname(partial)
1482
1482
  basename = ::File.basename(partial, ".rb")
1483
- basename = basename[1..-1] if basename.start_with?("_")
1483
+ basename = basename[1..] if basename.start_with?("_")
1484
1484
  class_eval IO.read(::File.expand_path("#{dirname}/_#{basename}.rb", ::File.dirname(caller_locations.first.absolute_path)))
1485
1485
  end
1486
1486
 
@@ -19,7 +19,9 @@
19
19
  require_relative "../resource"
20
20
  require_relative "../http/simple"
21
21
  require "tmpdir" unless defined?(Dir.mktmpdir)
22
- autoload :Addressable, "addressable"
22
+ module Addressable
23
+ autoload :URI, "addressable/uri"
24
+ end
23
25
 
24
26
  class Chef
25
27
  class Resource
@@ -60,15 +62,14 @@ class Chef
60
62
  end
61
63
  ```
62
64
 
63
- **Add the JuJu PPA, grab the key from the keyserver, and add source repo**:
65
+ **Add the JuJu PPA, grab the key from the Ubuntu keyserver, and add source repo**:
64
66
 
65
67
  ```ruby
66
68
  apt_repository 'juju' do
67
- uri 'http://ppa.launchpad.net/juju/stable/ubuntu'
69
+ uri 'ppa:juju/stable'
68
70
  components ['main']
69
71
  distribution 'xenial'
70
72
  key 'C8068B11'
71
- keyserver 'keyserver.ubuntu.com'
72
73
  action :add
73
74
  deb_src true
74
75
  end
@@ -168,7 +169,7 @@ class Chef
168
169
  # is the provided ID a key ID from a keyserver. Looks at length and HEX only values
169
170
  # @param [String] id the key value passed by the user that *may* be an ID
170
171
  def is_key_id?(id)
171
- id = id[2..-1] if id.start_with?("0x")
172
+ id = id[2..] if id.start_with?("0x")
172
173
  id =~ /^\h+$/ && [8, 16, 40].include?(id.length)
173
174
  end
174
175
 
@@ -25,7 +25,125 @@ class Chef
25
25
 
26
26
  provides :bash
27
27
 
28
- description "Use the **bash** resource to execute scripts using the Bash interpreter. This resource may also use any of the actions and properties that are available to the execute resource. Commands that are executed with this resource are (by their nature) not idempotent, as they are typically unique to the environment in which they are run. Use not_if and only_if to guard this resource for idempotence."
28
+ description "Use the **bash** resource to execute scripts using the Bash interpreter. This resource may also use any of the actions and properties that are available to the **execute** resource. Commands that are executed with this resource are (by their nature) not idempotent, as they are typically unique to the environment in which they are run. Use `not_if` and `only_if` to guard this resource for idempotence."
29
+ examples <<~'DOC'
30
+ **Compile an application**
31
+
32
+ ```ruby
33
+ bash 'install_something' do
34
+ user 'root'
35
+ cwd '/tmp'
36
+ code <<-EOH
37
+ wget http://www.example.com/tarball.tar.gz
38
+ tar -zxf tarball.tar.gz
39
+ cd tarball
40
+ ./configure
41
+ make
42
+ make install
43
+ EOH
44
+ end
45
+ ```
46
+
47
+ **Install a file from a remote location**
48
+
49
+ The following is an example of how to install the foo123 module for Nginx. This module adds shell-style functionality to an Nginx configuration file and does the following:
50
+
51
+ - Declares three variables
52
+ - Gets the Nginx file from a remote location
53
+ - Installs the file using Bash to the path specified by the `src_filepath` variable
54
+
55
+ ```ruby
56
+ src_filename = "foo123-nginx-module-v#{node['nginx']['foo123']['version']}.tar.gz"
57
+ src_filepath = "#{Chef::Config['file_cache_path']}/#{src_filename}"
58
+ extract_path = "#{Chef::Config['file_cache_path']}/nginx_foo123_module/#{node['nginx']['foo123']['checksum']}"
59
+
60
+ remote_file 'src_filepath' do
61
+ source node['nginx']['foo123']['url']
62
+ checksum node['nginx']['foo123']['checksum']
63
+ owner 'root'
64
+ group 'root'
65
+ mode '0755'
66
+ end
67
+
68
+ bash 'extract_module' do
69
+ cwd ::File.dirname(src_filepath)
70
+ code <<-EOH
71
+ mkdir -p #{extract_path}
72
+ tar xzf #{src_filename} -C #{extract_path}
73
+ mv #{extract_path}/*/* #{extract_path}/
74
+ EOH
75
+ not_if { ::File.exist?(extract_path) }
76
+ end
77
+ ```
78
+
79
+ **Install an application from git**
80
+
81
+ ```ruby
82
+ git "#{Chef::Config[:file_cache_path]}/ruby-build" do
83
+ repository 'git://github.com/rbenv/ruby-build.git'
84
+ revision 'master'
85
+ action :sync
86
+ end
87
+
88
+ bash 'install_ruby_build' do
89
+ cwd "#{Chef::Config[:file_cache_path]}/ruby-build"
90
+ user 'rbenv'
91
+ group 'rbenv'
92
+ code <<-EOH
93
+ ./install.sh
94
+ EOH
95
+ environment 'PREFIX' => '/usr/local'
96
+ end
97
+ ```
98
+
99
+ **Using Attributes in Bash Code**
100
+
101
+ The following recipe shows how an attributes file can be used to store certain settings. An attributes file is located in the `attributes/`` directory in the same cookbook as the recipe which calls the attributes file. In this example, the attributes file specifies certain settings for Python that are then used across all nodes against which this recipe will run.
102
+
103
+ Python packages have versions, installation directories, URLs, and checksum files. An attributes file that exists to support this type of recipe would include settings like the following:
104
+
105
+ ```ruby
106
+ default['python']['version'] = '2.7.1'
107
+
108
+ if python['install_method'] == 'package'
109
+ default['python']['prefix_dir'] = '/usr'
110
+ else
111
+ default['python']['prefix_dir'] = '/usr/local'
112
+ end
113
+
114
+ default['python']['url'] = 'http://www.python.org/ftp/python'
115
+ default['python']['checksum'] = '80e387...85fd61'
116
+ ```
117
+
118
+ and then the methods in the recipe may refer to these values. A recipe that is used to install Python will need to do the following:
119
+
120
+ - Identify each package to be installed (implied in this example, not shown)
121
+ - Define variables for the package `version` and the `install_path`
122
+ - Get the package from a remote location, but only if the package does not already exist on the target system
123
+ - Use the **bash** resource to install the package on the node, but only when the package is not already installed
124
+
125
+ ```ruby
126
+ version = node['python']['version']
127
+ install_path = "#{node['python']['prefix_dir']}/lib/python#{version.split(/(^\d+\.\d+)/)[1]}"
128
+
129
+ remote_file "#{Chef::Config[:file_cache_path]}/Python-#{version}.tar.bz2" do
130
+ source "#{node['python']['url']}/#{version}/Python-#{version}.tar.bz2"
131
+ checksum node['python']['checksum']
132
+ mode '0755'
133
+ not_if { ::File.exist?(install_path) }
134
+ end
135
+
136
+ bash 'build-and-install-python' do
137
+ cwd Chef::Config[:file_cache_path]
138
+ code <<-EOF
139
+ tar -jxvf Python-#{version}.tar.bz2
140
+ (cd Python-#{version} && ./configure #{configure_options})
141
+ (cd Python-#{version} && make && make install)
142
+ EOF
143
+ not_if { ::File.exist?(install_path) }
144
+ end
145
+ ```
146
+ DOC
29
147
 
30
148
  def initialize(name, run_context = nil)
31
149
  super
@@ -25,7 +25,7 @@ class Chef
25
25
 
26
26
  provides :batch
27
27
 
28
- description "Use the **batch** resource to execute a batch script using the cmd.exe interpreter on Windows. The batch resource creates and executes a temporary file (similar to how the script resource behaves), rather than running the command inline. Commands that are executed with this resource are (by their nature) not idempotent, as they are typically unique to the environment in which they are run. Use not_if and only_if to guard this resource for idempotence."
28
+ description "Use the **batch** resource to execute a batch script using the cmd.exe interpreter on Windows. The batch resource creates and executes a temporary file (similar to how the script resource behaves), rather than running the command inline. Commands that are executed with this resource are (by their nature) not idempotent, as they are typically unique to the environment in which they are run. Use `not_if` and `only_if` to guard this resource for idempotence."
29
29
 
30
30
  def initialize(*args)
31
31
  super
@@ -49,6 +49,8 @@ class Chef
49
49
 
50
50
  **The same recipe with breakpoints**
51
51
 
52
+ In the following example, the name of each breakpoint is an arbitrary string.
53
+
52
54
  ```ruby
53
55
  breakpoint "before yum_key node['yum']['repo_name']['key']" do
54
56
  action :break
@@ -81,7 +83,7 @@ class Chef
81
83
  end
82
84
  ```
83
85
 
84
- where the name of each breakpoint is an arbitrary string. In the previous examples, the names are used to indicate if the breakpoint is before or after a resource, and then also to specify which resource.
86
+ In the previous examples, the names are used to indicate if the breakpoint is before or after a resource and also to specify which resource it is before or after.
85
87
  DOC
86
88
 
87
89
  default_action :break
@@ -15,7 +15,6 @@
15
15
  #
16
16
 
17
17
  require_relative "../resource"
18
- autoload :Plist, "plist"
19
18
 
20
19
  class Chef
21
20
  class Resource
@@ -130,8 +129,8 @@ class Chef
130
129
  pkg_label = xcode_cli_package_label
131
130
 
132
131
  # With upgrade action we should install if it's not installed or if there's an available update.
133
- # `xcode_cli_package_label` will be nil if there's no update.
134
- install_xcode_cli_tools(pkg_label) if !xcode_cli_installed? || xcode_cli_package_label
132
+ # `pkg_label` will be nil if there's no update.
133
+ install_xcode_cli_tools(pkg_label) if !xcode_cli_installed? || pkg_label
135
134
  else
136
135
  Chef::Log.info "The build_essential resource :upgrade action is only supported on macOS systems. Skipping..."
137
136
  end
@@ -160,14 +159,12 @@ class Chef
160
159
  end
161
160
 
162
161
  #
163
- # Determine if the XCode Command Line Tools are installed by parsing the install history plist.
164
- # We parse the plist data install of running pkgutil because we found that pkgutils doesn't always contain all the packages
162
+ # Determine if the XCode Command Line Tools are installed by checking
163
+ # for success from `xcode-select -p`
165
164
  #
166
165
  # @return [true, false]
167
166
  def xcode_cli_installed?
168
- packages = ::Plist.parse_xml(::File.open("/Library/Receipts/InstallHistory.plist", "r"))
169
- packages.select! { |package| package["displayName"].match? "Command Line Tools" }
170
- !packages.empty?
167
+ !shell_out("xcode-select", "-p").error?
171
168
  end
172
169
 
173
170
  #
@@ -0,0 +1,313 @@
1
+ #
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require_relative "../resource"
18
+ require "chef-utils/dist" unless defined?(ChefUtils::Dist)
19
+
20
+ class Chef
21
+ class Resource
22
+ class ChefClientConfig < Chef::Resource
23
+ unified_mode true
24
+
25
+ provides :chef_client_config
26
+
27
+ description "Use the **chef_client_config** resource to create a client.rb file in the #{ChefUtils::Dist::Infra::PRODUCT} configuration directory. See the [client.rb docs](https://docs.chef.io/config_rb_client/) for more details on options available in the client.rb configuration file."
28
+ introduced "16.6"
29
+ examples <<~DOC
30
+ **Bare minimum #{ChefUtils::Dist::Infra::PRODUCT} client.rb**:
31
+
32
+ The absolute minimum configuration necessary for a node to communicate with the Infra Server is the URL of the Infra Server. All other configuration options either have values at the server side (Policyfiles, Roles, Environments, etc) or have default values determined at client startup.
33
+
34
+ ```ruby
35
+ chef_client_config 'Create client.rb' do
36
+ chef_server_url 'https://chef.example.dmz'
37
+ end
38
+ ```
39
+
40
+ **More complex #{ChefUtils::Dist::Infra::PRODUCT} client.rb**:
41
+
42
+ ```ruby
43
+ chef_client_config 'Create client.rb' do
44
+ chef_server_url 'https://chef.example.dmz'
45
+ log_level :info
46
+ log_location :syslog
47
+ http_proxy 'proxy.example.dmz'
48
+ https_proxy 'proxy.example.dmz'
49
+ no_proxy %w(internal.example.dmz)
50
+ end
51
+ ```
52
+
53
+ **Adding additional config content to the client.rb**:
54
+
55
+ This resource aims to provide common configuration options. Some configuration options are missing and some users may want to use arbitrary Ruby code within their configuration. For this we offer an `additional_config` property that can be used to add any configuration or code to the bottom of the `client.rb` file. Also keep in mind that within the configuration directory is a `client.d` directory where you can put additional `.rb` files containing configuration options. These can be created using `file` or `template` resources within your cookbooks as necessary.
56
+
57
+ ```ruby
58
+ chef_client_config 'Create client.rb' do
59
+ chef_server_url 'https://chef.example.dmz'
60
+ additional_config <<~CONFIG
61
+ # Extra config code to safely load a gem into the client run.
62
+ # Since the config is Ruby you can run any Ruby code you want via the client.rb.
63
+ # It's a great way to break things, so be careful
64
+ begin
65
+ require 'aws-sdk'
66
+ rescue LoadError
67
+ Chef::Log.warn "Failed to load aws-sdk."
68
+ end
69
+ CONFIG
70
+ end
71
+ ```
72
+
73
+ **Setup two report handlers in the client.rb**:
74
+
75
+ ```ruby
76
+ chef_client_config 'Create client.rb' do
77
+ chef_server_url 'https://chef.example.dmz'
78
+ report_handlers [
79
+ {
80
+ 'class' => 'ReportHandler1Class',
81
+ 'arguments' => ["'FirstArgument'", "'SecondArgument'"],
82
+ },
83
+ {
84
+ 'class' => 'ReportHandler2Class',
85
+ 'arguments' => ["'FirstArgument'", "'SecondArgument'"],
86
+ },
87
+ ]
88
+ end
89
+ ```
90
+ DOC
91
+
92
+ # @todo policy_file or policy_group being set requires the other to be set so enforce that.
93
+ # @todo all properties for automate report
94
+ # @todo add all descriptions
95
+ # @todo validate handler hash structure
96
+
97
+ #
98
+ # @param [String, Symbol] prop_val the value from the property
99
+ #
100
+ # @return [Symbol] The symbol form of the symbol-like string, string, or symbol value
101
+ #
102
+ def string_to_symbol(prop_val)
103
+ if prop_val.is_a?(String) && prop_val.start_with?(":")
104
+ prop_val[1..-1].to_sym
105
+ else
106
+ prop_val.to_sym
107
+ end
108
+ end
109
+
110
+ property :config_directory, String,
111
+ description: "The directory to store the client.rb in.",
112
+ default: ChefConfig::Config.etc_chef_dir,
113
+ default_description: "`/etc/chef/` on *nix-like systems and `C:\\chef\\` on Windows"
114
+
115
+ property :user, String,
116
+ description: "The user that should own the client.rb file and the configuration directory if it needs to be created. Note: The configuration directory will not be created if it already exists, which allows you to further control the setup of that directory outside of this resource."
117
+
118
+ property :group, String,
119
+ description: "The group that should own the client.rb file and the configuration directory if it needs to be created. Note: The configuration directory will not be created if it already exists, which allows you to further control the setup of that directory outside of this resource."
120
+
121
+ property :node_name, [String, NilClass], # this accepts nil so people can disable the default
122
+ description: "The name of the node. This configuration sets the `node.name` value used in cookbooks and the `client_name` value used when authenticating to a #{ChefUtils::Dist::Server::PRODUCT} to determine what configuration to apply. Note: By default this configuration uses the `node.name` value which would be set during bootstrap. Hard coding this value in the `client.rb` config avoids logic within #{ChefUtils::Dist::Server::PRODUCT} that performs DNS lookups and may fail in the event of a DNS outage. To skip this default value and instead use the built-in #{ChefUtils::Dist::Server::PRODUCT} logic, set this property to `nil`",
123
+ default: lazy { node.name },
124
+ default_description: "The `node.name` value reported by #{ChefUtils::Dist::Infra::PRODUCT}."
125
+
126
+ property :chef_server_url, String,
127
+ description: "The URL for the #{ChefUtils::Dist::Server::PRODUCT}.",
128
+ required: true
129
+
130
+ # @todo Allow passing this as a string and convert it to the symbol
131
+ property :ssl_verify_mode, [Symbol, String],
132
+ equal_to: %i{verify_none verify_peer},
133
+ coerce: proc { |x| string_to_symbol(x) },
134
+ description: <<~DESC
135
+ Set the verify mode for HTTPS requests.
136
+
137
+ * Use :verify_none for no validation of SSL certificates.
138
+ * Use :verify_peer for validation of all SSL certificates, including the #{ChefUtils::Dist::Server::PRODUCT} connections, S3 connections, and any HTTPS remote_file resource URLs used in #{ChefUtils::Dist::Infra::PRODUCT} runs. This is the recommended setting.
139
+ DESC
140
+
141
+ property :formatters, Array,
142
+ description: "",
143
+ default: []
144
+
145
+ property :event_loggers, Array,
146
+ description: "",
147
+ default: []
148
+
149
+ property :log_level, Symbol,
150
+ description: "The level of logging performed by the #{ChefUtils::Dist::Infra::PRODUCT}.",
151
+ equal_to: %i{auto trace debug info warn fatal}
152
+
153
+ property :log_location, [String, Symbol],
154
+ description: "The location to save logs to. This can either by a path to a log file on disk `:syslog` to log to Syslog, `:win_evt` to log to the Windows Event Log, or `'STDERR'`/`'STDOUT'` to log to the *nix text streams.",
155
+ callbacks: {
156
+ "accepts Symbol values of ':win_evt' for Windows Event Log or ':syslog' for Syslog" => lambda { |p|
157
+ p.is_a?(Symbol) ? %i{win_evt syslog}.include?(p) : true
158
+ },
159
+ }
160
+
161
+ property :http_proxy, String,
162
+ description: "The proxy server to use for HTTP connections."
163
+
164
+ property :https_proxy, String,
165
+ description: "The proxy server to use for HTTPS connections."
166
+
167
+ property :ftp_proxy, String,
168
+ description: "The proxy server to use for FTP connections."
169
+
170
+ property :no_proxy, [String, Array],
171
+ description: "A comma-separated list or an array of URLs that do not need a proxy.",
172
+ coerce: proc { |x| x.is_a?(Array) ? x.join(",") : x },
173
+ default: []
174
+
175
+ # @todo we need to fixup bad plugin naming inputs here
176
+ property :ohai_disabled_plugins, Array,
177
+ description: "Ohai plugins that should be disabled in order to speed up the #{ChefUtils::Dist::Infra::PRODUCT} run and reduce the size of node data sent to #{ChefUtils::Dist::Infra::PRODUCT}",
178
+ coerce: proc { |x| x.map { |v| string_to_symbol(v).capitalize } },
179
+ default: []
180
+
181
+ # @todo we need to fixup bad plugin naming inputs here
182
+ property :ohai_optional_plugins, Array,
183
+ description: "Optional Ohai plugins that should be enabled to provide additional Ohai data for use in cookbooks.",
184
+ coerce: proc { |x| x.map { |v| string_to_symbol(v).capitalize } },
185
+ default: []
186
+
187
+ property :minimal_ohai, [true, false],
188
+ description: "Run a minimal set of Ohai plugins providing data necessary for the execution of #{ChefUtils::Dist::Infra::PRODUCT}'s built-in resources. Setting this to true will skip many large and time consuming data sets such as `cloud` or `packages`. Setting this this to true may break cookbooks that assume all Ohai data will be present."
189
+
190
+ property :start_handlers, Array,
191
+ description: %q(An array of hashes that contain a report handler class and the arguments to pass to that class on initialization. The hash should include `class` and `argument` keys where `class` is a String and `argument` is an array of quoted String values. For example: `[{'class' => 'MyHandler', %w('"argument1"', '"argument2"')}]`),
192
+ default: []
193
+
194
+ property :report_handlers, Array,
195
+ description: %q(An array of hashes that contain a report handler class and the arguments to pass to that class on initialization. The hash should include `class` and `argument` keys where `class` is a String and `argument` is an array of quoted String values. For example: `[{'class' => 'MyHandler', %w('"argument1"', '"argument2"')}]`),
196
+ default: []
197
+
198
+ property :exception_handlers, Array,
199
+ description: %q(An array of hashes that contain a exception handler class and the arguments to pass to that class on initialization. The hash should include `class` and `argument` keys where `class` is a String and `argument` is an array of quoted String values. For example: `[{'class' => 'MyHandler', %w('"argument1"', '"argument2"')}]`),
200
+ default: []
201
+
202
+ property :chef_license, String,
203
+ description: "Accept the [Chef EULA](https://www.chef.io/end-user-license-agreement/)",
204
+ equal_to: %w{accept accept-no-persist accept-silent}
205
+
206
+ property :policy_name, String,
207
+ description: "The name of a policy, as identified by the `name` setting in a Policyfile.rb file. `policy_group` when setting this property."
208
+
209
+ property :policy_group, String,
210
+ description: "The name of a `policy group` that exists on the #{ChefUtils::Dist::Server::PRODUCT}. `policy_name` must also be specified when setting this property."
211
+
212
+ property :named_run_list, String,
213
+ description: "A specific named runlist defined in the node's applied Policyfile, which the should be used when running #{ChefUtils::Dist::Infra::PRODUCT}."
214
+
215
+ property :pid_file, String,
216
+ description: "The location in which a process identification number (pid) is saved. An executable, when started as a daemon, writes the pid to the specified file. "
217
+
218
+ property :file_cache_path, String,
219
+ description: "The location in which cookbooks (and other transient data) files are stored when they are synchronized. This value can also be used in recipes to download files with the `remote_file` resource."
220
+
221
+ property :file_backup_path, String,
222
+ description: "The location in which backup files are stored. If this value is empty, backup files are stored in the directory of the target file"
223
+
224
+ property :file_staging_uses_destdir, String,
225
+ description: "How file staging (via temporary files) is done. When `true`, temporary files are created in the directory in which files will reside. When `false`, temporary files are created under `ENV['TMP']`"
226
+
227
+ property :additional_config, String,
228
+ description: "Additional text to add at the bottom of the client.rb config. This can be used to run custom Ruby or to add less common config options"
229
+
230
+ action :create do
231
+ unless ::Dir.exist?(new_resource.config_directory)
232
+ directory new_resource.config_directory do
233
+ user new_resource.user unless new_resource.user.nil?
234
+ group new_resource.group unless new_resource.group.nil?
235
+ mode "0750"
236
+ recursive true
237
+ end
238
+ end
239
+
240
+ unless ::Dir.exist?(::File.join(new_resource.config_directory, "client.d"))
241
+ directory ::File.join(new_resource.config_directory, "client.d") do
242
+ user new_resource.user unless new_resource.user.nil?
243
+ group new_resource.group unless new_resource.group.nil?
244
+ mode "0750"
245
+ recursive true
246
+ end
247
+ end
248
+
249
+ template ::File.join(new_resource.config_directory, "client.rb") do
250
+ source ::File.expand_path("support/client.erb", __dir__)
251
+ user new_resource.user unless new_resource.user.nil?
252
+ group new_resource.group unless new_resource.group.nil?
253
+ local true
254
+ variables(
255
+ chef_license: new_resource.chef_license,
256
+ chef_server_url: new_resource.chef_server_url,
257
+ event_loggers: new_resource.event_loggers,
258
+ exception_handlers: format_handler(new_resource.exception_handlers),
259
+ file_backup_path: new_resource.file_backup_path,
260
+ file_cache_path: new_resource.file_cache_path,
261
+ file_staging_uses_destdir: new_resource.file_staging_uses_destdir,
262
+ formatters: new_resource.formatters,
263
+ http_proxy: new_resource.http_proxy,
264
+ https_proxy: new_resource.https_proxy,
265
+ ftp_proxy: new_resource.ftp_proxy,
266
+ log_level: new_resource.log_level,
267
+ log_location: new_resource.log_location,
268
+ minimal_ohai: new_resource.minimal_ohai,
269
+ named_run_list: new_resource.named_run_list,
270
+ no_proxy: new_resource.no_proxy,
271
+ node_name: new_resource.node_name,
272
+ ohai_disabled_plugins: new_resource.ohai_disabled_plugins,
273
+ ohai_optional_plugins: new_resource.ohai_optional_plugins,
274
+ pid_file: new_resource.pid_file,
275
+ policy_group: new_resource.policy_group,
276
+ policy_name: new_resource.policy_name,
277
+ report_handlers: format_handler(new_resource.report_handlers),
278
+ ssl_verify_mode: new_resource.ssl_verify_mode,
279
+ start_handlers: format_handler(new_resource.start_handlers),
280
+ additional_config: new_resource.additional_config
281
+ )
282
+ mode "0640"
283
+ action :create
284
+ end
285
+ end
286
+
287
+ action :remove do
288
+ file ::File.join(new_resource.config_directory, "client.rb") do
289
+ action :delete
290
+ end
291
+ end
292
+
293
+ action_class do
294
+ #
295
+ # Format the handler document in the way we want it presented in the client.rb file
296
+ #
297
+ # @param [Hash] a handler property
298
+ #
299
+ # @return [Array] Array of handler data
300
+ #
301
+ def format_handler(handler_property)
302
+ handler_data = []
303
+
304
+ handler_property.each do |handler|
305
+ handler_data << "#{handler["class"]}.new(#{handler["arguments"].join(",")})"
306
+ end
307
+
308
+ handler_data
309
+ end
310
+ end
311
+ end
312
+ end
313
+ end