chef 15.10.12 → 15.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +10 -10
  3. data/README.md +3 -3
  4. data/Rakefile +1 -1
  5. data/chef-universal-mingw32.gemspec +2 -2
  6. data/chef.gemspec +3 -3
  7. data/lib/chef/api_client/registration.rb +2 -2
  8. data/lib/chef/application/apply.rb +2 -2
  9. data/lib/chef/application/exit_code.rb +2 -2
  10. data/lib/chef/chef_fs/chef_fs_data_store.rb +3 -3
  11. data/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb +1 -1
  12. data/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb +1 -1
  13. data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +1 -1
  14. data/lib/chef/chef_fs/file_system/repository/base_file.rb +1 -0
  15. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb +2 -2
  16. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +1 -1
  17. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +2 -2
  18. data/lib/chef/chef_fs/file_system/repository/directory.rb +1 -1
  19. data/lib/chef/chef_fs/file_system/repository/file_system_entry.rb +1 -1
  20. data/lib/chef/chef_fs/path_utils.rb +3 -3
  21. data/lib/chef/cookbook/file_system_file_vendor.rb +1 -1
  22. data/lib/chef/cookbook_version.rb +4 -4
  23. data/lib/chef/data_bag.rb +2 -2
  24. data/lib/chef/data_collector/error_handlers.rb +1 -1
  25. data/lib/chef/deprecated.rb +13 -1
  26. data/lib/chef/dsl/declare_resource.rb +1 -1
  27. data/lib/chef/dsl/platform_introspection.rb +3 -1
  28. data/lib/chef/environment.rb +2 -2
  29. data/lib/chef/exceptions.rb +3 -0
  30. data/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb +2 -2
  31. data/lib/chef/formatters/error_inspectors/registration_error_inspector.rb +7 -7
  32. data/lib/chef/http.rb +2 -1
  33. data/lib/chef/knife.rb +26 -20
  34. data/lib/chef/knife/bootstrap.rb +30 -31
  35. data/lib/chef/knife/bootstrap/chef_vault_handler.rb +12 -8
  36. data/lib/chef/knife/bootstrap/client_builder.rb +23 -19
  37. data/lib/chef/knife/bootstrap/templates/chef-full.erb +9 -9
  38. data/lib/chef/knife/bootstrap/templates/windows-chef-client-msi.erb +3 -1
  39. data/lib/chef/knife/bootstrap/train_connector.rb +1 -0
  40. data/lib/chef/knife/cookbook_download.rb +1 -1
  41. data/lib/chef/knife/cookbook_metadata.rb +1 -1
  42. data/lib/chef/knife/cookbook_site_search.rb +1 -1
  43. data/lib/chef/knife/cookbook_site_show.rb +1 -1
  44. data/lib/chef/knife/cookbook_site_unshare.rb +1 -1
  45. data/lib/chef/knife/core/gem_glob_loader.rb +1 -1
  46. data/lib/chef/knife/core/hashed_command_loader.rb +3 -2
  47. data/lib/chef/knife/core/subcommand_loader.rb +1 -1
  48. data/lib/chef/knife/core/windows_bootstrap_context.rb +18 -3
  49. data/lib/chef/knife/exec.rb +2 -2
  50. data/lib/chef/knife/ssh.rb +21 -2
  51. data/lib/chef/log.rb +1 -1
  52. data/lib/chef/mixin/create_path.rb +8 -8
  53. data/lib/chef/mixin/openssl_helper.rb +26 -3
  54. data/lib/chef/mixin/template.rb +1 -0
  55. data/lib/chef/node/mixin/deep_merge_cache.rb +7 -7
  56. data/lib/chef/node_map.rb +5 -2
  57. data/lib/chef/provider/mount/solaris.rb +0 -1
  58. data/lib/chef/provider/package/cab.rb +1 -1
  59. data/lib/chef/provider/package/chocolatey.rb +4 -3
  60. data/lib/chef/provider/package/msu.rb +1 -0
  61. data/lib/chef/provider/package/powershell.rb +5 -1
  62. data/lib/chef/provider/package/snap.rb +96 -27
  63. data/lib/chef/provider/package/zypper.rb +0 -1
  64. data/lib/chef/provider/service/arch.rb +2 -2
  65. data/lib/chef/provider/service/debian.rb +1 -1
  66. data/lib/chef/provider/service/gentoo.rb +2 -2
  67. data/lib/chef/provider/service/macosx.rb +2 -2
  68. data/lib/chef/provider/service/openbsd.rb +1 -1
  69. data/lib/chef/provider/service/redhat.rb +2 -2
  70. data/lib/chef/provider/service/simple.rb +3 -3
  71. data/lib/chef/provider/service/upstart.rb +1 -1
  72. data/lib/chef/provider/windows_task.rb +1 -1
  73. data/lib/chef/provider/yum_repository.rb +1 -1
  74. data/lib/chef/provider/zypper_repository.rb +31 -11
  75. data/lib/chef/resource.rb +2 -0
  76. data/lib/chef/resource/archive_file.rb +28 -8
  77. data/lib/chef/resource/build_essential.rb +1 -1
  78. data/lib/chef/resource/cron_access.rb +13 -5
  79. data/lib/chef/resource/cron_d.rb +1 -1
  80. data/lib/chef/resource/hostname.rb +19 -18
  81. data/lib/chef/resource/launchd.rb +4 -4
  82. data/lib/chef/resource/lwrp_base.rb +7 -0
  83. data/lib/chef/resource/macos_userdefaults.rb +3 -3
  84. data/lib/chef/resource/msu_package.rb +5 -0
  85. data/lib/chef/resource/ssh_known_hosts_entry.rb +1 -1
  86. data/lib/chef/resource/sudo.rb +2 -2
  87. data/lib/chef/resource/windows_feature_powershell.rb +6 -2
  88. data/lib/chef/resource/windows_firewall_rule.rb +8 -4
  89. data/lib/chef/resource/windows_font.rb +2 -1
  90. data/lib/chef/resource/windows_share.rb +4 -4
  91. data/lib/chef/resource/windows_task.rb +13 -13
  92. data/lib/chef/resource_inspector.rb +4 -3
  93. data/lib/chef/role.rb +2 -2
  94. data/lib/chef/shell.rb +1 -1
  95. data/lib/chef/shell/shell_session.rb +2 -0
  96. data/lib/chef/util/diff.rb +1 -1
  97. data/lib/chef/util/dsc/lcm_output_parser.rb +3 -3
  98. data/lib/chef/util/powershell/cmdlet.rb +1 -1
  99. data/lib/chef/version.rb +2 -2
  100. data/lib/chef/win32/api/command_line_helper.rb +89 -0
  101. data/lib/chef/win32/api/file.rb +18 -18
  102. data/lib/chef/win32/file.rb +3 -3
  103. data/lib/chef/win32/process.rb +2 -2
  104. data/spec/functional/knife/ssh_spec.rb +4 -4
  105. data/spec/functional/resource/aix_service_spec.rb +0 -1
  106. data/spec/functional/resource/aixinit_service_spec.rb +7 -8
  107. data/spec/functional/resource/apt_package_spec.rb +0 -1
  108. data/spec/functional/resource/bff_spec.rb +2 -2
  109. data/spec/functional/resource/chocolatey_package_spec.rb +29 -0
  110. data/spec/functional/resource/cookbook_file_spec.rb +1 -1
  111. data/spec/functional/resource/cron_spec.rb +0 -1
  112. data/spec/functional/resource/dsc_resource_spec.rb +1 -1
  113. data/spec/functional/resource/insserv_spec.rb +4 -5
  114. data/spec/functional/resource/link_spec.rb +17 -17
  115. data/spec/functional/resource/msu_package_spec.rb +5 -2
  116. data/spec/functional/resource/rpm_spec.rb +2 -2
  117. data/spec/functional/resource/user/dscl_spec.rb +2 -2
  118. data/spec/functional/resource/user/mac_user_spec.rb +2 -2
  119. data/spec/functional/resource/windows_certificate_spec.rb +3 -3
  120. data/spec/functional/resource/windows_font_spec.rb +49 -0
  121. data/spec/functional/resource/windows_task_spec.rb +8 -8
  122. data/spec/functional/run_lock_spec.rb +2 -1
  123. data/spec/functional/util/powershell/cmdlet_spec.rb +1 -1
  124. data/spec/functional/version_spec.rb +1 -1
  125. data/spec/functional/win32/service_manager_spec.rb +1 -1
  126. data/spec/integration/recipes/accumulator_spec.rb +1 -1
  127. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +2 -2
  128. data/spec/integration/recipes/lwrp_spec.rb +1 -1
  129. data/spec/integration/recipes/notifies_spec.rb +1 -1
  130. data/spec/integration/recipes/notifying_block_spec.rb +1 -1
  131. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  132. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +2 -0
  133. data/spec/integration/recipes/resource_load_spec.rb +1 -0
  134. data/spec/integration/recipes/unified_mode_spec.rb +1 -1
  135. data/spec/scripts/ssl-serve.rb +1 -1
  136. data/spec/spec_helper.rb +26 -19
  137. data/spec/support/chef_helpers.rb +1 -1
  138. data/spec/support/platform_helpers.rb +12 -42
  139. data/spec/support/platforms/win32/spec_service.rb +1 -1
  140. data/spec/support/shared/functional/directory_resource.rb +1 -1
  141. data/spec/support/shared/functional/execute_resource.rb +1 -1
  142. data/spec/support/shared/functional/file_resource.rb +3 -3
  143. data/spec/support/shared/functional/win32_service.rb +1 -1
  144. data/spec/support/shared/functional/windows_script.rb +3 -3
  145. data/spec/support/shared/integration/knife_support.rb +2 -5
  146. data/spec/unit/application_spec.rb +7 -0
  147. data/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb +2 -4
  148. data/spec/unit/cookbook/gem_installer_spec.rb +2 -1
  149. data/spec/unit/data_bag_spec.rb +1 -1
  150. data/spec/unit/data_collector_spec.rb +1 -1
  151. data/spec/unit/dsl/platform_introspection_spec.rb +1 -0
  152. data/spec/unit/environment_spec.rb +7 -7
  153. data/spec/unit/event_dispatch/dispatcher_spec.rb +3 -0
  154. data/spec/unit/file_access_control_spec.rb +1 -1
  155. data/spec/unit/json_compat_spec.rb +1 -1
  156. data/spec/unit/knife/bootstrap_spec.rb +26 -29
  157. data/spec/unit/knife/cookbook_download_spec.rb +4 -4
  158. data/spec/unit/knife/cookbook_metadata_from_file_spec.rb +1 -1
  159. data/spec/unit/knife/cookbook_upload_spec.rb +5 -6
  160. data/spec/unit/knife/core/hashed_command_loader_spec.rb +3 -3
  161. data/spec/unit/knife/core/windows_bootstrap_context_spec.rb +6 -0
  162. data/spec/unit/knife/role_env_run_list_add_spec.rb +6 -6
  163. data/spec/unit/knife/role_env_run_list_clear_spec.rb +4 -4
  164. data/spec/unit/knife/role_env_run_list_remove_spec.rb +4 -4
  165. data/spec/unit/knife/role_env_run_list_replace_spec.rb +4 -4
  166. data/spec/unit/knife/role_env_run_list_set_spec.rb +4 -4
  167. data/spec/unit/knife/role_run_list_add_spec.rb +6 -6
  168. data/spec/unit/knife/role_run_list_clear_spec.rb +4 -4
  169. data/spec/unit/knife/role_run_list_remove_spec.rb +4 -4
  170. data/spec/unit/knife/role_run_list_replace_spec.rb +4 -4
  171. data/spec/unit/knife/role_run_list_set_spec.rb +4 -4
  172. data/spec/unit/knife/ssh_spec.rb +2 -2
  173. data/spec/unit/knife/supermarket_share_spec.rb +1 -1
  174. data/spec/unit/lwrp_spec.rb +4 -4
  175. data/spec/unit/mixin/securable_spec.rb +0 -1
  176. data/spec/unit/mixin/user_context_spec.rb +1 -9
  177. data/spec/unit/property_spec.rb +6 -6
  178. data/spec/unit/provider/apt_repository_spec.rb +2 -2
  179. data/spec/unit/provider/git_spec.rb +3 -3
  180. data/spec/unit/provider/osx_profile_spec.rb +2 -2
  181. data/spec/unit/provider/package/chocolatey_spec.rb +1 -1
  182. data/spec/unit/provider/package/dnf/python_helper_spec.rb +1 -1
  183. data/spec/unit/provider/package/msu_spec.rb +3 -3
  184. data/spec/unit/provider/package/powershell_spec.rb +95 -86
  185. data/spec/unit/provider/package/rubygems_spec.rb +5 -10
  186. data/spec/unit/provider/package/snap_spec.rb +1 -1
  187. data/spec/unit/provider/package/windows_spec.rb +30 -53
  188. data/spec/unit/provider/service/arch_service_spec.rb +3 -2
  189. data/spec/unit/provider/service/debian_service_spec.rb +1 -1
  190. data/spec/unit/provider/service/gentoo_service_spec.rb +8 -8
  191. data/spec/unit/provider/service/macosx_spec.rb +3 -3
  192. data/spec/unit/provider/service/redhat_spec.rb +2 -2
  193. data/spec/unit/provider/service/upstart_service_spec.rb +3 -3
  194. data/spec/unit/provider/service/windows_spec.rb +2 -6
  195. data/spec/unit/provider/systemd_unit_spec.rb +28 -24
  196. data/spec/unit/provider/zypper_repository_spec.rb +75 -25
  197. data/spec/unit/provider_resolver_spec.rb +9 -9
  198. data/spec/unit/provider_spec.rb +1 -0
  199. data/spec/unit/resource/archive_file_spec.rb +11 -2
  200. data/spec/unit/resource/msu_package_spec.rb +4 -0
  201. data/spec/unit/resource/windows_dns_record_spec.rb +3 -3
  202. data/spec/unit/resource/windows_dns_zone_spec.rb +2 -2
  203. data/spec/unit/resource/windows_feature_powershell_spec.rb +30 -4
  204. data/spec/unit/resource/windows_package_spec.rb +1 -0
  205. data/spec/unit/resource/windows_task_spec.rb +1 -1
  206. data/spec/unit/resource/windows_uac_spec.rb +2 -2
  207. data/spec/unit/resource/yum_repository_spec.rb +21 -21
  208. data/spec/unit/resource_reporter_spec.rb +1 -1
  209. data/spec/unit/resource_spec.rb +1 -1
  210. data/spec/unit/role_spec.rb +11 -11
  211. data/spec/unit/run_context/cookbook_compiler_spec.rb +1 -1
  212. data/spec/unit/run_context_spec.rb +1 -1
  213. data/spec/unit/run_lock_spec.rb +1 -1
  214. data/spec/unit/scan_access_control_spec.rb +1 -1
  215. data/spec/unit/util/threaded_job_queue_spec.rb +9 -0
  216. data/spec/unit/win32/security_spec.rb +4 -3
  217. data/tasks/rspec.rb +5 -13
  218. metadata +24 -16
