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
@@ -76,7 +76,7 @@ class Chef
76
76
  # complexity here is due to supporting mangling non-UTF8 strings (e.g. latin-1 filenames with characters that are illegal in UTF-8)
77
77
  b = File.basename(@new_resource.path)
78
78
  i = b.index(".")
79
- i.nil? ? "" : b[i..-1].scrub
79
+ i.nil? ? "" : b[i..].scrub
80
80
  end
81
81
 
82
82
  # Returns the possible directories for the tempfile to be created in.
@@ -115,14 +115,14 @@ class Chef
115
115
 
116
116
  def culprit_line
117
117
  @culprit_line ||= begin
118
- line_number = culprit_backtrace_entry[/^(?:.\:)?[^:]+:([\d]+)/, 1].to_i
118
+ line_number = culprit_backtrace_entry[/^(?:.\:)?[^:]+:(\d+)/, 1].to_i
119
119
  Chef::Log.trace("Line number of compile error: '#{line_number}'")
120
120
  line_number
121
121
  end
122
122
  end
123
123
 
124
124
  def culprit_file
125
- @culprit_file ||= culprit_backtrace_entry[/^((?:.\:)?[^:]+):([\d]+)/, 1]
125
+ @culprit_file ||= culprit_backtrace_entry[/^((?:.\:)?[^:]+):(\d+)/, 1]
126
126
  end
127
127
 
128
128
  def filtered_bt
@@ -16,7 +16,7 @@
16
16
  # See the License for the specific language governing permissions and
17
17
  # limitations under the License.
18
18
  #
19
- require "chef-utils" unless defined?(ChefUtils)
19
+ require "chef-utils" unless defined?(ChefUtils::CANARY)
20
20
 
21
21
  class Chef
22
22
  module Formatters
@@ -79,8 +79,8 @@ class Chef
79
79
  loop do
80
80
 
81
81
  # low rent parser. try to gracefully handle nested blocks in resources
82
- nesting += 1 if /[\s]+do[\s]*/.match?(lines[current_line])
83
- nesting -= 1 if /end[\s]*$/.match?(lines[current_line])
82
+ nesting += 1 if /\s+do\s*/.match?(lines[current_line])
83
+ nesting -= 1 if /end\s*$/.match?(lines[current_line])
84
84
 
85
85
  relevant_lines << format_line(current_line, lines[current_line])
86
86
 
@@ -114,11 +114,11 @@ class Chef
114
114
  end
115
115
 
116
116
  def parse_source
117
- resource.source_line[/^(([\w]:)?[^:]+):([\d]+)/, 1]
117
+ resource.source_line[/^((\w:)?[^:]+):(\d+)/, 1]
118
118
  end
119
119
 
120
120
  def parse_line(source)
