chef 16.6.14 → 16.7.61

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -11
  3. data/Rakefile +21 -14
  4. data/chef-universal-mingw32.gemspec +1 -1
  5. data/lib/chef/application/knife.rb +1 -1
  6. data/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb +1 -1
  7. data/lib/chef/chef_fs/file_pattern.rb +1 -1
  8. data/lib/chef/client.rb +1 -1
  9. data/lib/chef/cookbook_manifest.rb +1 -1
  10. data/lib/chef/cookbook_site_streaming_uploader.rb +1 -1
  11. data/lib/chef/cookbook_version.rb +2 -5
  12. data/lib/chef/environment.rb +1 -1
  13. data/lib/chef/exceptions.rb +1 -1
  14. data/lib/chef/file_access_control/windows.rb +1 -4
  15. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +2 -2
  16. data/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb +4 -4
  17. data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +28 -39
  18. data/lib/chef/http.rb +2 -12
  19. data/lib/chef/http/basic_client.rb +1 -1
  20. data/lib/chef/http/http_request.rb +1 -1
  21. data/lib/chef/http/socketless_chef_zero_client.rb +1 -1
  22. data/lib/chef/json_compat.rb +2 -7
  23. data/lib/chef/key.rb +1 -1
  24. data/lib/chef/knife/bootstrap.rb +2 -1
  25. data/lib/chef/knife/bootstrap/templates/windows-chef-client-msi.erb +2 -2
  26. data/lib/chef/knife/config_show.rb +1 -1
  27. data/lib/chef/knife/core/cookbook_scm_repo.rb +1 -1
  28. data/lib/chef/knife/core/gem_glob_loader.rb +1 -1
  29. data/lib/chef/knife/core/windows_bootstrap_context.rb +7 -4
  30. data/lib/chef/mixin/convert_to_class_name.rb +0 -56
  31. data/lib/chef/mixin/openssl_helper.rb +1 -1
  32. data/lib/chef/mixin/properties.rb +2 -0
  33. data/lib/chef/mixin/unformatter.rb +1 -1
  34. data/lib/chef/node/attribute_collections.rb +2 -6
  35. data/lib/chef/powershell.rb +5 -2
  36. data/lib/chef/property.rb +1 -1
  37. data/lib/chef/provider/cron.rb +2 -13
  38. data/lib/chef/provider/group.rb +14 -6
  39. data/lib/chef/provider/group/windows.rb +12 -1
  40. data/lib/chef/provider/ifconfig.rb +7 -7
  41. data/lib/chef/provider/ifconfig/debian.rb +5 -7
  42. data/lib/chef/provider/ifconfig/redhat.rb +3 -1
  43. data/lib/chef/provider/launchd.rb +1 -11
  44. data/lib/chef/provider/mount.rb +18 -1
  45. data/lib/chef/provider/mount/linux.rb +4 -0
  46. data/lib/chef/provider/mount/mount.rb +41 -43
  47. data/lib/chef/provider/package.rb +3 -0
  48. data/lib/chef/provider/package/apt.rb +1 -1
  49. data/lib/chef/provider/package/chocolatey.rb +6 -6
  50. data/lib/chef/provider/package/freebsd/base.rb +3 -2
  51. data/lib/chef/provider/package/freebsd/pkgng.rb +1 -1
  52. data/lib/chef/provider/package/ips.rb +1 -1
  53. data/lib/chef/provider/package/powershell.rb +2 -3
  54. data/lib/chef/provider/package/rubygems.rb +1 -1
  55. data/lib/chef/provider/package/snap.rb +1 -3
  56. data/lib/chef/provider/package/solaris.rb +0 -2
  57. data/lib/chef/provider/package/yum/rpm_utils.rb +1 -1
  58. data/lib/chef/provider/package/zypper.rb +98 -71
  59. data/lib/chef/provider/registry_key.rb +4 -3
  60. data/lib/chef/provider/route.rb +2 -2
  61. data/lib/chef/provider/service/debian.rb +2 -1
  62. data/lib/chef/provider/user.rb +17 -9
  63. data/lib/chef/provider/user/aix.rb +1 -1
  64. data/lib/chef/provider/user/mac.rb +12 -4
  65. data/lib/chef/provider/user/solaris.rb +1 -1
  66. data/lib/chef/provider/user/windows.rb +10 -3
  67. data/lib/chef/providers.rb +0 -3
  68. data/lib/chef/pwsh.rb +7 -0
  69. data/lib/chef/resource/bash.rb +119 -1
  70. data/lib/chef/resource/batch.rb +1 -1
  71. data/lib/chef/resource/breakpoint.rb +3 -1
  72. data/lib/chef/resource/build_essential.rb +5 -8
  73. data/lib/chef/resource/csh.rb +2 -2
  74. data/lib/chef/resource/execute.rb +6 -4
  75. data/lib/chef/resource/file.rb +1 -1
  76. data/lib/chef/resource/homebrew_update.rb +4 -1
  77. data/lib/chef/resource/hostname.rb +2 -2
  78. data/lib/chef/resource/ifconfig.rb +52 -5
  79. data/lib/chef/resource/ksh.rb +3 -3
  80. data/lib/chef/resource/lwrp_base.rb +3 -5
  81. data/lib/chef/resource/mount.rb +7 -1
  82. data/lib/chef/resource/perl.rb +2 -2
  83. data/lib/chef/resource/plist.rb +2 -6
  84. data/lib/chef/resource/powershell_package_source.rb +19 -18
  85. data/lib/chef/resource/powershell_script.rb +7 -10
  86. data/lib/chef/resource/python.rb +2 -2
  87. data/lib/chef/resource/registry_key.rb +93 -2
  88. data/lib/chef/resource/route.rb +1 -1
  89. data/lib/chef/resource/ruby.rb +2 -2
  90. data/lib/chef/resource/scm/_scm.rb +2 -1
  91. data/lib/chef/resource/scm/git.rb +82 -1
  92. data/lib/chef/resource/scm/subversion.rb +12 -0
  93. data/lib/chef/resource/script.rb +2 -2
  94. data/lib/chef/resource/solaris_package.rb +0 -2
  95. data/lib/chef/resource/sudo.rb +1 -1
  96. data/lib/chef/resource/support/client.erb +4 -5
  97. data/lib/chef/resource/systemd_unit.rb +42 -1
  98. data/lib/chef/resource/windows_ad_join.rb +9 -9
  99. data/lib/chef/resource/windows_certificate.rb +6 -6
  100. data/lib/chef/resource/windows_dfs_server.rb +7 -4
  101. data/lib/chef/resource/windows_env.rb +173 -0
  102. data/lib/chef/resource/windows_feature.rb +2 -0
  103. data/lib/chef/resource/windows_firewall_profile.rb +7 -12
  104. data/lib/chef/resource/windows_firewall_rule.rb +9 -11
  105. data/lib/chef/resource/windows_font.rb +1 -1
  106. data/lib/chef/resource/windows_package.rb +1 -0
  107. data/lib/chef/resource/windows_path.rb +38 -0
  108. data/lib/chef/resource/windows_security_policy.rb +5 -5
  109. data/lib/chef/resource/windows_service.rb +108 -0
  110. data/lib/chef/resource/windows_share.rb +18 -18
  111. data/lib/chef/resource/windows_task.rb +629 -28
  112. data/lib/chef/resource/windows_workgroup.rb +6 -4
  113. data/lib/chef/resource/yum_repository.rb +1 -1
  114. data/lib/chef/resource_collection/resource_set.rb +1 -5
  115. data/lib/chef/resource_inspector.rb +77 -75
  116. data/lib/chef/run_lock.rb +1 -1
  117. data/lib/chef/server_api.rb +0 -4
  118. data/lib/chef/shell/ext.rb +1 -1
  119. data/lib/chef/util/dsc/lcm_output_parser.rb +1 -3
  120. data/lib/chef/util/dsc/local_configuration_manager.rb +1 -1
  121. data/lib/chef/util/powershell/cmdlet.rb +3 -9
  122. data/lib/chef/version.rb +1 -1
  123. data/lib/chef/win32/security/sid.rb +1 -1
  124. data/spec/functional/mixin/powershell_out_spec.rb +4 -4
  125. data/spec/functional/resource/apt_package_spec.rb +4 -6
  126. data/spec/functional/resource/chocolatey_package_spec.rb +3 -3
  127. data/spec/functional/resource/cron_spec.rb +3 -3
  128. data/spec/functional/resource/dsc_script_spec.rb +3 -3
  129. data/spec/functional/resource/mount_spec.rb +10 -2
  130. data/spec/functional/resource/powershell_package_source_spec.rb +107 -0
  131. data/spec/functional/resource/windows_certificate_spec.rb +10 -6
  132. data/spec/functional/resource/windows_firewall_rule_spec.rb +93 -0
  133. data/spec/functional/resource/windows_package_spec.rb +36 -10
  134. data/spec/functional/resource/windows_share_spec.rb +103 -0
  135. data/spec/functional/resource/windows_task_spec.rb +2 -3
  136. data/spec/functional/resource/zypper_package_spec.rb +11 -0
  137. data/spec/integration/knife/client_key_create_spec.rb +1 -1
  138. data/spec/integration/knife/node_create_spec.rb +1 -1
  139. data/spec/integration/knife/node_environment_set_spec.rb +1 -1
  140. data/spec/integration/knife/node_run_list_add_spec.rb +4 -4
  141. data/spec/integration/knife/node_run_list_remove_spec.rb +1 -1
  142. data/spec/integration/knife/node_run_list_set_spec.rb +1 -1
  143. data/spec/integration/knife/node_show_spec.rb +1 -1
  144. data/spec/integration/recipes/notifies_spec.rb +1 -1
  145. data/spec/integration/recipes/provider_choice.rb +2 -2
  146. data/spec/support/lib/chef/resource/cat.rb +1 -1
  147. data/spec/support/lib/chef/resource/one_two_three_four.rb +1 -1
  148. data/spec/support/mock/platform.rb +24 -16
  149. data/spec/support/platform_helpers.rb +6 -4
  150. data/spec/support/shared/unit/knife_shared.rb +1 -1
  151. data/spec/support/shared/unit/script_resource.rb +4 -4
  152. data/spec/support/shared/unit/windows_script_resource.rb +1 -1
  153. data/spec/unit/client_spec.rb +16 -0
  154. data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +11 -11
  155. data/spec/unit/knife/client_create_spec.rb +2 -2
  156. data/spec/unit/knife/configure_client_spec.rb +5 -5
  157. data/spec/unit/knife/configure_spec.rb +3 -3
  158. data/spec/unit/knife/cookbook_delete_spec.rb +2 -2
  159. data/spec/unit/knife/cookbook_download_spec.rb +2 -2
  160. data/spec/unit/knife/cookbook_list_spec.rb +2 -2
  161. data/spec/unit/knife/cookbook_metadata_spec.rb +3 -3
  162. data/spec/unit/knife/environment_compare_spec.rb +3 -3
  163. data/spec/unit/knife/supermarket_download_spec.rb +8 -8
  164. data/spec/unit/knife/supermarket_list_spec.rb +3 -3
  165. data/spec/unit/knife/supermarket_search_spec.rb +1 -1
  166. data/spec/unit/knife/tag_create_spec.rb +1 -1
  167. data/spec/unit/knife/tag_delete_spec.rb +1 -1
  168. data/spec/unit/knife/user_create_spec.rb +1 -1
  169. data/spec/unit/mixin/which.rb +1 -1
  170. data/spec/unit/provider/group/windows_spec.rb +6 -0
  171. data/spec/unit/provider/group_spec.rb +1 -1
  172. data/spec/unit/provider/mount/linux_spec.rb +10 -0
  173. data/spec/unit/provider/mount/mount_spec.rb +21 -10
  174. data/spec/unit/provider/mount/solaris_spec.rb +1 -1
  175. data/spec/unit/provider/mount_spec.rb +31 -0
  176. data/spec/unit/provider/package/chocolatey_spec.rb +1 -2
  177. data/spec/unit/provider/package/powershell_spec.rb +87 -95
  178. data/spec/unit/provider/package/zypper_spec.rb +0 -25
  179. data/spec/unit/provider/package_spec.rb +2 -2
  180. data/spec/unit/provider/subversion_spec.rb +0 -3
  181. data/spec/unit/provider/user_spec.rb +7 -1
  182. data/spec/unit/provider/windows_env_spec.rb +18 -34
  183. data/spec/unit/provider/windows_path_spec.rb +6 -11
  184. data/spec/unit/provider/windows_task_spec.rb +7 -6
  185. data/spec/unit/resource/breakpoint_spec.rb +1 -1
  186. data/spec/unit/resource/build_essential_spec.rb +0 -12
  187. data/spec/unit/resource/ifconfig_spec.rb +2 -10
  188. data/spec/unit/resource/mount_spec.rb +18 -5
  189. data/spec/unit/resource/powershell_package_source_spec.rb +20 -20
  190. data/spec/unit/resource/powershell_script_spec.rb +4 -74
  191. data/spec/unit/resource/service_spec.rb +2 -2
  192. data/spec/unit/resource/solaris_package_spec.rb +8 -10
  193. data/spec/unit/resource_inspector_spec.rb +3 -3
  194. data/spec/unit/shell_spec.rb +2 -2
  195. data/tasks/rspec.rb +1 -1
  196. metadata +9 -15
  197. data/lib/chef/monkey_patches/net_http.rb +0 -22
  198. data/lib/chef/provider/windows_env.rb +0 -210
  199. data/lib/chef/provider/windows_path.rb +0 -61
  200. data/lib/chef/provider/windows_task.rb +0 -631
  201. data/spec/support/mock/constant.rb +0 -52
  202. data/spec/unit/monkey_patches/uri_spec.rb +0 -34
  203. data/spec/unit/provider_resolver_spec.rb +0 -885
  204. data/spec/unit/resource/data/InstallHistory_with_CLT.plist +0 -92
  205. data/spec/unit/resource/data/InstallHistory_without_CLT.plist +0 -38
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9601a0e75782478aa0b49ba679d1636eefd626471cf89fdc1f3bc03ece08d0d9
4
- data.tar.gz: 55a6507691792de235cecee29b666c915f8dfaa67d54c7928b5bf6b6843aee1b
3
+ metadata.gz: 45d0c49c6265534a875b8044449678109b0c11a22b83027f28826e3ea14ee792
4
+ data.tar.gz: a6375a107a0ece5bbd866f42c0d415e582135d24512d8815b894786e64c685b9
5
5
  SHA512:
