chef 15.10.12-universal-mingw32 → 15.14.0-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) 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/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 +2 -2
  11. data/lib/chef/application/exit_code.rb +2 -2
  12. data/lib/chef/chef_fs/chef_fs_data_store.rb +3 -3
  13. data/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb +1 -1
  14. data/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb +1 -1
  15. data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +1 -1
  16. data/lib/chef/chef_fs/file_system/repository/base_file.rb +1 -0
  17. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb +2 -2
  18. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +1 -1
  19. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +2 -2
  20. data/lib/chef/chef_fs/file_system/repository/directory.rb +1 -1
  21. data/lib/chef/chef_fs/file_system/repository/file_system_entry.rb +1 -1
  22. data/lib/chef/chef_fs/path_utils.rb +3 -3
  23. data/lib/chef/cookbook/file_system_file_vendor.rb +1 -1
  24. data/lib/chef/cookbook_version.rb +4 -4
  25. data/lib/chef/data_bag.rb +2 -2
  26. data/lib/chef/data_collector/error_handlers.rb +1 -1
  27. data/lib/chef/deprecated.rb +13 -1
  28. data/lib/chef/dsl/declare_resource.rb +1 -1
  29. data/lib/chef/dsl/platform_introspection.rb +3 -1
  30. data/lib/chef/environment.rb +2 -2
  31. data/lib/chef/exceptions.rb +3 -0
  32. data/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb +2 -2
  33. data/lib/chef/formatters/error_inspectors/registration_error_inspector.rb +7 -7
  34. data/lib/chef/http.rb +2 -1
  35. data/lib/chef/knife.rb +26 -20
  36. data/lib/chef/knife/bootstrap.rb +30 -31
  37. data/lib/chef/knife/bootstrap/chef_vault_handler.rb +12 -8
  38. data/lib/chef/knife/bootstrap/client_builder.rb +23 -19
  39. data/lib/chef/knife/bootstrap/templates/chef-full.erb +9 -9
  40. data/lib/chef/knife/bootstrap/templates/windows-chef-client-msi.erb +3 -1
  41. data/lib/chef/knife/bootstrap/train_connector.rb +1 -0
  42. data/lib/chef/knife/cookbook_download.rb +1 -1
  43. data/lib/chef/knife/cookbook_metadata.rb +1 -1
  44. data/lib/chef/knife/cookbook_site_search.rb +1 -1
  45. data/lib/chef/knife/cookbook_site_show.rb +1 -1
  46. data/lib/chef/knife/cookbook_site_unshare.rb +1 -1
  47. data/lib/chef/knife/core/gem_glob_loader.rb +1 -1
  48. data/lib/chef/knife/core/hashed_command_loader.rb +3 -2
  49. data/lib/chef/knife/core/subcommand_loader.rb +1 -1
  50. data/lib/chef/knife/core/windows_bootstrap_context.rb +18 -3
  51. data/lib/chef/knife/exec.rb +2 -2
  52. data/lib/chef/knife/ssh.rb +21 -2
  53. data/lib/chef/log.rb +1 -1
  54. data/lib/chef/mixin/create_path.rb +8 -8
  55. data/lib/chef/mixin/openssl_helper.rb +26 -3
  56. data/lib/chef/mixin/template.rb +1 -0
  57. data/lib/chef/node/mixin/deep_merge_cache.rb +7 -7
  58. data/lib/chef/node_map.rb +5 -2
  59. data/lib/chef/provider/mount/solaris.rb +0 -1
  60. data/lib/chef/provider/package/cab.rb +1 -1
  61. data/lib/chef/provider/package/chocolatey.rb +4 -3
  62. data/lib/chef/provider/package/msu.rb +1 -0
  63. data/lib/chef/provider/package/powershell.rb +5 -1
  64. data/lib/chef/provider/package/snap.rb +96 -27
  65. data/lib/chef/provider/package/zypper.rb +0 -1
  66. data/lib/chef/provider/service/arch.rb +2 -2
  67. data/lib/chef/provider/service/debian.rb +1 -1
  68. data/lib/chef/provider/service/gentoo.rb +2 -2
  69. data/lib/chef/provider/service/macosx.rb +2 -2
  70. data/lib/chef/provider/service/openbsd.rb +1 -1
  71. data/lib/chef/provider/service/redhat.rb +2 -2
  72. data/lib/chef/provider/service/simple.rb +3 -3
  73. data/lib/chef/provider/service/upstart.rb +1 -1
  74. data/lib/chef/provider/windows_task.rb +1 -1
  75. data/lib/chef/provider/yum_repository.rb +1 -1
  76. data/lib/chef/provider/zypper_repository.rb +31 -11
  77. data/lib/chef/resource.rb +2 -0
  78. data/lib/chef/resource/archive_file.rb +28 -8
  79. data/lib/chef/resource/build_essential.rb +1 -1
  80. data/lib/chef/resource/cron_access.rb +13 -5
  81. data/lib/chef/resource/cron_d.rb +1 -1
  82. data/lib/chef/resource/hostname.rb +19 -18
  83. data/lib/chef/resource/launchd.rb +4 -4
  84. data/lib/chef/resource/lwrp_base.rb +7 -0
  85. data/lib/chef/resource/macos_userdefaults.rb +3 -3
  86. data/lib/chef/resource/msu_package.rb +5 -0
  87. data/lib/chef/resource/ssh_known_hosts_entry.rb +1 -1
  88. data/lib/chef/resource/sudo.rb +2 -2
  89. data/lib/chef/resource/windows_feature_powershell.rb +6 -2
  90. data/lib/chef/resource/windows_firewall_rule.rb +8 -4
  91. data/lib/chef/resource/windows_font.rb +2 -1
  92. data/lib/chef/resource/windows_share.rb +4 -4
  93. data/lib/chef/resource/windows_task.rb +13 -13
  94. data/lib/chef/resource_inspector.rb +4 -3
  95. data/lib/chef/role.rb +2 -2
  96. data/lib/chef/shell.rb +1 -1
  97. data/lib/chef/shell/shell_session.rb +2 -0
  98. data/lib/chef/util/diff.rb +1 -1
  99. data/lib/chef/util/dsc/lcm_output_parser.rb +3 -3
  100. data/lib/chef/util/powershell/cmdlet.rb +1 -1
  101. data/lib/chef/version.rb +2 -2
  102. data/lib/chef/win32/api/command_line_helper.rb +89 -0
  103. data/lib/chef/win32/api/file.rb +18 -18
  104. data/lib/chef/win32/file.rb +3 -3
  105. data/lib/chef/win32/process.rb +2 -2
  106. data/spec/functional/knife/ssh_spec.rb +4 -4
  107. data/spec/functional/resource/aix_service_spec.rb +0 -1
  108. data/spec/functional/resource/aixinit_service_spec.rb +7 -8
  109. data/spec/functional/resource/apt_package_spec.rb +0 -1
  110. data/spec/functional/resource/bff_spec.rb +2 -2
  111. data/spec/functional/resource/chocolatey_package_spec.rb +29 -0
  112. data/spec/functional/resource/cookbook_file_spec.rb +1 -1
  113. data/spec/functional/resource/cron_spec.rb +0 -1
  114. data/spec/functional/resource/dsc_resource_spec.rb +1 -1
  115. data/spec/functional/resource/insserv_spec.rb +4 -5
  116. data/spec/functional/resource/link_spec.rb +17 -17
  117. data/spec/functional/resource/msu_package_spec.rb +5 -2
  118. data/spec/functional/resource/rpm_spec.rb +2 -2
  119. data/spec/functional/resource/user/dscl_spec.rb +2 -2
  120. data/spec/functional/resource/user/mac_user_spec.rb +2 -2
  121. data/spec/functional/resource/windows_certificate_spec.rb +3 -3
  122. data/spec/functional/resource/windows_font_spec.rb +49 -0
  123. data/spec/functional/resource/windows_task_spec.rb +8 -8
  124. data/spec/functional/run_lock_spec.rb +2 -1
  125. data/spec/functional/util/powershell/cmdlet_spec.rb +1 -1
  126. data/spec/functional/version_spec.rb +1 -1
  127. data/spec/functional/win32/service_manager_spec.rb +1 -1
  128. data/spec/integration/recipes/accumulator_spec.rb +1 -1
  129. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +2 -2
  130. data/spec/integration/recipes/lwrp_spec.rb +1 -1
  131. data/spec/integration/recipes/notifies_spec.rb +1 -1
  132. data/spec/integration/recipes/notifying_block_spec.rb +1 -1
  133. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  134. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +2 -0
  135. data/spec/integration/recipes/resource_load_spec.rb +1 -0
  136. data/spec/integration/recipes/unified_mode_spec.rb +1 -1
  137. data/spec/scripts/ssl-serve.rb +1 -1
  138. data/spec/spec_helper.rb +26 -19
  139. data/spec/support/chef_helpers.rb +1 -1
  140. data/spec/support/platform_helpers.rb +12 -42
  141. data/spec/support/platforms/win32/spec_service.rb +1 -1
  142. data/spec/support/shared/functional/directory_resource.rb +1 -1
  143. data/spec/support/shared/functional/execute_resource.rb +1 -1
  144. data/spec/support/shared/functional/file_resource.rb +3 -3
  145. data/spec/support/shared/functional/win32_service.rb +1 -1
  146. data/spec/support/shared/functional/windows_script.rb +3 -3
  147. data/spec/support/shared/integration/knife_support.rb +2 -5
  148. data/spec/unit/application_spec.rb +7 -0
  149. data/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb +2 -4
  150. data/spec/unit/cookbook/gem_installer_spec.rb +2 -1
  151. data/spec/unit/data_bag_spec.rb +1 -1
  152. data/spec/unit/data_collector_spec.rb +1 -1
  153. data/spec/unit/dsl/platform_introspection_spec.rb +1 -0
  154. data/spec/unit/environment_spec.rb +7 -7
  155. data/spec/unit/event_dispatch/dispatcher_spec.rb +3 -0
  156. data/spec/unit/file_access_control_spec.rb +1 -1
  157. data/spec/unit/json_compat_spec.rb +1 -1
  158. data/spec/unit/knife/bootstrap_spec.rb +26 -29
  159. data/spec/unit/knife/cookbook_download_spec.rb +4 -4
  160. data/spec/unit/knife/cookbook_metadata_from_file_spec.rb +1 -1
  161. data/spec/unit/knife/cookbook_upload_spec.rb +5 -6
  162. data/spec/unit/knife/core/hashed_command_loader_spec.rb +3 -3
  163. data/spec/unit/knife/core/windows_bootstrap_context_spec.rb +6 -0
  164. data/spec/unit/knife/role_env_run_list_add_spec.rb +6 -6
  165. data/spec/unit/knife/role_env_run_list_clear_spec.rb +4 -4
  166. data/spec/unit/knife/role_env_run_list_remove_spec.rb +4 -4
  167. data/spec/unit/knife/role_env_run_list_replace_spec.rb +4 -4
  168. data/spec/unit/knife/role_env_run_list_set_spec.rb +4 -4
  169. data/spec/unit/knife/role_run_list_add_spec.rb +6 -6
  170. data/spec/unit/knife/role_run_list_clear_spec.rb +4 -4
  171. data/spec/unit/knife/role_run_list_remove_spec.rb +4 -4
  172. data/spec/unit/knife/role_run_list_replace_spec.rb +4 -4
  173. data/spec/unit/knife/role_run_list_set_spec.rb +4 -4
  174. data/spec/unit/knife/ssh_spec.rb +2 -2
  175. data/spec/unit/knife/supermarket_share_spec.rb +1 -1
  176. data/spec/unit/lwrp_spec.rb +4 -4
  177. data/spec/unit/mixin/securable_spec.rb +0 -1
  178. data/spec/unit/mixin/user_context_spec.rb +1 -9
  179. data/spec/unit/property_spec.rb +6 -6
  180. data/spec/unit/provider/apt_repository_spec.rb +2 -2
  181. data/spec/unit/provider/git_spec.rb +3 -3
  182. data/spec/unit/provider/osx_profile_spec.rb +2 -2
  183. data/spec/unit/provider/package/chocolatey_spec.rb +1 -1
  184. data/spec/unit/provider/package/dnf/python_helper_spec.rb +1 -1
  185. data/spec/unit/provider/package/msu_spec.rb +3 -3
  186. data/spec/unit/provider/package/powershell_spec.rb +95 -86
  187. data/spec/unit/provider/package/rubygems_spec.rb +5 -10
  188. data/spec/unit/provider/package/snap_spec.rb +1 -1
  189. data/spec/unit/provider/package/windows_spec.rb +30 -53
  190. data/spec/unit/provider/service/arch_service_spec.rb +3 -2
  191. data/spec/unit/provider/service/debian_service_spec.rb +1 -1
  192. data/spec/unit/provider/service/gentoo_service_spec.rb +8 -8
  193. data/spec/unit/provider/service/macosx_spec.rb +3 -3
  194. data/spec/unit/provider/service/redhat_spec.rb +2 -2
  195. data/spec/unit/provider/service/upstart_service_spec.rb +3 -3
  196. data/spec/unit/provider/service/windows_spec.rb +2 -6
  197. data/spec/unit/provider/systemd_unit_spec.rb +28 -24
  198. data/spec/unit/provider/zypper_repository_spec.rb +75 -25
  199. data/spec/unit/provider_resolver_spec.rb +9 -9
  200. data/spec/unit/provider_spec.rb +1 -0
  201. data/spec/unit/resource/archive_file_spec.rb +11 -2
  202. data/spec/unit/resource/msu_package_spec.rb +4 -0
  203. data/spec/unit/resource/windows_dns_record_spec.rb +3 -3
  204. data/spec/unit/resource/windows_dns_zone_spec.rb +2 -2
  205. data/spec/unit/resource/windows_feature_powershell_spec.rb +30 -4
  206. data/spec/unit/resource/windows_package_spec.rb +1 -0
  207. data/spec/unit/resource/windows_task_spec.rb +1 -1
  208. data/spec/unit/resource/windows_uac_spec.rb +2 -2
  209. data/spec/unit/resource/yum_repository_spec.rb +21 -21
  210. data/spec/unit/resource_reporter_spec.rb +1 -1
  211. data/spec/unit/resource_spec.rb +1 -1
  212. data/spec/unit/role_spec.rb +11 -11
  213. data/spec/unit/run_context/cookbook_compiler_spec.rb +1 -1
  214. data/spec/unit/run_context_spec.rb +1 -1
  215. data/spec/unit/run_lock_spec.rb +1 -1
  216. data/spec/unit/scan_access_control_spec.rb +1 -1
  217. data/spec/unit/util/threaded_job_queue_spec.rb +9 -0
  218. data/spec/unit/win32/security_spec.rb +4 -3
  219. data/tasks/rspec.rb +5 -13
  220. metadata +32 -18
@@ -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)
@@ -168,7 +168,7 @@ class Chef
168
168
  has_platform
169
169
  end
170
170
 
171
- # Implementation class for determining platform family dependent values
171
+ # Implementation class for determining platform family dependent values
172
172
  class PlatformFamilyDependentValue
173
173
 
174
174
  # Create a platform family dependent value object.
@@ -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|
@@ -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