@@ -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|
@@ -46,7 +46,7 @@ class Chef
46
46
  when Chef::Exceptions::PrivateKeyMissing
47
47
  error_description.section("Private Key Not Found:", <<~E)
48
48
  Your private key could not be loaded. If the key file exists, ensure that it is
49
- readable by #{Chef::Dist::CLIENT}.
49
+ readable by #{Chef::Dist::PRODUCT}.
50
50
  E
51
51
  error_description.section("Relevant Config Settings:", <<~E)
52
52
  client_key "#{api_key}"
@@ -99,7 +99,7 @@ class Chef
99
99
  # redirect.
100
100
  def describe_404_error(error_description)
101
101
  error_description.section("Resource Not Found:", <<~E)
102
- The server returned a HTTP 404. This usually indicates that your chef_server_url is incorrect.
102
+ The #{Chef::Dist::SERVER_PRODUCT} returned a HTTP 404. This usually indicates that your chef_server_url is incorrect.
103
103
  E
104
104
  error_description.section("Relevant Config Settings:", <<~E)
105
105
  chef_server_url "#{server_url}"
@@ -28,7 +28,7 @@ class Chef
28
28
  humanize_http_exception(error_description)
29
29
  when Errno::ECONNREFUSED, Timeout::Error, Errno::ETIMEDOUT, SocketError