121
- resource.source_line[/^#{Regexp.escape(source)}:([\d]+)/, 1].to_i
121
+ resource.source_line[/^#{Regexp.escape(source)}:(\d+)/, 1].to_i
122
122
  end
123
123
 
124
124
  end
@@ -20,7 +20,7 @@ class Chef
20
20
  # pastel.decorate is a lightweight replacement for highline.color
21
21
  def pastel
22
22
  @pastel ||= begin
23
- require "pastel"
23
+ require "pastel" unless defined?(Pastel)
24
24
  Pastel.new
25
25
  end
26
26
  end
@@ -126,7 +126,7 @@ class Chef
126
126
  indent_line(options)
127
127
 
128
128
  # Note that the next line will need to be started
129
- if line[-1..-1] == "\n"
129
+ if line[-1..] == "\n"
130
130
  @line_started = false
131
131
  end
132
132
 
@@ -20,19 +20,30 @@ require_relative "../guard_interpreter"
20
20
 
21
21
  class Chef
22
22
  class GuardInterpreter
23
- class ResourceGuardInterpreter < DefaultGuardInterpreter
24
-
23
+ class ResourceGuardInterpreter
25
24
  def initialize(parent_resource, command, opts)
26
- super(command, opts)
25
+ @command = command
26
+ @opts = opts
27
+
27
28
  @parent_resource = parent_resource
28
29
  @resource = get_interpreter_resource(parent_resource)
29
30
  end
30
31
 
32
+ # This class used to inherit from DefaultGuardInterpreter and it responds
33
+ # to #output, so leave this in for potential backwards compatibility.
34
+ def output
35
+ nil
36
+ end
37
+
31
38
  def evaluate
32
39
  # Add attributes inherited from the parent class
33
40
  # to the resource
34
41
  merge_inherited_attributes
35
42
 
43
+ @opts.each do |attribute, value|
44
+ @resource.send(attribute, value)
45
+ end
46
+
36
47
  # Only execute and script resources and use guard attributes.
37
48
  # The command to be executed on them are passed via different attributes.
38
49
  # Script resources use code attribute and execute resources use
@@ -42,9 +53,9 @@ class Chef
42
53
  # We need to make sure we check for Script first because any resource
43
54
  # that can get to here is an Execute resource.
44
55
  if @resource.is_a? Chef::Resource::Script
45
- block_attributes = @command_opts.merge({ code: @command })
56
+ @resource.code @command
46
57
  else
47
- block_attributes = @command_opts.merge({ command: @command })
58
+ @resource.command @command
48
59
  end
49
60
 
50
61
  # Handles cases like powershell_script where default
@@ -53,33 +64,24 @@ class Chef
53
64
  # the one attribute that causes this changes its default to be
54
65
  # the same after some period to prepare for deprecation
55
66
  if @resource.class.respond_to?(:get_default_attributes)
56
- block_attributes = @resource.class.send(:get_default_attributes, @command_opts).merge(block_attributes)
67
+ @resource.class.send(:get_default_attributes).each do |attribute, value|
68
+ @resource.send(attribute, value)
69
+ end
57
70
  end
58
71
 
59
- resource_block = block_from_attributes(block_attributes)
60
- evaluate_action(nil, &resource_block)
61
- end
62
-
63
- protected
64
-
65
- def evaluate_action(action = nil, &block)
66
- @resource.instance_eval(&block)
67
-
68
- run_action = action || @resource.action
69
-
70
72
  begin
71
73
  # Coerce to an array to be safe. This could happen with a legacy
72
74
  # resource or something overriding the default_action code in a
73
75
  # subclass.
74
- Array(run_action).each { |action_to_run| @resource.run_action(action_to_run) }
75
- resource_updated = @resource.updated
76
+ Array(@resource.action).each { |action_to_run| @resource.run_action(action_to_run) }
77
+ @resource.updated
76
78
  rescue Mixlib::ShellOut::ShellCommandFailed
77
- resource_updated = nil
79
+ nil
78
80
  end
79
-
80
- resource_updated
81
81
  end
82
82
 
83
+ private
84
+
83
85
  def get_interpreter_resource(parent_resource)
84
86
  if parent_resource.nil? || parent_resource.node.nil?
85
87
  raise ArgumentError, "Node for guard resource parent must not be nil"
@@ -106,14 +108,6 @@ class Chef
106
108
  interpreter_resource
107
109
  end
108
110
 
109
- def block_from_attributes(attributes)
110
- Proc.new do
111
- attributes.each_key do |attribute_name|
112
- send(attribute_name, attributes[attribute_name]) if respond_to?(attribute_name)
113
- end
114
- end
115
- end
116
-
117
111
  def merge_inherited_attributes
118
112
  inherited_attributes = []
119
113
 
@@ -121,15 +115,10 @@ class Chef
121
115
  inherited_attributes = @parent_resource.class.send(:guard_inherited_attributes)
122
116
  end
123
117
 
124
- if inherited_attributes && !inherited_attributes.empty?
125
- inherited_attributes.each do |attribute|
126
- if @parent_resource.respond_to?(attribute) && @resource.respond_to?(attribute)
127
- parent_value = @parent_resource.send(attribute)
128
- child_value = @resource.send(attribute)
129
- if parent_value || child_value
130
- @resource.send(attribute, parent_value)
131
- end
132
- end
118
+ inherited_attributes.each do |attribute|
119
+ if @parent_resource.respond_to?(attribute) && @resource.respond_to?(attribute)
120
+ parent_value = @parent_resource.send(attribute)
121
+ @resource.send(attribute, parent_value)
133
122
  end
134
123
  end
135
124
  end
@@ -25,8 +25,8 @@ require "tempfile" unless defined?(Tempfile)
25
25
  autoload :OpenSSL, "openssl"
26
26
  autoload :URI, "uri"
27
27
  module Net
28
- autoload :HTTP, File.expand_path("monkey_patches/net_http", __dir__)
29
- autoload :HTTPClientException, File.expand_path("monkey_patches/net_http", __dir__)
28
+ autoload :HTTP, "net/http"
29
+ autoload :HTTPClientException, "net/http"
30
30
  end
31
31
  require_relative "http/basic_client"
32
32
  require_relative "config"
@@ -165,10 +165,6 @@ class Chef
165
165
  end
166
166
  rescue Exception => exception
167
167
  log_failed_request(response, return_value) unless response.nil?
168
-
169
- if exception.respond_to?(:chef_rest_request=)
170
- exception.chef_rest_request = rest_request
171
- end
172
168
  raise
173
169
  end
174
170
 
@@ -204,9 +200,6 @@ class Chef
204
200
  end
205
201
  rescue Exception => e
206
202
  log_failed_request(response, return_value) unless response.nil?
207
- if e.respond_to?(:chef_rest_request=)
208
- e.chef_rest_request = rest_request
209
- end
210
203
  raise
211
204
  end
212
205
 
@@ -260,9 +253,6 @@ class Chef
260
253
  end
261
254
  rescue Exception => e
262
255
  log_failed_request(response, return_value) unless response.nil?
263
- if e.respond_to?(:chef_rest_request=)
264
- e.chef_rest_request = rest_request
265
- end
266
256
  raise
267
257
  end
268
258
 
@@ -22,7 +22,7 @@
22
22
  #
23
23
  autoload :URI, "uri"
24
24
  module Net
25
- autoload :HTTP, File.expand_path("../monkey_patches/net_http", __dir__)
25
+ autoload :HTTP, "net/http"
26
26
  end
27
27
  require_relative "ssl_policies"
28
28
  require_relative "http_request"
@@ -23,7 +23,7 @@
23
23
  autoload :URI, "uri"
24
24
  autoload :CGI, "cgi"
25
25
  module Net
26
- autoload :HTTP, File.expand_path("../monkey_patches/net_http", __dir__)
26
+ autoload :HTTP, "net/http"
27
27
  end
28
28
  require "chef-utils/dist" unless defined?(ChefUtils::Dist)
29
29
 
@@ -46,7 +46,7 @@
46
46
  require "chef_zero/server"
47
47
  require "chef-utils/dist" unless defined?(ChefUtils::Dist)
48
48
  module Net
49
- autoload :HTTPResponse, File.expand_path("../monkey_patches/net_http", __dir__)
49
+ autoload :HTTPResponse, "net/http"
50
50
  end
51
51
 
52
52
  class Chef
@@ -70,6 +70,12 @@ class Chef
70
70
  end
71
71
 
72
72
  http_client.ca_file = config[:ssl_ca_file]
73
+ elsif ENV["SSL_CERT_FILE"]
74
+ unless ::File.exist?(ENV["SSL_CERT_FILE"])
75
+ raise Chef::Exceptions::ConfigurationError, "The configured ssl_ca_file #{ENV["SSL_CERT_FILE"]} does not exist"
76
+ end
77
+
78
+ http_client.ca_file = ENV["SSL_CERT_FILE"]
73
79
  end
74
80
  end
75
81
 
@@ -24,18 +24,15 @@ require "json" unless defined?(JSON)
24
24
 
25
25
  class Chef
26
26
  class JSONCompat
27
- JSON_MAX_NESTING = 1000
28
27
 
29
28
  class <<self
30
29
 
31
- # API to use to avoid create_additions
32
30
  def parse(source, opts = {})
33
31
  FFI_Yajl::Parser.parse(source, opts)
34
32
  rescue FFI_Yajl::ParseError => e
35
33
  raise Chef::Exceptions::JSON::ParseError, e.message
36
34
  end
37
35
 
38
- # Just call the JSON gem's parse method with a modified :max_nesting field
39
36
  def from_json(source, opts = {})
40
37
  obj = parse(source, opts)
41
38
 
@@ -56,10 +53,8 @@ class Chef
56
53
  end
57
54
 
58
55
  def to_json_pretty(obj, opts = nil)
59
- opts ||= {}
60
- options_map = {}
61
- options_map[:pretty] = true
62
- options_map[:indent] = opts[:indent] if opts.key?(:indent)
56
+ options_map = { pretty: true }
57
+ options_map[:indent] = opts[:indent] if opts.respond_to?(:key?) && opts.key?(:indent)
63
58
  to_json(obj, options_map).chomp
64
59
  end
65
60
 
@@ -46,7 +46,7 @@ class Chef
46
46
  # Actor that the key is for, either a client or a user.
47
47
  @actor = actor
48
48
 
49
- unless actor_field_name == "user" || actor_field_name == "client"
49
+ unless %w{user client}.include?(actor_field_name)
50
50
  raise Chef::Exceptions::InvalidKeyArgument, "the second argument to initialize must be either 'user' or 'client'"
51
51
  end
52
52
 
@@ -330,7 +330,7 @@ class Chef
330
330
  long: "--bootstrap-vault-item VAULT_ITEM",
331
331
  description: 'A single vault and item to update as "vault:item".',
332
332
  proc: Proc.new { |i, accumulator|
333
- (vault, item) = i.split(/:/)
333
+ (vault, item) = i.split(":")
334
334
  accumulator ||= {}
335
335
  accumulator[vault] ||= []
336
336
  accumulator[vault].push(item)
@@ -407,6 +407,7 @@ class Chef
407
407
  deps do
408
408
  require "erubis" unless defined?(Erubis)
409
409
 
410
+ require "net/ssh" unless defined?(Net::SSH)
410
411
  require_relative "../json_compat"
411
412
  require_relative "../util/path_helper"
412
413
  require_relative "bootstrap/chef_vault_handler"
@@ -230,9 +230,9 @@ echo Writing validation key...
230
230
  echo Validation key written.
231
231
  @echo on
232
232
 
233
- <% if @config[:secret] -%>
233
+ <% if secret -%>
234
234
  > <%= bootstrap_directory %>\encrypted_data_bag_secret (
235
- <%= secret %>
235
+ <%= encrypted_data_bag_secret %>
236
236
  )
237
237
  <% end -%>
238
238
 
@@ -285,7 +285,7 @@ class Chef
285
285
  # Train.unpack_target_from_uri only works for complete URIs in
286
286
  # form of proto://[user[:pass]@]host[:port]/
287
287
  # So we'll add the protocol prefix if it's not supplied.
288
- uri_to_check = if URI.regexp.match(uri)
288
+ uri_to_check = if URI::DEFAULT_PARSER.make_regexp.match(uri)
289
289
  uri
290
290
  else
291
291
  "#{default_protocol}://#{uri}"
@@ -79,7 +79,7 @@ class Chef
79
79
  end
80
80
  else
81
81
  # It's a dotted path string.
82
- filter_parts = filter.split(/\./)
82
+ filter_parts = filter.split(".")
83
83
  extract = lambda do |memo, filter_part|
84
84
  memo.is_a?(Hash) ? memo[filter_part.to_sym] : nil
85
85
  end
@@ -22,7 +22,7 @@ class Chef
22
22
  class Knife
23
23
  class CookbookSCMRepo
24
24
 
25
- DIRTY_REPO = /^[\s]+M/.freeze
25
+ DIRTY_REPO = /^\s+M/.freeze
26
26
 
27
27
  include Chef::Mixin::ShellOut
28
28
 
@@ -22,7 +22,7 @@ class Chef
22
22
  class Knife
23
23
  class SubcommandLoader
24
24
  class GemGlobLoader < Chef::Knife::SubcommandLoader
25
- MATCHES_CHEF_GEM ||= %r{/chef-[\d]+\.[\d]+\.[\d]+}.freeze
25
+ MATCHES_CHEF_GEM ||= %r{/chef-\d+\.\d+\.\d+}.freeze
26
26
  MATCHES_THIS_CHEF_GEM ||= %r{/chef-#{Chef::VERSION}(-\w+)?(-\w+)?/}.freeze
27
27
 
28
28
  def subcommand_files
@@ -64,13 +64,16 @@ class Chef
64
64
  # Creates a new object of class TTY::Prompt
65
65
  # with interrupt as exit so that it can be terminated with status code.
66
66
  def prompt
67
- @prompt ||= TTY::Prompt.new(interrupt: :exit)
67
+ @prompt ||= begin
68
+ require "tty-prompt"
69
+ TTY::Prompt.new(interrupt: :exit)
70
+ end
68
71
  end
69
72
 
70
73
  # pastel.decorate is a lightweight replacement for highline.color
71
74
  def pastel
72
75
  @pastel ||= begin
73
- require "pastel"
76
+ require "pastel" unless defined?(Pastel)
74
77
  Pastel.new
75
78
  end
76
79
  end
@@ -32,6 +32,7 @@ class Chef
32
32
  class WindowsBootstrapContext < BootstrapContext
33
33
  attr_accessor :config
34
34
  attr_accessor :chef_config
35
+ attr_accessor :secret
35
36
 
36
37
  def initialize(config, run_list, chef_config, secret = nil)
37
38
  @config = config
@@ -49,8 +50,8 @@ class Chef
49
50
  end
50
51
  end
51
52
 
52
- def secret
53
- escape_and_echo(config[:secret])
53
+ def encrypted_data_bag_secret
54
+ escape_and_echo(@secret)
54
55
  end
55
56
 
56
57
  def trusted_certs_script
@@ -134,8 +135,8 @@ class Chef
134
135
  client_rb << %Q{no_proxy "#{config[:bootstrap_no_proxy]}"\n}
135
136
  end
136
137
 
137
- if config[:secret]
138
- client_rb << %Q{encrypted_data_bag_secret "#{ChefConfig::Config.etc_chef_dir(windows: true)}/encrypted_data_bag_secret"\n}
138
+ if secret
139
+ client_rb << %Q{encrypted_data_bag_secret "#{ChefConfig::PathHelper.escapepath(ChefConfig::Config.etc_chef_dir(windows: true))}\\\\encrypted_data_bag_secret"\n}
139
140
  end
140
141
 
141
142
  unless trusted_certs_script.empty?
@@ -255,6 +256,8 @@ class Chef
255
256
  [String] $localPath
256
257
  )
257
258
 
259
+ [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
260
+
258
261
  $ProxyUrl = $env:http_proxy;
259
262
  $webClient = new-object System.Net.WebClient;
260
263