6
- metadata.gz: 7123ac0cd41df9a3a5dd64f766e468f1e1ec3cfacd4a85bca99d2a2361154fa0db1cebdc6a09fc19594bcea77ea9bba8994a34e98be870fd7b8e0b9b527c04c4
7
- data.tar.gz: 5474902d65ae70b1c4bf3698452c6ce6599fe741c49133e073f0bbc4eaefa51a73a3f1da64ab8a77cf0cff26567c2869ef9000a7617d383ef89f0bceb660d7f9
6
+ metadata.gz: 8cf6a1c8dd0316944eaa700f6c788e2ff6843dc9bd9252b2710e2465498041e1eb8a6990ace8bbef2bb265e3254e1460a56e9f85489d133a0dffbc03b140c928
7
+ data.tar.gz: e57ee2f117d322936e53b384202691b7d9be946b4be9b4cc697d162163f3b65885109ef5977448861fa6f8db3cafbe364294ab2e30d78b61f7e51d8fc7eed16a
data/Gemfile CHANGED
@@ -30,21 +30,14 @@ group(:omnibus_package) do
30
30
  gem "inspec-core", "~> 4.18"
31
31
  gem "inspec-core-bin", "~> 4.18" # need to provide the binaries for inspec
32
32
  gem "chef-vault"