30
30
  error_description.section("Network Error:", <<~E)
31
- There was a network error connecting to the Chef Server:
31
+ There was a network error connecting to the #{Chef::Dist::SERVER_PRODUCT}:
32
32
  #{exception.message}
33
33
  E
34
34
  error_description.section("Relevant Config Settings:", <<~E)
@@ -39,14 +39,14 @@ class Chef
39
39
  when Chef::Exceptions::PrivateKeyMissing
40
40
  error_description.section("Private Key Not Found:", <<~E)
41
41
  Your private key could not be loaded. If the key file exists, ensure that it is
42
- readable by #{Chef::Dist::CLIENT}.
42
+ readable by #{Chef::Dist::PRODUCT}.
43
43
  E
44
44
  error_description.section("Relevant Config Settings:", <<~E)
45
45
  validation_key "#{api_key}"
46
46
  E
47
47
  when Chef::Exceptions::InvalidRedirect
48
48
  error_description.section("Invalid Redirect:", <<~E)
49
- Change your server location in client.rb to the server's FQDN to avoid unwanted redirections.
49
+ Change your #{Chef::Dist::SERVER_PRODUCT} location in client.rb to the #{Chef::Dist::SERVER_PRODUCT}'s FQDN to avoid unwanted redirections.
50
50
  E
