chef 15.11.8-universal-mingw32 → 15.16.2-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +12 -13
  3. data/README.md +3 -3
  4. data/Rakefile +11 -17
  5. data/chef-universal-mingw32.gemspec +4 -4
  6. data/chef.gemspec +25 -7
  7. data/distro/powershell/chef/chef.psm1 +3 -3
  8. data/distro/templates/powershell/chef/chef.psm1.erb +3 -3
  9. data/lib/chef/api_client/registration.rb +2 -2
  10. data/lib/chef/application/apply.rb +1 -1
  11. data/lib/chef/chef_fs/file_system/repository/base_file.rb +1 -0
  12. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb +2 -2
  13. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +1 -1
  14. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +2 -2
  15. data/lib/chef/chef_fs/file_system/repository/directory.rb +1 -1
  16. data/lib/chef/chef_fs/file_system/repository/file_system_entry.rb +1 -1
  17. data/lib/chef/chef_fs/path_utils.rb +3 -3
  18. data/lib/chef/cookbook/file_system_file_vendor.rb +1 -1
  19. data/lib/chef/data_bag.rb +2 -2
  20. data/lib/chef/data_collector/error_handlers.rb +1 -1
  21. data/lib/chef/deprecated.rb +12 -0
  22. data/lib/chef/dsl/declare_resource.rb +1 -1
  23. data/lib/chef/dsl/platform_introspection.rb +2 -0
  24. data/lib/chef/environment.rb +2 -2
  25. data/lib/chef/exceptions.rb +3 -0
  26. data/lib/chef/http.rb +2 -1
  27. data/lib/chef/knife/bootstrap.rb +6 -9
  28. data/lib/chef/knife/bootstrap/templates/chef-full.erb +9 -9
  29. data/lib/chef/knife/bootstrap/train_connector.rb +1 -0
  30. data/lib/chef/knife/cookbook_download.rb +1 -1
  31. data/lib/chef/knife/cookbook_metadata.rb +1 -1
  32. data/lib/chef/knife/core/gem_glob_loader.rb +1 -1
  33. data/lib/chef/knife/core/hashed_command_loader.rb +3 -2
  34. data/lib/chef/knife/core/subcommand_loader.rb +1 -1
  35. data/lib/chef/knife/exec.rb +2 -2
  36. data/lib/chef/knife/ssh.rb +20 -1
  37. data/lib/chef/log.rb +1 -1
  38. data/lib/chef/mixin/openssl_helper.rb +26 -3
  39. data/lib/chef/mixin/template.rb +1 -0
  40. data/lib/chef/node_map.rb +5 -2
  41. data/lib/chef/provider/mount/solaris.rb +0 -1
  42. data/lib/chef/provider/package/cab.rb +1 -1
  43. data/lib/chef/provider/package/chocolatey.rb +1 -1
  44. data/lib/chef/provider/package/dnf/dnf_helper.py +5 -0
  45. data/lib/chef/provider/package/freebsd/pkgng.rb +3 -1
  46. data/lib/chef/provider/package/msu.rb +1 -0
  47. data/lib/chef/provider/package/powershell.rb +5 -1
  48. data/lib/chef/provider/package/snap.rb +96 -27
  49. data/lib/chef/provider/package/yum/yum_helper.py +4 -0
  50. data/lib/chef/provider/package/zypper.rb +0 -1
  51. data/lib/chef/provider/service/arch.rb +2 -2
  52. data/lib/chef/provider/service/debian.rb +1 -1
  53. data/lib/chef/provider/service/gentoo.rb +2 -2
  54. data/lib/chef/provider/service/macosx.rb +2 -2
  55. data/lib/chef/provider/service/openbsd.rb +1 -1
  56. data/lib/chef/provider/service/redhat.rb +2 -2
  57. data/lib/chef/provider/service/upstart.rb +1 -1
  58. data/lib/chef/provider/yum_repository.rb +1 -1
  59. data/lib/chef/provider/zypper_repository.rb +31 -11
  60. data/lib/chef/resource.rb +2 -0
  61. data/lib/chef/resource/archive_file.rb +28 -8
  62. data/lib/chef/resource/cron_access.rb +13 -5
  63. data/lib/chef/resource/cron_d.rb +2 -1
  64. data/lib/chef/resource/homebrew_cask.rb +3 -3
  65. data/lib/chef/resource/hostname.rb +19 -18
  66. data/lib/chef/resource/locale.rb +1 -1
  67. data/lib/chef/resource/lwrp_base.rb +7 -0
  68. data/lib/chef/resource/msu_package.rb +5 -0
  69. data/lib/chef/resource/ssh_known_hosts_entry.rb +1 -1
  70. data/lib/chef/resource/sudo.rb +2 -2
  71. data/lib/chef/resource/windows_feature_powershell.rb +6 -2
  72. data/lib/chef/resource/windows_font.rb +2 -1
  73. data/lib/chef/role.rb +2 -2
  74. data/lib/chef/shell.rb +32 -1
  75. data/lib/chef/shell/shell_session.rb +2 -0
  76. data/lib/chef/util/diff.rb +1 -1
  77. data/lib/chef/util/dsc/configuration_generator.rb +1 -1
  78. data/lib/chef/util/powershell/cmdlet.rb +1 -1
  79. data/lib/chef/version.rb +2 -2
  80. data/lib/chef/version_string.rb +1 -1
  81. data/lib/chef/win32/file.rb +2 -2
  82. data/spec/functional/knife/ssh_spec.rb +4 -4
  83. data/spec/functional/resource/aix_service_spec.rb +0 -1
  84. data/spec/functional/resource/aixinit_service_spec.rb +7 -8
  85. data/spec/functional/resource/apt_package_spec.rb +0 -1
  86. data/spec/functional/resource/bff_spec.rb +2 -2
  87. data/spec/functional/resource/cookbook_file_spec.rb +1 -1
  88. data/spec/functional/resource/cron_spec.rb +0 -1
  89. data/spec/functional/resource/dsc_resource_spec.rb +1 -1
  90. data/spec/functional/resource/insserv_spec.rb +4 -5
  91. data/spec/functional/resource/link_spec.rb +17 -17
  92. data/spec/functional/resource/msu_package_spec.rb +5 -2
  93. data/spec/functional/resource/rpm_spec.rb +2 -2
  94. data/spec/functional/resource/user/dscl_spec.rb +1 -1
  95. data/spec/functional/resource/user/mac_user_spec.rb +1 -1
  96. data/spec/functional/resource/windows_certificate_spec.rb +3 -3
  97. data/spec/functional/resource/windows_font_spec.rb +49 -0
  98. data/spec/functional/resource/windows_task_spec.rb +8 -8
  99. data/spec/functional/run_lock_spec.rb +2 -1
  100. data/spec/functional/shell_spec.rb +5 -5
  101. data/spec/functional/util/powershell/cmdlet_spec.rb +1 -1
  102. data/spec/functional/version_spec.rb +1 -1
  103. data/spec/functional/win32/service_manager_spec.rb +1 -1
  104. data/spec/integration/recipes/accumulator_spec.rb +1 -1
  105. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +2 -2
  106. data/spec/integration/recipes/lwrp_spec.rb +1 -1
  107. data/spec/integration/recipes/notifies_spec.rb +1 -1
  108. data/spec/integration/recipes/notifying_block_spec.rb +1 -1
  109. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  110. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +2 -0
  111. data/spec/integration/recipes/resource_load_spec.rb +1 -0
  112. data/spec/integration/recipes/unified_mode_spec.rb +1 -1
  113. data/spec/scripts/ssl-serve.rb +1 -1
  114. data/spec/spec_helper.rb +10 -8
  115. data/spec/support/platform_helpers.rb +12 -42
  116. data/spec/support/platforms/win32/spec_service.rb +1 -1
  117. data/spec/support/shared/functional/directory_resource.rb +1 -1
  118. data/spec/support/shared/functional/execute_resource.rb +1 -1
  119. data/spec/support/shared/functional/file_resource.rb +2 -2
  120. data/spec/support/shared/functional/win32_service.rb +1 -1
  121. data/spec/support/shared/functional/windows_script.rb +3 -3
  122. data/spec/support/shared/integration/knife_support.rb +2 -5
  123. data/spec/unit/application_spec.rb +7 -0
  124. data/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb +2 -4
  125. data/spec/unit/cookbook/gem_installer_spec.rb +2 -1
  126. data/spec/unit/data_bag_spec.rb +1 -1
  127. data/spec/unit/dsl/platform_introspection_spec.rb +1 -0
  128. data/spec/unit/environment_spec.rb +7 -7
  129. data/spec/unit/event_dispatch/dispatcher_spec.rb +3 -0
  130. data/spec/unit/knife/bootstrap_spec.rb +16 -16
  131. data/spec/unit/knife/cookbook_download_spec.rb +4 -4
  132. data/spec/unit/knife/cookbook_metadata_from_file_spec.rb +1 -1
  133. data/spec/unit/knife/cookbook_upload_spec.rb +5 -6
  134. data/spec/unit/knife/core/hashed_command_loader_spec.rb +3 -3
  135. data/spec/unit/knife/ssh_spec.rb +2 -2
  136. data/spec/unit/knife/supermarket_share_spec.rb +5 -3
  137. data/spec/unit/lwrp_spec.rb +4 -4
  138. data/spec/unit/mixin/securable_spec.rb +0 -1
  139. data/spec/unit/mixin/user_context_spec.rb +1 -9
  140. data/spec/unit/property_spec.rb +6 -6
  141. data/spec/unit/provider/package/dnf/python_helper_spec.rb +1 -1
  142. data/spec/unit/provider/package/freebsd/pkgng_spec.rb +1 -1
  143. data/spec/unit/provider/package/powershell_spec.rb +95 -86
  144. data/spec/unit/provider/package/rubygems_spec.rb +5 -10
  145. data/spec/unit/provider/package/snap_spec.rb +1 -1
  146. data/spec/unit/provider/package/windows_spec.rb +30 -53
  147. data/spec/unit/provider/service/arch_service_spec.rb +3 -2
  148. data/spec/unit/provider/service/debian_service_spec.rb +1 -1
  149. data/spec/unit/provider/service/gentoo_service_spec.rb +7 -7
  150. data/spec/unit/provider/service/macosx_spec.rb +3 -3
  151. data/spec/unit/provider/service/redhat_spec.rb +2 -2
  152. data/spec/unit/provider/service/upstart_service_spec.rb +3 -3
  153. data/spec/unit/provider/service/windows_spec.rb +2 -6
  154. data/spec/unit/provider/systemd_unit_spec.rb +28 -24
  155. data/spec/unit/provider/zypper_repository_spec.rb +75 -25
  156. data/spec/unit/provider_spec.rb +1 -0
  157. data/spec/unit/resource/archive_file_spec.rb +11 -2
  158. data/spec/unit/resource/msu_package_spec.rb +4 -0
  159. data/spec/unit/resource/windows_dns_record_spec.rb +3 -3
  160. data/spec/unit/resource/windows_dns_zone_spec.rb +2 -2
  161. data/spec/unit/resource/windows_feature_powershell_spec.rb +30 -4
  162. data/spec/unit/resource/windows_package_spec.rb +1 -0
  163. data/spec/unit/resource/windows_task_spec.rb +1 -1
  164. data/spec/unit/resource/windows_uac_spec.rb +2 -2
  165. data/spec/unit/resource/yum_repository_spec.rb +21 -21
  166. data/spec/unit/resource_spec.rb +1 -1
  167. data/spec/unit/role_spec.rb +11 -11
  168. data/spec/unit/run_context/cookbook_compiler_spec.rb +1 -1
  169. data/spec/unit/util/threaded_job_queue_spec.rb +9 -0
  170. data/spec/unit/win32/security_spec.rb +4 -3
  171. metadata +64 -39