33
- gem "ed25519" # ed25519 ssh key support done here as it's a native gem we can't put in train
34
- gem "bcrypt_pbkdf", ">= 1.1.0.rc1" # ed25519 ssh key support done here as it's a native gem we can't put in train
35
33
  end
36
34
 
37
35
  group(:omnibus_package, :pry) do
38
36
  gem "pry"
39
37
  gem "pry-byebug"
40
- gem "pry-remote"
41
38
  gem "pry-stack_explorer"
42
39
  end
43
40
 
44
- group(:docgen) do
45
- gem "yard"
46
- end
47
-
48
41
  # Everything except AIX
49
42
  group(:ruby_prof) do
50
43
  # ruby-prof 1.3.0 does not compile on our centos6 builders/kitchen testers
@@ -58,10 +51,7 @@ end
58
51
 
59
52
  group(:development, :test) do
60
53
  gem "rake"
61
- gem "rspec-core", "~> 3.5"
62
- gem "rspec-mocks", "~> 3.5"
63
- gem "rspec-expectations", "~> 3.5"
64
- gem "rspec_junit_formatter", "~> 0.2.0"
54
+ gem "rspec"
65
55
  gem "webmock"
66
56
  gem "fauxhai-ng" # for chef-utils gem
67
57
  end
@@ -81,6 +71,9 @@ eval_gemfile("./Gemfile.local") if File.exist?("./Gemfile.local")
81
71
  # For FFI to call into PowerShell we need the binaries and assemblies located