51
51
  when EOFError
52
52
  describe_eof_error(error_description)
@@ -61,13 +61,13 @@ class Chef
61
61
  when Net::HTTPUnauthorized
62
62
  if clock_skew?
63
63
  error_description.section("Authentication Error:", <<~E)
64
- Failed to authenticate to the chef server (http 401).
64
+ Failed to authenticate to the #{Chef::Dist::SERVER_PRODUCT} (http 401).
65
65
  The request failed because your clock has drifted by more than 15 minutes.
66
66
  Syncing your clock to an NTP Time source should resolve the issue.
67
67
  E
68
68
  else
69
69
  error_description.section("Authentication Error:", <<~E)
70
- Failed to authenticate to the chef server (http 401).
70
+ Failed to authenticate to the #{Chef::Dist::SERVER_PRODUCT} (http 401).
71
71
  E
72
72
 
73
73
  error_description.section("Server Response:", format_rest_error)
@@ -81,7 +81,7 @@ class Chef
81
81
  end
82
82
  when Net::HTTPForbidden
83
83
  error_description.section("Authorization Error:", <<~E)
84
- Your validation client is not authorized to create the client for this node (HTTP 403).
84
+ Your validation client is not authorized to create the client for this node on the #{Chef::Dist::SERVER_PRODUCT} (HTTP 403).
85
85
  E