@@ -18,7 +18,7 @@
18
18
  class Chef
19
19
  class DataCollector
20
20
 
21
- # This module isolates the handling of collecting error descriptions to insert into the data_colletor
21
+ # This module isolates the handling of collecting error descriptions to insert into the data_collector
22
22
  # report output. For very early errors it is responsible for collecting the node_name for the report
23
23
  # to use. For all failure conditions that have an ErrorMapper it collects the output.
24
24
  #
@@ -233,6 +233,18 @@ class Chef
233
233
  target 28
234
234
  end
235
235
 
236
+ class KnifeBootstrapApis < Base
237
+ target 29
238
+ end
239
+
240
+ class ArchiveFileIntegerFileMode < Base
241
+ target 30
242
+ end
243
+
244
+ class ResourceNameWithoutProvides < Base
245
+ target 31
246
+ end
247
+
236
248
  class Generic < Base
237
249
  def url
238
250
  "https://docs.chef.io/chef_deprecations_client/"
@@ -151,7 +151,7 @@ class Chef
151
151
  # source "y.txt.erb"
152
152
  # variables {}
153
153
  # end
154
- # resource.variables.merge!({ home: "/home/klowns" })
154
+ # resource.variables.merge!({ home: "/home/clowns" })
155
155
  #
156
156
  def edit_resource(type, name, created_at: nil, run_context: self.run_context, &resource_attrs_block)