82
72
  # in the Ruby bindir.
83
73
  # The Powershell DLL source lives here: https://github.com/chef/chef-powershell-shim
74
+ # Every merge into that repo triggers a Habitat build and promotion. Running
75
+ # the rake :update_chef_exec_dll task in this (chef/chef) repo will pull down
76
+ # the built packages and copy the binaries to distro/ruby_bin_folder.
84
77
  #
85
78
  # We copy (and overwrite) these files every time "bundle <exec|install>" is
86
79
  # executed, just in case they have changed.
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@chef.io>)
3
3
  # Author:: Daniel DeLeo (<dan@chef.io>)
4
- # Copyright:: Copyright 2008-2019, Chef Software Inc.
4
+ # Copyright:: Copyright, Chef Software Inc.
5
5
  # License:: Apache License, Version 2.0
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,7 +23,6 @@ $LOAD_PATH.unshift(File.expand_path("chef-config/lib", __dir__))
23
23
  begin
24
24
  require_relative "tasks/rspec"
25
25
  require_relative "tasks/dependencies"
26
- require_relative "tasks/announce"
27
26
  require_relative "tasks/docs"
28
27
  require_relative "tasks/spellcheck"
29
28
  require_relative "chef-utils/lib/chef-utils/dist" unless defined?(ChefUtils::Dist)