86
86
  error_description.section("Possible Causes:", <<~E)
87
87
  * There may already be a client named "#{config[:node_name]}"
@@ -94,7 +94,7 @@ class Chef
94
94
  error_description.section("Server Response:", format_rest_error)
95
95
  when Net::HTTPNotFound
96
96
  error_description.section("Resource Not Found:", <<~E)
97
- The server returned a HTTP 404. This usually indicates that your chef_server_url is incorrect.
97
+ The #{Chef::Dist::SERVER_PRODUCT} returned a HTTP 404. This usually indicates that your chef_server_url configuration is incorrect.
98
98
  E
99
99
  error_description.section("Relevant Config Settings:", <<~E)
100
100
  chef_server_url "#{server_url}"
@@ -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"
@@ -345,31 +345,35 @@ class Chef
345
345
  exit(1)
346
346
  end
347
347
 
348
- # keys from mixlib-cli options
349
- def cli_keys
350
- self.class.options.keys
348
+ # This is all set and default mixlib-config values. We only need the default
349
+ # values here (the set values are explicitly mixed in again later), but there is
350
+ # no mixlib-config API to get a Hash back with only the default values.
351
+ #
352
+ # Assumption: since config_file_defaults is the lowest precedence it doesn't matter
353
+ # that we include the set values here, but this is a hack and makes the name of the
354
+ # method a lie. FIXME: make the name not a lie by adding an API to mixlib-config.
355
+ #
356
+ # @api private
357
+ #
358
+ def config_file_defaults
359
+ Chef::Config[:knife].save(true) # this is like "dup" to a (real) Hash, and includes default values (and user set values)
351
360
  end