157
157
  edit_resource!(type, name, created_at: created_at, run_context: run_context, &resource_attrs_block)
@@ -248,6 +248,8 @@ class Chef
248
248
  end
249
249
 
250
250
  # a simple helper to determine if we're on a windows release pre-2012 / 8
251
+ #
252
+ # @deprecated Windows releases before Windows 2012 and 8 are no longer supported
251
253
  # @return [Boolean] Is the system older than Windows 8 / 2012
252
254
  def older_than_win_2012_or_8?(node = run_context.nil? ? nil : run_context.node)
253
255
  node["platform_version"].to_f < 6.2
@@ -255,11 +255,11 @@ class Chef
255
255
  js_file = File.join(Chef::Config[:environment_path], "#{name}.json")
256
256
  rb_file = File.join(Chef::Config[:environment_path], "#{name}.rb")
257
257
 
258
- if File.exists?(js_file)
258
+ if File.exist?(js_file)
259
259
  # from_json returns object.class => json_class in the JSON.
260
260
  hash = Chef::JSONCompat.parse(IO.read(js_file))
261
261
  from_hash(hash)
262
- elsif File.exists?(rb_file)
262
+ elsif File.exist?(rb_file)
263
263
  environment = Chef::Environment.new
264
264
  environment.name(name)