@@ -48,6 +47,7 @@ namespace :pre_install do
48
47
 
49
48
  desc "Renders the powershell extensions with distro flavoring"
50
49
  task :render_powershell_extension do
50
+ require "erb"
51
51
  template_file = ::File.join(::File.dirname(__FILE__), "distro", "templates", "powershell", "chef", "chef.psm1.erb")
52
52
  psm1_path = ::File.join(::File.dirname(__FILE__), "distro", "powershell", "chef")
53
53
  FileUtils.mkdir_p psm1_path
@@ -88,6 +88,25 @@ task :register_eventlog do
88
88
  end
89
89
  end
90
90
 
91
+ desc "Copies powershell_exec related binaries from the latest built Habitat Packages"
92
+ task :update_chef_exec_dll do
93
+ raise "This task must be run on Windows since we are installing a Windows targeted package!" unless Gem.win_platform?
94
+
95
+ require "mkmf"
96
+ raise "Unable to locate Habitat cli. Please install Habitat cli before invoking this task!" unless find_executable "hab"
97
+
98
+ sh("hab pkg install chef/chef-powershell-shim")
99
+ sh("hab pkg install chef/chef-powershell-shim-x86")
100
+ x64 = `hab pkg path chef/chef-powershell-shim`.chomp.gsub(/\\/, "/")
101
+ x86 = `hab pkg path chef/chef-powershell-shim-x86`.chomp.gsub(/\\/, "/")
102
+ FileUtils.rm_rf(Dir["distro/ruby_bin_folder/AMD64/*"])
103
+ FileUtils.rm_rf(Dir["distro/ruby_bin_folder/x86/*"])
104
+ puts "Copying #{x64}/bin/* to distro/ruby_bin_folder/AMD64"
105
+ FileUtils.cp_r(Dir["#{x64}/bin/*"], "distro/ruby_bin_folder/AMD64")
106
+ puts "Copying #{x86}/bin/* to distro/ruby_bin_folder/x86"
107
+ FileUtils.cp_r(Dir["#{x86}/bin/*"], "distro/ruby_bin_folder/x86")
108
+ end
109
+
91
110
  begin