352
361
 
353
- # extracts the settings from the Chef::Config[:knife] sub-hash that correspond
354
- # to knife cli options -- in preparation for merging config values with cli values
362
+ # This is only the user-set mixlib-config values. We do not include the defaults
363
+ # here so that the config defaults do not override the cli defaults.
364
+ #
365
+ # @api private
355
366
  #
356
- # NOTE: due to weirdness in mixlib-config #has_key? is only true if the value has
357
- # been set by the user -- the Chef::Config defaults return #has_key?() of false and
358
- # this code DEPENDS on that functionality since applying the default values in
359
- # Chef::Config[:knife] would break the defaults in the cli that we would otherwise
360
- # overwrite.
361
367
  def config_file_settings
362
- cli_keys.each_with_object({}) do |key, memo|
363
- if Chef::Config[:knife].key?(key)
364
- memo[key] = Chef::Config[:knife][key]
365
- end
366
- end
368
+ Chef::Config[:knife].save(false) # this is like "dup" to a (real) Hash, and does not include default values (just user set values)
367
369
  end
368
370
 
369
371
  # config is merged in this order (inverse of precedence)
370
- # default_config - mixlib-cli defaults (accessor from the mixin)
371
- # config_file_settings - Chef::Config[:knife] sub-hash
372
- # config - mixlib-cli settings (accessor from the mixin)
372
+ # config_file_defaults - Chef::Config[:knife] defaults from chef-config (XXX: this also includes the settings, but they get overwritten)
373
+ # default_config - mixlib-cli defaults (accessor from mixlib-cli)
374
+ # config_file_settings - Chef::Config[:knife] user settings from the client.rb file
375
+ # config - mixlib-cli settings (accessor from mixlib-cli)
376
+ #
373
377
  def merge_configs
374
378
  # Update our original_config - if someone has created a knife command
375
379
  # instance directly, they are likely ot have set cmd.config values directly
@@ -377,7 +381,7 @@ class Chef
377
381
  @original_config = config.dup
378
382
  # other code may have a handle to the config object, so use Hash#replace to deliberately
379
383
  # update-in-place.
380
- config.replace(default_config.merge(config_file_settings).merge(config))
384
+ config.replace(config_file_defaults.merge(default_config).merge(config_file_settings).merge(config))
381
385
  end
382
386
 
383
387
  #
@@ -387,8 +391,9 @@ class Chef
387
391
  # @return [Symbol,NilClass] return the source of the config key,
388
392
  # one of:
389
393
  # - :cli - this was explicitly provided on the CLI
390
- # - :config - this came from Chef::Config[:knife]
394
+ # - :config - this came from Chef::Config[:knife] explicitly being set
391
395
  # - :cli_default - came from a declared CLI `option`'s `default` value.
396
+ # - :config_default - this came from Chef::Config[:knife]'s defaults
392
397
  # - nil - if the key could not be found in any source.
393
398
  # This can happen when it is invalid, or has been
394
399
  # set directly into #config without then calling #merge_config
@@ -396,6 +401,7 @@ class Chef
396
401
  return :cli if @original_config.include? key
397
402
  return :config if config_file_settings.key? key
398
403
  return :cli_default if default_config.include? key
404
+ return :config_default if config_file_defaults.key? key # must come after :config check
399
405
 
400
406
  nil
401
407
  end
@@ -94,13 +94,13 @@ class Chef
94
94
  description: "For WinRM basic authentication when using the 'ssl' auth method.",
95
95
  boolean: true
96
96
 
97
- # This option was provided in knife bootstrap windows winrm,
98
- # but it is ignored in knife-windows/WinrmSession, and so remains unimplemeneted here.
99
- # option :kerberos_keytab_file,
100
- # :short => "-T KEYTAB_FILE",
101
- # :long => "--keytab-file KEYTAB_FILE",
102
- # :description => "The Kerberos keytab file used for authentication",
103
- # :proc => Proc.new { |keytab| Chef::Config[:knife][:kerberos_keytab_file] = keytab }
97
+ # This option was provided in knife bootstrap windows winrm,
98
+ # but it is ignored in knife-windows/WinrmSession, and so remains unimplemeneted here.
99
+ # option :kerberos_keytab_file,
100
+ # :short => "-T KEYTAB_FILE",
101
+ # :long => "--keytab-file KEYTAB_FILE",
102
+ # :description => "The Kerberos keytab file used for authentication",
103
+ # :proc => Proc.new { |keytab| Chef::Config[:knife][:kerberos_keytab_file] = keytab }
104
104
 