265
265
  environment.from_file(rb_file)
@@ -198,6 +198,7 @@ class Chef
198
198
  class MetadataNotFound < StandardError
199
199
  attr_reader :install_path
200
200
  attr_reader :cookbook_name
201
+
201
202
  def initialize(install_path, cookbook_name)
202
203
  @install_path = install_path
203
204
  @cookbook_name = cookbook_name
@@ -448,6 +449,7 @@ class Chef
448
449
  # to correctly populate the backtrace with the wrapped backtraces.
449
450
  class RunFailedWrappingError < RuntimeError
450
451
  attr_reader :wrapped_errors
452
+
451
453
  def initialize(*errors)
452
454
  errors = errors.select { |e| !e.nil? }
453
455
  output = "Found #{errors.size} errors, they are stored in the backtrace"
@@ -488,6 +490,7 @@ class Chef
488
490
 
489
491
  class MultipleDscResourcesFound < RuntimeError
490
492
  attr_reader :resources_found
493
+
491
494
  def initialize(resources_found)
492
495
  @resources_found = resources_found
493
496
  matches_info = @resources_found.each do |r|
data/lib/chef/http.rb CHANGED
@@ -22,7 +22,8 @@
22
22
  #
23
23
 
24
24
  require "tempfile" unless defined?(Tempfile)
25
- require "net/https"
25
+ require "openssl" unless defined?(OpenSSL)
26
+ require "net/http" unless defined?(Net::HTTP)
26
27
  require "uri" unless defined?(URI)
27
28
  require_relative "http/basic_client"
28
29
  require_relative "monkey_patches/net_http"
@@ -497,7 +497,7 @@ class Chef
497
497
  template = bootstrap_template
498
498
 