92
111
  require "chefstyle"
93
112
  require "rubocop/rake_task"
@@ -97,15 +116,3 @@ begin
97
116
  rescue LoadError
98
117
  puts "chefstyle/rubocop is not available. bundle install first to make sure all dependencies are installed."
99
118
  end
100
-
101
- begin
102
- require "yard"
103
- DOC_FILES = [ "spec/tiny_server.rb", "lib/**/*.rb" ].freeze
104
-
105
- YARD::Rake::YardocTask.new(:docs) do |t|
106
- t.files = DOC_FILES
107
- t.options = ["--format", "html"]
108
- end
109
- rescue LoadError
110
- puts "yard is not available. bundle install first to make sure all dependencies are installed."
111
- end
@@ -9,7 +9,7 @@ gemspec.add_dependency "win32-event", "~> 0.6.1"
9
9
  gemspec.add_dependency "win32-eventlog", "0.6.3"
10
10
  gemspec.add_dependency "win32-mmap", "~> 0.4.1"
11
11
  gemspec.add_dependency "win32-mutex", "~> 0.4.2"
12
- gemspec.add_dependency "win32-process", "~> 0.8.2"
12
+ gemspec.add_dependency "win32-process", "~> 0.9"
13
13
  gemspec.add_dependency "win32-service", ">= 2.1.5", "< 3.0"
14
14
  gemspec.add_dependency "wmi-lite", "~> 1.0"
15
15
  gemspec.add_dependency "win32-taskscheduler", "~> 2.0"
@@ -20,7 +20,7 @@ require_relative "../application"
20
20
  require "mixlib/log"
21
21
  require "ohai/config"
22
22
  module Net
23
- autoload :HTTP, File.expand_path("../monkey_patches/net_http", __dir__)
23
+ autoload :HTTP, "net/http"
24
24
  end
25
25
  require "chef-utils/dist" unless defined?(ChefUtils::Dist)
26
26
 
@@ -24,7 +24,7 @@ class Chef
24
24
  end
25
25
 
26
26
  def preserve_key?(key)
27
- key == "cookbook_name" || key == "version"
27
+ %w{cookbook_name version}.include?(key)
28
28
  end
29
29
 
30
30
  def chef_class
@@ -204,7 +204,7 @@ class Chef
204
204
  end
205
205
 
206
206
  # Skip // and /./ (pretend it's not there)
207
- if exact == "" || exact == "."
207
+ if ["", "."].include?(exact)
208
208
  next
209
209
  end
210
210
 
@@ -243,12 +243,12 @@ class Chef
243
243
  run_status.run_context = run_context
244
244
 
245
245
  events.run_start(Chef::VERSION, run_status)
246
-
247
246
  logger.info("*** #{ChefUtils::Dist::Infra::PRODUCT} #{Chef::VERSION} ***")
248
247
  logger.info("Platform: #{RUBY_PLATFORM}")
249
248
  logger.info "#{ChefUtils::Dist::Infra::CLIENT.capitalize} pid: #{Process.pid}"