105
105
  option :kerberos_realm,
106
106
  short: "-R KERBEROS_REALM",
@@ -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
@@ -1061,24 +1058,25 @@ class Chef
1061
1058
  }
1062
1059
  end
1063
1060
 
1064
- # Looks up configuration entries, first in the class member
1065
- # `config` which contains options populated from CLI flags.
1066
- # If the entry is not found there, Chef::Config[:knife][KEY]
1067
- # is checked.
1061
+ # Knife plugins should just use the config hash and not call this method. In the
1062
+ # future there will be a way to deprecate Chef::Config options in addition to the
1063
+ # CLI options, which will eliminate this methods primary purpose.
1064
+ #
1065
+ # In Chef-16 the single-argument verison of this function will be deprecated and
1066
+ # config_value(:whatver) should be converted to config[:whatever]. That never had
1067
+ # any purpose and never should have been used this way.
1068
1068
  #
1069
- # knife_config_key should be specified if the knife config lookup
1070
- # key is different from the CLI flag lookup key.
1069
+ # @api deprecated
1071
1070
  #
1072
- def config_value(key, knife_config_key = nil, default = nil)
1073
- if config.key? key
1071
+ def config_value(key, fallback_key = nil, default = nil)
1072
+ if config.key?(key)
1073
+ # the first key is the primary key so we check the merged hash first
1074
1074
  config[key]
1075
+ elsif config.key?(fallback_key)
1076
+ # we get the old config option here (the deprecated cli option shouldn't exist)
1077
+ config[fallback_key]
1075
1078
  else
1076
- lookup_key = knife_config_key || key
1077
- if Chef::Config[:knife].key?(lookup_key) || config.key?(lookup_key)
1078
- Chef::Config[:knife][lookup_key] || config[lookup_key]
1079
- else
1080
- default
1081
- end
1079
+ default
1082
1080
  end
1083
1081
  end
1084
1082
 
@@ -1107,7 +1105,8 @@ class Chef
1107
1105
  # These keys are available in Chef::Config, and are prefixed with the protocol name.
1108
1106
  # For example, :user CLI option will map to :winrm_user and :ssh_user Chef::Config keys,
1109
1107
  # based on the connection protocol in use.
1110
- def knife_key_for_protocol(protocol, option)
1108
+ def knife_key_for_protocol(new_option, option = nil)
1109
+ option = new_option if option.nil? # hacky compat with both old Chef-15 style and new Chef-16 style API signature
1111
1110
  "#{connection_protocol}_#{option}".to_sym
1112
1111
  end
1113
1112
 
@@ -21,7 +21,7 @@ class Chef
21
21
  class ChefVaultHandler
22
22
 
23
23
  # @return [Hash] knife merged config, typically @config
24
- attr_accessor :knife_config
24
+ attr_accessor :config
25
25
 
26
26
  # @return [Chef::Knife::UI] ui object for output
27
27
  attr_accessor :ui
@@ -29,11 +29,15 @@ class Chef
29
29
  # @return [Chef::ApiClient] vault client
30
30
  attr_reader :client
31
31
 
32
- # @param knife_config [Hash] knife merged config, typically @config
32
+ # @param config [Hash] knife merged config, typically @config
33
33
  # @param ui [Chef::Knife::UI] ui object for output
34
- def initialize(knife_config: {}, ui: nil)
35
- @knife_config = knife_config
36
- @ui = ui
34
+ def initialize(config: {}, knife_config: nil, ui: nil)
35
+ @config = config
36
+ unless knife_config.nil?
37
+ # the knife_config argument becomes deprecated in Chef-16, don't use it
38
+ @config = knife_config
39
+ end
40
+ @ui = ui
37
41
  end
38
42
 
39
43
  # Updates the chef vault items for the newly created client.
@@ -85,17 +89,17 @@ class Chef
85
89
 