499
499
  # Use the template directly if it's a path to an actual file
500
- if File.exists?(template)
500
+ if File.exist?(template)
501
501
  Chef::Log.trace("Using the specified bootstrap template: #{File.dirname(template)}")
502
502
  return template
503
503
  end
@@ -512,7 +512,7 @@ class Chef
512
512
 
513
513
  template_file = Array(bootstrap_files).find do |bootstrap_template|
514
514
  Chef::Log.trace("Looking for bootstrap template in #{File.dirname(bootstrap_template)}")
515
- File.exists?(bootstrap_template)
515
+ File.exist?(bootstrap_template)
516
516
  end
517
517
 
518
518
  unless template_file
@@ -555,7 +555,7 @@ class Chef
555
555
  end
556
556
 
557
557
  def run
558
- check_license
558
+ check_license if ChefConfig::Dist::ENFORCE_LICENSE
559
559
 
560
560
  plugin_setup!
561
561
  validate_name_args!
@@ -597,11 +597,8 @@ class Chef
597
597
 
598
598
  bootstrap_context.client_pem = client_builder.client_path
599
599
  else
600
- ui.info <<~EOM
601
- Performing legacy client registration with the validation key at #{Chef::Config[:validation_key]}...
602
- Delete your validation key in order to use your user credentials for client registration instead.
603
- EOM
604
-
600
+ ui.warn "Performing legacy client registration with the validation key at #{Chef::Config[:validation_key]}..."
601
+ ui.warn "Remove the key file or remove the 'validation_key' configuration option from your config.rb (knife.rb) to use more secure user credentials for client registration."
605
602
  end
606
603
  end
607
604
 
@@ -619,7 +616,7 @@ class Chef
619
616
  end
620
617
 
621
618
  def connect!
622
- ui.info("Connecting to #{ui.color(server_name, :bold)}")
619
+ ui.info("Connecting to #{ui.color(server_name, :bold)} using #{connection_protocol}")
623
620
  opts ||= connection_opts.dup
624
621
  do_connect(opts)
625
622
  rescue Train::Error => e
@@ -185,50 +185,50 @@ if test "x$tmp_dir" != "x"; then
185
185
  rm -r "$tmp_dir"
186
186
  fi
187
187
 
188
- mkdir -p <%= ChefConfig::Config.etc_chef_dir(false) %>
188
+ mkdir -p /etc/chef
189
189
 
190
190
  <% if client_pem -%>