250
249
  logger.info "Targeting node: #{Chef::Config.target_mode.host}" if Chef::Config.target_mode?
251
250
  logger.debug("#{ChefUtils::Dist::Infra::CLIENT.capitalize} request_id: #{request_id}")
251
+ logger.warn("`enforce_path_sanity` is deprecated, please use `enforce_default_paths` instead!") if Chef::Config[:enforce_path_sanity]
252
252
  ENV["PATH"] = ChefUtils::DSL::DefaultPaths.default_paths if Chef::Config[:enforce_default_paths] || Chef::Config[:enforce_path_sanity]
253
253
 
254
254
  run_ohai
@@ -282,7 +282,7 @@ class Chef
282
282
 
283
283
  name = File.join(segment, pathname.basename.to_s)
284
284
 
285
- if segment == "templates" || segment == "files"
285
+ if %w{templates files}.include?(segment)
286
286
  # Check if pathname looks like files/foo or templates/foo (unscoped)
287
287
  if pathname.each_filename.to_a.length == 2
288
288
  # Use root_default in case the same path exists at root_default and default
@@ -20,7 +20,7 @@
20
20
 
21
21
  autoload :URI, "uri"
22
22
  module Net
23
- autoload :HTTP, File.expand_path("monkey_patches/net_http", __dir__)
23
+ autoload :HTTP, "net/http"
24
24
  end
25
25
  autoload :OpenSSL, "openssl"
26
26
  module Mixlib
@@ -264,7 +264,7 @@ class Chef
264
264
  if found_pref
265
265
  manifest_records_by_path[found_pref]
266
266
  else
267
- if segment == :files || segment == :templates
267
+ if %i{files templates}.include?(segment)
268
268
  error_message = "Cookbook '#{name}' (#{version}) does not contain a file at any of these locations:\n"
269
269
  error_locations = if filename.is_a?(Array)
270
270
  filename.map { |name| " #{File.join(segment.to_s, name)}" }
@@ -587,10 +587,7 @@ class Chef
587
587
  end
588
588
 
589
589
  def file_vendor
590
- unless @file_vendor
591
- @file_vendor = Chef::Cookbook::FileVendor.create_from_manifest(cookbook_manifest)
592
- end
593
- @file_vendor
590
+ @file_vendor ||= Chef::Cookbook::FileVendor.create_from_manifest(cookbook_manifest)
594
591
  end
595
592
 
596
593
  end
@@ -35,7 +35,7 @@ class Chef
35
35
  include Chef::Mixin::ParamsValidate
36
36
  include Chef::Mixin::FromFile
37
37
 
38
- COMBINED_COOKBOOK_CONSTRAINT = /(.+)(?:[\s]+)((?:#{Chef::VersionConstraint::OPS.join('|')})(?:[\s]+).+)$/.freeze
38
+ COMBINED_COOKBOOK_CONSTRAINT = /(.+)(?:\s+)((?:#{Chef::VersionConstraint::OPS.join('|')})(?:\s+).+)$/.freeze
39
39
 
40
40
  def initialize(chef_server_rest: nil)
41
41
  @name = ""
@@ -451,7 +451,7 @@ class Chef
451
451
  attr_reader :wrapped_errors
452
452
 
453
453
  def initialize(*errors)
454
- errors = errors.select { |e| !e.nil? }
454
+ errors = errors.compact
455
455
  output = "Found #{errors.size} errors, they are stored in the backtrace"
456
456
  @wrapped_errors = errors
457
457
  super output
@@ -255,10 +255,7 @@ class Chef
255
255
  flags |= CONTAINER_INHERIT_ACE
256
256
  when :objects_only
257
257
  flags |= OBJECT_INHERIT_ACE
258
- when true
259
- flags |= CONTAINER_INHERIT_ACE
260
- flags |= OBJECT_INHERIT_ACE
261
- when nil
258
+ when true, nil
262
259
  flags |= CONTAINER_INHERIT_ACE
263
260
  flags |= OBJECT_INHERIT_ACE
264
261
  end
@@ -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
@@ -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,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