86
90
  # @return [String] string with serialized JSON representing the chef vault items
87
91
  def bootstrap_vault_json
88
- knife_config[:bootstrap_vault_json]
92
+ config[:bootstrap_vault_json]
89
93
  end
90
94
 
91
95
  # @return [String] JSON text in a file representing the chef vault items
92
96
  def bootstrap_vault_file
93
- knife_config[:bootstrap_vault_file]
97
+ config[:bootstrap_vault_file]
94
98
  end
95
99
 
96
100
  # @return [Hash] Ruby object representing the chef vault items to create
97
101
  def bootstrap_vault_item
98
- knife_config[:bootstrap_vault_item]
102
+ config[:bootstrap_vault_item]
99
103
  end
100
104
 
101
105
  # Helper to return a ruby object represeting all the data bags and items
@@ -28,7 +28,7 @@ class Chef
28
28
  class ClientBuilder
29
29
 
30
30
  # @return [Hash] knife merged config, typically @config
31
- attr_accessor :knife_config
31
+ attr_accessor :config
32
32
  # @return [Hash] chef config object
33
33
  attr_accessor :chef_config
34
34
  # @return [Chef::Knife::UI] ui object for output
@@ -36,13 +36,17 @@ class Chef
36
36
  # @return [Chef::ApiClient] client saved on run
37
37
  attr_reader :client
38
38
 
39
- # @param knife_config [Hash] Hash of knife config settings
39
+ # @param config [Hash] Hash of knife config settings
40
40
  # @param chef_config [Hash] Hash of chef config settings
41
41
  # @param ui [Chef::Knife::UI] UI object for output
42
- def initialize(knife_config: {}, chef_config: {}, ui: nil)
43
- @knife_config = knife_config
44
- @chef_config = chef_config
45
- @ui = ui
42
+ def initialize(config: {}, knife_config: nil, chef_config: {}, ui: nil)
43
+ @config = config
44
+ unless knife_config.nil?
45
+ # the knife_config argument becomes deprecated in Chef-16, don't use it
46
+ @config = knife_config
47
+ end
48
+ @chef_config = chef_config
49
+ @ui = ui
46
50
  end
47
51
 
48
52
  # Main entry. Prompt the user to clean up any old client or node objects. Then create
@@ -77,34 +81,34 @@ class Chef
77
81
 
78
82
  private
79
83
 
80
- # @return [String] node name from the knife_config
84
+ # @return [String] node name from the config
81
85
  def node_name
82
- knife_config[:chef_node_name]
86
+ config[:chef_node_name]
83
87
  end
84
88
 
85
- # @return [String] enviroment from the knife_config
89
+ # @return [String] enviroment from the config
86
90
  def environment
87
- knife_config[:environment]
91
+ config[:environment]
88
92
  end
89
93
 
90
- # @return [String] run_list from the knife_config
94
+ # @return [String] run_list from the config
91
95
  def run_list
92
- knife_config[:run_list]
96
+ config[:run_list]
93
97
  end
94
98
 
95
- # @return [String] policy_name from the knife_config
99
+ # @return [String] policy_name from the config
96
100
  def policy_name
97
- knife_config[:policy_name]
101
+ config[:policy_name]
98
102
  end
99
103
 
100
- # @return [String] policy_group from the knife_config
104
+ # @return [String] policy_group from the config
101
105
  def policy_group
102
- knife_config[:policy_group]
106
+ config[:policy_group]
103
107
  end
104
108
 
105
- # @return [Hash,Array] Object representation of json first-boot attributes from the knife_config
109
+ # @return [Hash,Array] Object representation of json first-boot attributes from the config
106
110
  def first_boot_attributes
107
- knife_config[:first_boot_attributes]
111
+ config[:first_boot_attributes]
108
112
  end
109
113
 
110
114
  # @return [String] chef server url from the Chef::Config
@@ -154,7 +158,7 @@ class Chef
154
158
  node.environment(environment) if environment
155
159
  node.policy_name = policy_name if policy_name
156
160
  node.policy_group = policy_group if policy_group
157
- (knife_config[:tags] || []).each do |tag|
161
+ (config[:tags] || []).each do |tag|
158
162
  node.tags << tag
159
163
  end
160
164
  node
@@ -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