191
- (umask 077 && (cat > <%= ChefConfig::Config.etc_chef_dir(false) %>/client.pem <<'EOP'
191
+ (umask 077 && (cat > /etc/chef/client.pem <<'EOP'
192
192
  <%= ::File.read(::File.expand_path(client_pem)) %>
193
193
  EOP
194
194
  )) || exit 1
195
195
  <% end -%>
196
196
 
197
197
  <% if validation_key -%>
198
- (umask 077 && (cat > <%= ChefConfig::Config.etc_chef_dir(false) %>/validation.pem <<'EOP'
198
+ (umask 077 && (cat > /etc/chef/validation.pem <<'EOP'
199
199
  <%= validation_key %>
200
200
  EOP
201
201
  )) || exit 1
202
202
  <% end -%>
203
203
 
204
204
  <% if encrypted_data_bag_secret -%>
205
- (umask 077 && (cat > <%= ChefConfig::Config.etc_chef_dir(false) %>/encrypted_data_bag_secret <<'EOP'
205
+ (umask 077 && (cat > /etc/chef/encrypted_data_bag_secret <<'EOP'
206
206
  <%= encrypted_data_bag_secret %>
207
207
  EOP
208
208
  )) || exit 1
209
209
  <% end -%>
210
210
 
211
211
  <% unless trusted_certs.empty? -%>
212
- mkdir -p <%= ChefConfig::Config.etc_chef_dir(false) %>/trusted_certs
212
+ mkdir -p /etc/chef/trusted_certs
213
213
  <%= trusted_certs %>
214
214
  <% end -%>
215
215
 
216
216
  <%# Generate Ohai Hints -%>
217
217
  <% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
218
- mkdir -p <%= ChefConfig::Config.etc_chef_dir(false) %>/ohai/hints
218
+ mkdir -p /etc/chef/ohai/hints
219
219
 
220
220
  <% @chef_config[:knife][:hints].each do |name, hash| -%>
221
- cat > <%= ChefConfig::Config.etc_chef_dir(false) %>/ohai/hints/<%= name %>.json <<'EOP'
221
+ cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP'
222
222
  <%= Chef::JSONCompat.to_json(hash) %>
223
223
  EOP
224
224
  <% end -%>
225
225
  <% end -%>
226
226
 
227
- cat > <%= ChefConfig::Config.etc_chef_dir(false) %>/client.rb <<'EOP'
227
+ cat > /etc/chef/client.rb <<'EOP'
228
228
  <%= config_content %>
229
229
  EOP
230
230
 
231
- cat > <%= ChefConfig::Config.etc_chef_dir(false) %>/first-boot.json <<'EOP'
231
+ cat > /etc/chef/first-boot.json <<'EOP'
232
232
  <%= Chef::JSONCompat.to_json(first_boot) %>
233
233
  EOP
234
234
 
@@ -322,6 +322,7 @@ class Chef
322
322
 
323
323
  class RemoteExecutionFailed < StandardError
324
324
  attr_reader :exit_status, :command, :hostname, :stdout, :stderr
325
+
325
326
  def initialize(hostname, command, result)
326
327
  @hostname = hostname
327
328
  @exit_status = result.exit_status
@@ -73,7 +73,7 @@ class Chef
73
73
  manifest = cookbook.cookbook_manifest
74
74
 
75
75
  basedir = File.join(config[:download_directory], "#{@cookbook_name}-#{cookbook.version}")
76
- if File.exists?(basedir)
76
+ if File.exist?(basedir)
77
77
  if config[:force]
78
78
  Chef::Log.trace("Deleting #{basedir}")
79
79
  FileUtils.rm_rf(basedir)
@@ -62,7 +62,7 @@ class Chef
62
62
  def generate_metadata(cookbook)
63
63
  Array(config[:cookbook_path]).reverse_each do |path|
64
64
  file = File.expand_path(File.join(path, cookbook, "metadata.rb"))
65
- if File.exists?(file)
65
+ if File.exist?(file)
66
66
  generate_metadata_from_file(cookbook, file)
67
67
  else
68
68
  validate_metadata_json(path, cookbook)
@@ -47,7 +47,7 @@ class Chef
47
47
 
48
48
  def find_subcommands_via_dirglob
49
49
  # The "require paths" of the core knife subcommands bundled with chef
50
- files = Dir[File.join(Chef::Util::PathHelper.escape_glob_dir(File.expand_path("../../../knife", __FILE__)), "*.rb")]
50
+ files = Dir[File.join(Chef::Util::PathHelper.escape_glob_dir(File.expand_path("../../knife", __dir__)), "*.rb")]
51
51
  subcommand_files = {}
52
52
  files.each do |knife_file|
53
53
  rel_path = knife_file[/#{CHEF_ROOT}#{Regexp.escape(File::SEPARATOR)}(.*)\.rb/, 1]
@@ -27,6 +27,7 @@ class Chef
27
27
  KEY = "_autogenerated_command_paths".freeze
28
28
 
29
29
  attr_accessor :manifest
30
+
30
31
  def initialize(chef_config_dir, plugin_manifest)
31
32
  super(chef_config_dir)
32
33
  @manifest = plugin_manifest
@@ -52,7 +53,7 @@ class Chef
52
53
  paths = manifest[KEY]["plugins_paths"][command]
53
54
  if paths && paths.is_a?(Array)
54
55
  # It is only an error if all the paths don't exist
55
- if paths.all? { |sc| !File.exists?(sc) }
56
+ if paths.all? { |sc| !File.exist?(sc) }
56
57
  errors[command] = paths
57
58
  end
58
59
  end
@@ -76,7 +77,7 @@ class Chef
76
77
  false
77
78
  else
78
79
  paths.each do |sc|
79
- if File.exists?(sc)
80
+ if File.exist?(sc)
80
81
  Kernel.load sc
81
82
  else
82
83
  return false
@@ -125,7 +125,7 @@ class Chef
125
125
  #
126
126
  def find_subcommands_via_dirglob
127
127
  # The "require paths" of the core knife subcommands bundled with chef
128
- files = Dir[File.join(Chef::Util::PathHelper.escape_glob_dir(File.expand_path("../../../knife", __FILE__)), "*.rb")]
128
+ files = Dir[File.join(Chef::Util::PathHelper.escape_glob_dir(File.expand_path("../../knife", __dir__)), "*.rb")]
129
129
  subcommand_files = {}
130
130
  files.each do |knife_file|
131
131
  rel_path = knife_file[/#{CHEF_ROOT}#{Regexp.escape(File::SEPARATOR)}(.*)\.rb/, 1]
@@ -76,7 +76,7 @@ class Chef::Knife::Exec < Chef::Knife
76
76
  def find_script(x)
77
77
  # Try to find a script. First try expanding the path given.
78
78
  script = File.expand_path(x)
79
- return script if File.exists?(script)
79
+ return script if File.exist?(script)
80
80
 
81
81
  # Failing that, try searching the script path. If we can't find
82
82
  # anything, fail gracefully.
@@ -86,7 +86,7 @@ class Chef::Knife::Exec < Chef::Knife
86
86
  path = File.expand_path(path)
87
87
  test = File.join(path, x)
88
88
  Chef::Log.trace("Testing: #{test}")
89
- if File.exists?(test)
89
+ if File.exist?(test)
90
90
  script = test
91
91
  Chef::Log.trace("Found: #{test}")
92
92
  return script
@@ -298,6 +298,10 @@ class Chef
298
298
  opts[:keepalive] = true
299
299
  opts[:keepalive_interval] = ssh_config[:keepalive_interval]
300
300
  end
301
+ # maintain support for legacy key types / ciphers / key exchange algorithms.
302
+ # most importantly this adds back support for DSS host keys
303
+ # See https://github.com/net-ssh/net-ssh/pull/709
304
+ opts[:append_all_supported_algorithms] = true
301
305
  end
302
306
  end
303
307
 
@@ -358,11 +362,21 @@ class Chef
358
362
  subsession ||= session
359
363
  command = fixup_sudo(command)
360
364
  command.force_encoding("binary") if command.respond_to?(:force_encoding)
365
+ begin
366
+ open_session(subsession, command)
367
+ rescue => e
368
+ open_session(subsession, command, true)
369
+ end
370
+ end
371
+
372
+ def open_session(subsession, command, pty = false)
373
+ stderr = ""
374
+ exit_status = 0
361
375
  subsession.open_channel do |chan|
362
376
  if config[:on_error] && exit_status != 0
363
377
  chan.close
364
378
  else
365
- chan.request_pty
379
+ chan.request_pty if pty
366
380
  chan.exec command do |ch, success|
367
381
  raise ArgumentError, "Cannot execute #{command}" unless success
368
382
 
@@ -373,6 +387,11 @@ class Chef
373
387
  ichannel.send_data("#{get_password}\n")
374
388
  end
375
389
  end
390
+
391
+ ch.on_extended_data do |_, _type, data|
392
+ stderr += data
393
+ end
394
+
376
395
  ch.on_request "exit-status" do |ichannel, data|
377
396
  exit_status = [exit_status, data.read_long].max
378
397
  end
data/lib/chef/log.rb CHANGED
@@ -47,7 +47,7 @@ class Chef
47
47
  def self.caller_location
48
48
  # Pick the first caller that is *not* part of the Chef gem, that's the
49
49
  # thing the user wrote. Or failing that, the most recent caller.
50
- chef_gem_path = File.expand_path("../..", __FILE__)
50
+ chef_gem_path = File.expand_path("..", __dir__)
51
51
  caller(0..20).find { |c| !c.start_with?(chef_gem_path) } || caller(0..1)[0]
52
52
  end
53
53
 
@@ -282,7 +282,9 @@ class Chef
282
282
  ef.issuer_certificate = info["issuer"]
283
283
  end
284
284
  ef.subject_certificate = cert
285
- ef.config = ::OpenSSL::Config.load(::OpenSSL::Config::DEFAULT_CONFIG_FILE)
285
+ if openssl_config = __openssl_config
286
+ ef.config = openssl_config
287
+ end
286
288
 
287
289
  cert.extensions = extension
288
290
  cert.add_extension ef.create_extension("subjectKeyIdentifier", "hash")
@@ -313,7 +315,9 @@ class Chef
313
315
  crl.last_update = Time.now
314
316
  crl.next_update = Time.now + 3600 * 24 * info["validity"]
315
317
 
316
- ef.config = ::OpenSSL::Config.load(::OpenSSL::Config::DEFAULT_CONFIG_FILE)
318
+ if openssl_config = __openssl_config
319
+ ef.config = openssl_config
320
+ end
317
321
  ef.issuer_certificate = info["issuer"]
318
322
 
319
323
  crl.add_extension ::OpenSSL::X509::Extension.new("crlNumber", ::OpenSSL::ASN1::Integer(1))
@@ -391,7 +395,9 @@ class Chef
391
395
  crl.next_update = crl.last_update + 3600 * 24 * info["validity"]
392
396
 
393
397
  ef = ::OpenSSL::X509::ExtensionFactory.new
394
- ef.config = ::OpenSSL::Config.load(::OpenSSL::Config::DEFAULT_CONFIG_FILE)
398
+ if openssl_config = __openssl_config
399
+ ef.config = openssl_config
400
+ end
395
401
  ef.issuer_certificate = info["issuer"]
396
402
 
397
403
  crl.extensions = [ ::OpenSSL::X509::Extension.new("crlNumber",
@@ -422,6 +428,23 @@ class Chef
422
428
 
423
429
  resp
424
430
  end
431
+
432
+ private
433
+
434
+ def __openssl_config
435
+ path = if File.exist?(::OpenSSL::Config::DEFAULT_CONFIG_FILE)
436
+ OpenSSL::Config::DEFAULT_CONFIG_FILE
437
+ else
438
+ Dir[File.join(RbConfig::CONFIG["prefix"], "**", "openssl.cnf")].first
439
+ end
440
+
441
+ if File.exist?(path)
442
+ ::OpenSSL::Config.load(path)
443
+ else
444
+ Chef::Log.warn("Couldn't find OpenSSL config file")
445
+ nil
446
+ end
447
+ end
425
448
  end
426
449
  end
427
450
  end
@@ -213,6 +213,7 @@ class Chef
213
213
 
214
214
  class TemplateError < RuntimeError
215
215
  attr_reader :original_exception, :context, :options
216
+
216
217
  SOURCE_CONTEXT_WINDOW = 2
217
218
 
218
219
  def initialize(original_exception, template, context, options)
data/lib/chef/node_map.rb CHANGED
@@ -35,10 +35,13 @@
35
35
  #
36
36
  # XXX: confusingly, in the *_priority_map the :klass may be an array of Strings of class names
37
37
  #
38
+
39
+ require_relative "dist"
40
+
38
41
  class Chef
39
42
  class NodeMap
40
43
  COLLISION_WARNING = <<~EOH.gsub(/\s+/, " ").strip
41
- %{type_caps} %{key} from the client is overriding the %{type} from a cookbook. Please upgrade your cookbook
44
+ %{type_caps} %{key} built into %{client_name} is being overridden by the %{type} from a cookbook. Please upgrade your cookbook
42
45
  or remove the cookbook from your run_list.
43
46
  EOH
44
47
 
@@ -84,7 +87,7 @@ class Chef
84
87
  else
85
88
  klass.superclass.to_s
86
89
  end
87
- Chef::Log.warn( COLLISION_WARNING % { type: type_of_thing, key: key, type_caps: type_of_thing.capitalize } )
90
+ Chef::Log.warn( COLLISION_WARNING % { type: type_of_thing, key: key, type_caps: type_of_thing.capitalize, client_name: Chef::Dist::PRODUCT } )
88
91
  end
89
92
 
90
93
  # The map is sorted in order of preference already; we just need to find