chef 14.1.12-universal-mingw32 → 14.2.0-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -6
  3. data/VERSION +1 -1
  4. data/chef.gemspec +2 -3
  5. data/lib/chef/chef_fs/data_handler/data_handler_base.rb +8 -4
  6. data/lib/chef/cookbook/manifest_v0.rb +2 -2
  7. data/lib/chef/cookbook_manifest.rb +3 -2
  8. data/lib/chef/cookbook_version.rb +3 -2
  9. data/lib/chef/guard_interpreter/default_guard_interpreter.rb +2 -2
  10. data/lib/chef/http/auth_credentials.rb +5 -3
  11. data/lib/chef/http/authenticator.rb +6 -3
  12. data/lib/chef/knife.rb +3 -6
  13. data/lib/chef/knife/configure.rb +12 -8
  14. data/lib/chef/knife/raw.rb +6 -1
  15. data/lib/chef/mixin/shell_out.rb +16 -14
  16. data/lib/chef/provider/execute.rb +4 -3
  17. data/lib/chef/provider/git.rb +1 -1
  18. data/lib/chef/provider/package/dnf.rb +5 -5
  19. data/lib/chef/provider/package/windows.rb +7 -0
  20. data/lib/chef/provider/package/yum.rb +7 -7
  21. data/lib/chef/provider/service/freebsd.rb +3 -3
  22. data/lib/chef/provider/service/init.rb +5 -5
  23. data/lib/chef/provider/service/macosx.rb +5 -4
  24. data/lib/chef/provider/service/simple.rb +4 -4
  25. data/lib/chef/provider/service/systemd.rb +13 -13
  26. data/lib/chef/provider/service/upstart.rb +3 -3
  27. data/lib/chef/provider/service/windows.rb +2 -0
  28. data/lib/chef/provider/systemd_unit.rb +4 -4
  29. data/lib/chef/provider/user.rb +18 -1
  30. data/lib/chef/provider/user/aix.rb +40 -8
  31. data/lib/chef/provider/user/dscl.rb +7 -14
  32. data/lib/chef/provider/user/linux.rb +1 -11
  33. data/lib/chef/provider/user/solaris.rb +57 -26
  34. data/lib/chef/provider/user/useradd.rb +4 -1
  35. data/lib/chef/provider/windows_task.rb +1 -0
  36. data/lib/chef/providers.rb +1 -2
  37. data/lib/chef/resource/execute.rb +4 -1
  38. data/lib/chef/resource/gem_package.rb +1 -1
  39. data/lib/chef/resource/hostname.rb +1 -1
  40. data/lib/chef/resource/sysctl.rb +3 -1
  41. data/lib/chef/resource/windows_ad_join.rb +16 -3
  42. data/lib/chef/resource_inspector.rb +13 -0
  43. data/lib/chef/run_context/cookbook_compiler.rb +1 -1
  44. data/lib/chef/server_api.rb +2 -0
  45. data/lib/chef/version.rb +1 -1
  46. data/spec/functional/mixin/shell_out_spec.rb +27 -1
  47. data/spec/functional/resource/execute_spec.rb +2 -2
  48. data/spec/functional/resource/windows_task_spec.rb +1 -1
  49. data/spec/support/shared/functional/securable_resource.rb +1 -1
  50. data/spec/support/shared/unit/execute_resource.rb +1 -1
  51. data/spec/support/shared/unit/provider/useradd_based_user_provider.rb +3 -3
  52. data/spec/unit/chef_fs/data_handler/data_handler_base_spec.rb +65 -0
  53. data/spec/unit/cookbook/manifest_v0_spec.rb +1 -1
  54. data/spec/unit/cookbook_manifest_spec.rb +2 -0
  55. data/spec/unit/dsl/recipe_spec.rb +1 -5
  56. data/spec/unit/http/authenticator_spec.rb +33 -8
  57. data/spec/unit/mixin/shell_out_spec.rb +61 -1
  58. data/spec/unit/provider/apt_update_spec.rb +7 -7
  59. data/spec/unit/provider/execute_spec.rb +16 -15
  60. data/spec/unit/provider/git_spec.rb +3 -3
  61. data/spec/unit/provider/package/windows_spec.rb +12 -0
  62. data/spec/unit/provider/script_spec.rb +2 -2
  63. data/spec/unit/provider/service/arch_service_spec.rb +9 -9
  64. data/spec/unit/provider/service/freebsd_service_spec.rb +6 -6
  65. data/spec/unit/provider/service/init_service_spec.rb +11 -11
  66. data/spec/unit/provider/service/invokercd_service_spec.rb +9 -9
  67. data/spec/unit/provider/service/macosx_spec.rb +11 -11
  68. data/spec/unit/provider/service/openbsd_service_spec.rb +6 -6
  69. data/spec/unit/provider/service/simple_service_spec.rb +4 -4
  70. data/spec/unit/provider/service/systemd_service_spec.rb +16 -16
  71. data/spec/unit/provider/service/upstart_service_spec.rb +12 -12
  72. data/spec/unit/provider/service/windows_spec.rb +5 -0
  73. data/spec/unit/provider/systemd_unit_spec.rb +163 -118
  74. data/spec/unit/provider/user/dscl_spec.rb +2 -9
  75. data/spec/unit/provider/user/solaris_spec.rb +2 -2
  76. data/spec/unit/provider/zypper_repository_spec.rb +3 -3
  77. data/spec/unit/provider_spec.rb +1 -5
  78. data/spec/unit/resource/apt_package_spec.rb +14 -0
  79. data/spec/unit/resource/apt_preference_spec.rb +14 -1
  80. data/spec/unit/resource/apt_repository_spec.rb +12 -3
  81. data/spec/unit/resource/apt_update_spec.rb +9 -0
  82. data/spec/unit/resource/bash_spec.rb +8 -0
  83. data/spec/unit/resource/bff_package_spec.rb +51 -0
  84. data/spec/unit/resource/breakpoint_spec.rb +4 -4
  85. data/spec/unit/resource/build_essential_spec.rb +5 -1
  86. data/spec/unit/resource/cab_package_spec.rb +10 -0
  87. data/spec/unit/resource/chef_gem_spec.rb +14 -0
  88. data/spec/unit/resource/chef_handler_spec.rb +9 -4
  89. data/spec/unit/resource/chocolatey_package_spec.rb +15 -1
  90. data/spec/unit/resource/conditional_spec.rb +3 -3
  91. data/spec/unit/resource/cookbook_file_spec.rb +13 -2
  92. data/spec/unit/resource/cron_spec.rb +2 -7
  93. data/spec/unit/resource/csh_spec.rb +8 -0
  94. data/spec/unit/resource/directory_spec.rb +4 -9
  95. data/spec/unit/resource/dmg_package_spec.rb +8 -4
  96. data/spec/unit/resource/dnf_package_spec.rb +16 -1
  97. data/spec/unit/resource/dpkg_package_spec.rb +18 -0
  98. data/spec/unit/resource/dsc_resource_spec.rb +6 -6
  99. data/spec/unit/resource/dsc_script_spec.rb +39 -39
  100. data/spec/unit/resource/execute_spec.rb +20 -12
  101. data/spec/unit/resource/file_spec.rb +10 -10
  102. data/spec/unit/resource/freebsd_package_spec.rb +16 -0
  103. data/spec/unit/resource/gem_package_spec.rb +27 -0
  104. data/spec/unit/resource/git_spec.rb +17 -2
  105. data/spec/unit/resource/group_spec.rb +18 -17
  106. data/spec/unit/resource/homebrew_cask_spec.rb +9 -4
  107. data/spec/unit/resource/homebrew_package_spec.rb +14 -0
  108. data/spec/unit/resource/homebrew_tap_spec.rb +8 -3
  109. data/spec/unit/resource/hostname_spec.rb +10 -6
  110. data/spec/unit/resource/http_request_spec.rb +14 -0
  111. data/spec/unit/resource/ips_package_spec.rb +15 -3
  112. data/spec/unit/resource/ksh_spec.rb +8 -0
  113. data/spec/unit/resource/launchd_spec.rb +11 -5
  114. data/spec/unit/resource/link_spec.rb +6 -11
  115. data/spec/unit/resource/log_spec.rb +8 -8
  116. data/spec/unit/resource/macos_user_defaults_spec.rb +5 -1
  117. data/spec/unit/resource/macports_package_spec.rb +19 -0
  118. data/spec/unit/resource/mdadm_spec.rb +7 -3
  119. data/spec/unit/resource/mount_spec.rb +15 -18
  120. data/spec/unit/resource/msu_package_spec.rb +10 -0
  121. data/spec/unit/resource/ohai_hint_spec.rb +9 -8
  122. data/spec/unit/resource/ohai_spec.rb +11 -3
  123. data/spec/unit/resource/openbsd_package_spec.rb +14 -0
  124. data/spec/unit/resource/openssl_dhparam.rb +10 -5
  125. data/spec/unit/resource/openssl_rsa_private_key_spec.rb +10 -5
  126. data/spec/unit/resource/openssl_rsa_public_key_spec.rb +9 -5
  127. data/spec/unit/resource/osx_profile_spec.rb +7 -4
  128. data/spec/unit/resource/package_spec.rb +14 -0
  129. data/spec/unit/resource/pacman_package_spec.rb +17 -3
  130. data/spec/unit/resource/paludis_package_spec.rb +36 -0
  131. data/spec/unit/resource/perl_spec.rb +8 -0
  132. data/spec/unit/resource/portage_package_spec.rb +14 -0
  133. data/spec/unit/resource/powershell_package_spec.rb +14 -0
  134. data/spec/unit/resource/python_spec.rb +8 -0
  135. data/spec/unit/resource/reboot_spec.rb +5 -3
  136. data/spec/unit/resource/registry_key_spec.rb +12 -1
  137. data/spec/unit/resource/remote_directory_spec.rb +11 -1
  138. data/spec/unit/resource/remote_file_spec.rb +19 -0
  139. data/spec/unit/resource/rhsm_errata_level_spec.rb +7 -3
  140. data/spec/unit/resource/rhsm_errata_spec.rb +8 -4
  141. data/spec/unit/resource/rhsm_register_spec.rb +6 -1
  142. data/spec/unit/resource/rhsm_repo_spec.rb +9 -4
  143. data/spec/unit/resource/rhsm_subscription_spec.rb +9 -4
  144. data/spec/unit/resource/route_spec.rb +4 -9
  145. data/spec/unit/resource/rpm_package_spec.rb +14 -0
  146. data/spec/unit/resource/ruby_block_spec.rb +12 -8
  147. data/spec/unit/resource/ruby_spec.rb +8 -0
  148. data/spec/unit/resource/scm_spec.rb +16 -8
  149. data/spec/unit/resource/script_spec.rb +8 -0
  150. data/spec/unit/resource/service_spec.rb +15 -0
  151. data/spec/unit/resource/smartos_package_spec.rb +18 -4
  152. data/spec/unit/resource/solaris_package_spec.rb +14 -0
  153. data/spec/unit/resource/subversion_spec.rb +14 -8
  154. data/spec/unit/resource/sudo_spec.rb +11 -4
  155. data/spec/unit/resource/swap_file_spec.rb +4 -5
  156. data/spec/unit/resource/sysctl_spec.rb +8 -10
  157. data/spec/unit/resource/systemd_unit_spec.rb +14 -12
  158. data/spec/unit/resource/template_spec.rb +19 -0
  159. data/spec/unit/resource/{windows_ad_join.rb → windows_ad_join_spec.rb} +12 -6
  160. data/spec/unit/resource/windows_auto_run_spec.rb +9 -9
  161. data/spec/unit/resource/windows_env_spec.rb +8 -16
  162. data/spec/unit/resource/windows_feature.rb +27 -8
  163. data/spec/unit/resource/windows_feature_dism.rb +30 -9
  164. data/spec/unit/resource/windows_feature_powershell.rb +7 -7
  165. data/spec/unit/resource/windows_font_spec.rb +3 -4
  166. data/spec/unit/resource/windows_package_spec.rb +12 -2
  167. data/spec/unit/resource/windows_pagefile_spec.rb +12 -8
  168. data/spec/unit/resource/windows_path_spec.rb +4 -5
  169. data/spec/unit/resource/windows_printer_port_spec.rb +20 -3
  170. data/spec/unit/resource/windows_printer_spec.rb +12 -5
  171. data/spec/unit/resource/windows_service_spec.rb +24 -1
  172. data/spec/unit/resource/windows_shortcut_spec.rb +4 -5
  173. data/spec/unit/resource/yum_repository_spec.rb +48 -2
  174. data/spec/unit/resource/zypper_package_spec.rb +51 -0
  175. data/spec/unit/resource/zypper_repository_spec.rb +56 -11
  176. data/spec/unit/resource_spec.rb +1 -5
  177. metadata +21 -12
  178. data/spec/functional/resource/user/useradd_spec.rb +0 -709
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2bd4dff7db3d6974b97656208d26294a91b879c4ac248a1f015ef8ba0e564c3
4
- data.tar.gz: c521620fdca29be30799f680c071d4ef38e84e302324f14c80fc748ed551e7e9
3
+ metadata.gz: 5003d5c03f9a495db071bcf2fd9dd28c5e302db2fa32dc6a47008eb1b2c7c01b
4
+ data.tar.gz: 9d2a707e2e0b1507f6a4f6a3be54896afaa78b6024ea1089cc6f575cf0963f8f
5
5
  SHA512:
6
- metadata.gz: 0075f0bf86d6bb18941e1e0f25f5d43b03b42e57c2fae1773088f514fe6d365979dd30bd21925dc5cefc82c02bf06972c58c64150c431af7de72e0f3f2208872
7
- data.tar.gz: 395cc71f09d88f45f1f11b30d4c3e0c777214c2faeeea44568eebbb681dc597531cef675e20c3498126e385671932f052ffebbfe1836565d0836463e39990b60
6
+ metadata.gz: 33ae86c180e12d7718def52255330f2aebc7e7ac00db9c10217aa9a750923baec6ede05983efb4f3ec0a890bc16c5ef6f13919f5dc07439656b510166dc7a180
7
+ data.tar.gz: b4f7f2e3aa6da47b4f5e5001db8568b0eb316e566e1f6cd8c2e757f4e05a081ada36375bfceede12761d1193c646074d11ee456223e63e2a022d4bbffda99c26
data/Gemfile CHANGED
@@ -11,14 +11,9 @@ gem "chef-config", path: File.expand_path("../chef-config", __FILE__) if File.ex
11
11
  gem "cheffish", "~> 14"
12
12
 
13
13
  group(:omnibus_package) do
14
- # override for unf_ext for inspec 2 until
15
- # https://github.com/knu/ruby-unf_ext/pull/39
16
- # is merged and released
17
- gem "unf_ext", "=0.0.7.6", :git => "https://github.com/jquick/ruby-unf_ext.git"
18
-
19
14
  gem "appbundler"
20
15
  gem "rb-readline"
21
- gem "inspec", "~> 2"
16
+ gem "inspec-core", "~> 2"
22
17
  gem "chef-vault"
23
18
  end
24
19
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 14.1.12
1
+ 14.2.0
@@ -19,13 +19,12 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.add_dependency "mixlib-cli", "~> 1.7"
21
21
  s.add_dependency "mixlib-log", "~> 2.0", ">= 2.0.3"
22
- s.add_dependency "mixlib-authentication", "~> 2.0"
22
+ s.add_dependency "mixlib-authentication", "~> 2.1"
23
23
  s.add_dependency "mixlib-shellout", "~> 2.0"
24
24
  s.add_dependency "mixlib-archive", "~> 0.4"
25
25
  s.add_dependency "ohai", "~> 14.0"
26
26
 
27
- # ffi 1.9.22+1.9.23 are buggy in our spec/unit/application/client_spec.rb tests on el6/el7
28
- s.add_dependency "ffi", "< 1.9.22"
27
+ s.add_dependency "ffi", "~> 1.9", ">= 1.9.25"
29
28
  s.add_dependency "ffi-yajl", "~> 2.2"
30
29
  s.add_dependency "net-ssh", "~> 4.2"
31
30
  s.add_dependency "net-ssh-multi", "~> 1.2", ">= 1.2.1"
@@ -63,11 +63,15 @@ class Chef
63
63
  def normalize_hash(object, defaults)
64
64
  # Make a normalized result in the specified order for diffing
65
65
  result = {}
66
- defaults.each_pair do |key, default|
67
- result[key] = object.has_key?(key) ? object[key] : default
66
+ defaults.each_pair do |key, value|
67
+ result[key] = object.is_a?(Hash) && object.key?(key) ? object[key] : value
68
68
  end
69
- object.each_pair do |key, value|
70
- result[key] = value if !result.has_key?(key)
69
+ if object.is_a?(Hash)
70
+ object.each_pair do |key, value|
71
+ result[key] = value unless result.key?(key)
72
+ end
73
+ else
74
+ Chef::Log.warn "Encountered invalid object during normalization. Using these defaults #{defaults}"
71
75
  end
72
76
  result
73
77
  end
@@ -31,7 +31,7 @@ class Chef
31
31
  response[:all_files] = COOKBOOK_SEGMENTS.inject([]) do |memo, segment|
32
32
  next memo if hash[segment].nil? || hash[segment].empty?
33
33
  hash[segment].each do |file|
34
- file["name"] = "#{segment}/#{file["name"]}" unless segment == "root_files"
34
+ file["name"] = "#{segment}/#{file["name"]}"
35
35
  memo << file
36
36
  end
37
37
  response.delete(segment)
@@ -49,7 +49,7 @@ class Chef
49
49
  if COOKBOOK_SEGMENTS.include?(parent)
50
50
  memo[parent] ||= []
51
51
  files[parent].each do |file|
52
- file["name"] = file["name"].split("/")[1] unless parent == "root_files"
52
+ file["name"] = file["name"].split("/")[1]
53
53
  file.delete("full_path")
54
54
  memo[parent] << file
55
55
  end
@@ -204,7 +204,8 @@ class Chef
204
204
 
205
205
  def root_files
206
206
  manifest[:all_files].select do |file|
207
- file[:name].split("/").length == 1
207
+ segment, name = file[:name].split("/")
208
+ name.nil? || segment == "root_files"
208
209
  end
209
210
  end
210
211
 
@@ -271,7 +272,7 @@ class Chef
271
272
  next if parts[0] == ".."
272
273
 
273
274
  # if we have a root_file, such as metadata.rb, the first part will be "."
274
- return [ pathname.to_s, pathname.to_s, "default" ] if parts.length == 1
275
+ return [ "root_files/#{pathname}", pathname.to_s, "default" ] if parts.length == 1
275
276
 
276
277
  segment = parts[0]
277
278
 
@@ -131,7 +131,7 @@ class Chef
131
131
  def attribute_filenames_by_short_filename
132
132
  @attribute_filenames_by_short_filename ||= begin
133
133
  name_map = filenames_by_name(files_for("attributes"))
134
- root_alias = cookbook_manifest.root_files.find { |record| record[:name] == "attributes.rb" }
134
+ root_alias = cookbook_manifest.root_files.find { |record| record[:name] == "root_files/attributes.rb" }
135
135
  name_map["default"] = root_alias[:full_path] if root_alias
136
136
  name_map
137
137
  end
@@ -140,7 +140,7 @@ class Chef
140
140
  def recipe_filenames_by_name
141
141
  @recipe_filenames_by_name ||= begin
142
142
  name_map = filenames_by_name(files_for("recipes"))
143
- root_alias = cookbook_manifest.root_files.find { |record| record[:name] == "recipe.rb" }
143
+ root_alias = cookbook_manifest.root_files.find { |record| record[:name] == "root_files/recipe.rb" }
144
144
  if root_alias
145
145
  Chef::Log.error("Cookbook #{name} contains both recipe.rb and and recipes/default.rb, ignoring recipes/default.rb") if name_map["default"]
146
146
  name_map["default"] = root_alias[:full_path]
@@ -239,6 +239,7 @@ class Chef
239
239
  filename.map { |name| " #{File.join(segment.to_s, name)}" }
240
240
  else
241
241
  [
242
+ " #{segment}/host-#{node[:fqdn]}/#{filename}",
242
243
  " #{segment}/#{node[:platform]}-#{node[:platform_version]}/#{filename}",
243
244
  " #{segment}/#{node[:platform]}/#{filename}",
244
245
  " #{segment}/default/#{filename}",
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Adam Edwards (<adamed@chef.io>)
3
- # Copyright:: Copyright 2014-2017, Chef Software Inc.
3
+ # Copyright:: Copyright 2014-2018, Chef Software Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -33,7 +33,7 @@ class Chef
33
33
  public
34
34
 
35
35
  def evaluate
36
- result = shell_out_with_systems_locale(@command, @command_opts)
36
+ result = shell_out(@command, default_env: false, **@command_opts)
37
37
  Chef::Log.debug "Command failed: #{result.stderr}" unless result.status.success?
38
38
  result.status.success?
39
39
  # Timeout fails command rather than chef-client run, see:
@@ -28,8 +28,10 @@ class Chef
28
28
  class AuthCredentials
29
29
  attr_reader :client_name, :key
30
30
 
31
- def initialize(client_name = nil, key = nil)
32
- @client_name, @key = client_name, key
31
+ def initialize(client_name = nil, key = nil, use_ssh_agent: false)
32
+ @client_name = client_name
33
+ @key = key
34
+ @use_ssh_agent = use_ssh_agent
33
35
  end
34
36
 
35
37
  def sign_requests?
@@ -48,7 +50,7 @@ class Chef
48
50
  host = request_params.delete(:host) || "localhost"
49
51
 
50
52
  sign_obj = Mixlib::Authentication::SignedHeaderAuth.signing_object(request_params)
51
- signed = sign_obj.sign(key).merge({ :host => host })
53
+ signed = sign_obj.sign(key, use_ssh_agent: @use_ssh_agent).merge({ :host => host })
52
54
  signed.inject({}) { |memo, kv| memo["#{kv[0].to_s.upcase}"] = kv[1]; memo }
53
55
  end
54
56
 
@@ -40,7 +40,7 @@ class Chef
40
40
  @sign_request = true
41
41
  @signing_key_filename = opts[:signing_key_filename]
42
42
  @key = load_signing_key(opts[:signing_key_filename], opts[:raw_key])
43
- @auth_credentials = AuthCredentials.new(opts[:client_name], @key)
43
+ @auth_credentials = AuthCredentials.new(opts[:client_name], @key, use_ssh_agent: opts[:ssh_agent_signing])
44
44
  @version_class = opts[:version_class]
45
45
  @api_version = opts[:api_version]
46
46
  end
@@ -89,12 +89,15 @@ class Chef
89
89
  else
90
90
  return nil
91
91
  end
92
- @key = OpenSSL::PKey::RSA.new(@raw_key)
92
+ # Pass in '' as the passphrase to avoid OpenSSL prompting on the TTY if
93
+ # given an encrypted key. This also helps if using a single file for
94
+ # both the public and private key with ssh-agent mode.
95
+ @key = OpenSSL::PKey::RSA.new(@raw_key, "")
93
96
  rescue SystemCallError, IOError => e
94
97
  Chef::Log.warn "Failed to read the private key #{key_file}: #{e.inspect}"
95
98
  raise Chef::Exceptions::PrivateKeyMissing, "I cannot read #{key_file}, which you told me to use to sign requests!"
96
99
  rescue OpenSSL::PKey::RSAError
97
- msg = "The file #{key_file} or :raw_key option does not contain a correctly formatted private key.\n"
100
+ msg = "The file #{key_file} or :raw_key option does not contain a correctly formatted private key or the key is encrypted.\n"
98
101
  msg << "The key file should begin with '-----BEGIN RSA PRIVATE KEY-----' and end with '-----END RSA PRIVATE KEY-----'"
99
102
  raise Chef::Exceptions::InvalidPrivateKey, msg
100
103
  end
@@ -234,7 +234,7 @@ class Chef
234
234
  end
235
235
  end
236
236
 
237
- OFFICIAL_PLUGINS = %w{ec2 rackspace windows openstack terremark bluebox}
237
+ OFFICIAL_PLUGINS = %w{ec2 rackspace windows openstack azure google linode push vcenter lpar}
238
238
 
239
239
  class << self
240
240
  def list_commands(preferred_category = nil)
@@ -258,7 +258,6 @@ class Chef
258
258
  caller_line.split(/:\d+/).first
259
259
  end
260
260
 
261
- # :nodoc:
262
261
  # Error out and print usage. probably because the arguments given by the
263
262
  # user could not be resolved to a subcommand.
264
263
  # @api private
@@ -272,10 +271,8 @@ class Chef
272
271
 
273
272
  if category_commands = guess_category(args)
274
273
  list_commands(category_commands)
275
- elsif missing_plugin = ( OFFICIAL_PLUGINS.find { |plugin| plugin == args[0] } )
276
- ui.info("The #{missing_plugin} commands were moved to plugins in Chef 0.10")
277
- ui.info("You can install the plugin with `(sudo) gem install knife-#{missing_plugin}`")
278
- ui.info("Use `chef gem install knife-#{missing_plugin}` instead if using ChefDK")
274
+ elsif OFFICIAL_PLUGINS.include?(args[0]) # command was an uninstalled official chef knife plugin
275
+ ui.info("Use `chef gem install knife-#{args[0]}` to install the plugin into ChefDK")
279
276
  else
280
277
  list_commands
281
278
  end
@@ -69,15 +69,12 @@ class Chef
69
69
 
70
70
  def run
71
71
  FileUtils.mkdir_p(chef_config_path)
72
- config_file = File.join(chef_config_path, "credentials")
73
72
 
74
73
  ask_user_for_config
75
74
 
76
- config_file = File.expand_path(config_file)
77
- if File.exist?(config_file)
78
- confirm("Overwrite #{config_file}")
79
- end
80
- ::File.open(config_file, "w") do |f|
75
+ confirm("Overwrite #{config_file_path}") if ::File.exist?(config_file_path)
76
+
77
+ ::File.open(config_file_path, "w") do |f|
81
78
  f.puts <<-EOH
82
79
  [default]
83
80
  client_name = '#{new_client_name}'
@@ -110,7 +107,7 @@ EOH
110
107
  ui.msg("*****")
111
108
  end
112
109
 
113
- ui.msg("Configuration file written to #{config[:config_file]}")
110
+ ui.msg("Knife configuration file written to #{config_file_path}")
114
111
  end
115
112
 
116
113
  def ask_user_for_config
@@ -129,14 +126,21 @@ EOH
129
126
  @new_client_key = File.expand_path(@new_client_key)
130
127
  end
131
128
 
129
+ # @return [String] our best guess at what the servername should be using Ohai data and falling back to localhost
132
130
  def guess_servername
133
131
  o = Ohai::System.new
134
132
  o.all_plugins(%w{ os hostname fqdn })
135
133
  o[:fqdn] || o[:machinename] || o[:hostname] || "localhost"
136
134
  end
137
135
 
136
+ # @return [String] the path to the user's .chef directory
138
137
  def chef_config_path
139
- Chef::Util::PathHelper.home(".chef")
138
+ @chef_config_path ||= Chef::Util::PathHelper.home(".chef")
139
+ end
140
+
141
+ # @return [String] the full path to the config file (credential file)
142
+ def config_file_path
143
+ @config_file_path ||= ::File.expand_path(::File.join(chef_config_path, "credentials"))
140
144
  end
141
145
  end
142
146
  end
@@ -39,10 +39,15 @@ class Chef
39
39
  :default => false,
40
40
  :description => "Use webui proxy authentication. Client key must be the webui key."
41
41
 
42
+ # We need a custom HTTP client class here because we don't want to even
43
+ # try to decode the body, in case we get back corrupted JSON or whatnot.
42
44
  class RawInputServerAPI < Chef::HTTP
43
45
  def initialize(options = {})
46
+ # If making a change here, also update Chef::ServerAPI.
44
47
  options[:client_name] ||= Chef::Config[:node_name]
45
- options[:signing_key_filename] ||= Chef::Config[:client_key]
48
+ options[:raw_key] ||= Chef::Config[:client_key_contents]
49
+ options[:signing_key_filename] ||= Chef::Config[:client_key] unless options[:raw_key]
50
+ options[:ssh_agent_signing] ||= Chef::Config[:ssh_agent_signing]
46
51
  super(Chef::Config[:chef_server_url], options)
47
52
  end
48
53
  use Chef::HTTP::JSONOutput
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # Author:: Daniel DeLeo (<dan@chef.io>)
3
- # Copyright:: Copyright 2010-2017, Chef Software Inc.
3
+ # Copyright:: Copyright 2010-2018, Chef Software Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -104,13 +104,17 @@ class Chef
104
104
  # generally must support UTF-8 unicode.
105
105
  def shell_out(*args, **options)
106
106
  options = options.dup
107
- env_key = options.has_key?(:env) ? :env : :environment
108
- options[env_key] = {
109
- "LC_ALL" => Chef::Config[:internal_locale],
110
- "LANGUAGE" => Chef::Config[:internal_locale],
111
- "LANG" => Chef::Config[:internal_locale],
112
- env_path => sanitized_path,
113
- }.update(options[env_key] || {})
107
+ default_env = options.delete(:default_env)
108
+ default_env = true if default_env.nil?
109
+ if default_env
110
+ env_key = options.key?(:env) ? :env : :environment
111
+ options[env_key] = {
112
+ "LC_ALL" => Chef::Config[:internal_locale],
113
+ "LANGUAGE" => Chef::Config[:internal_locale],
114
+ "LANG" => Chef::Config[:internal_locale],
115
+ env_path => sanitized_path,
116
+ }.update(options[env_key] || {})
117
+ end
114
118
  shell_out_command(*args, **options)
115
119
  end
116
120
 
@@ -121,14 +125,12 @@ class Chef
121
125
  cmd
122
126
  end
123
127
 
124
- def shell_out_with_systems_locale(*command_args)
125
- shell_out_command(*command_args)
128
+ def shell_out_with_systems_locale(*args, **options) # FIXME: deprecate
129
+ shell_out(*args, default_env: false, **options)
126
130
  end
127
131
 
128
- def shell_out_with_systems_locale!(*command_args)
129
- cmd = shell_out_with_systems_locale(*command_args)
130
- cmd.error!
131
- cmd
132
+ def shell_out_with_systems_locale!(*args, **options) # FIXME: deprecate
133
+ shell_out!(*args, default_env: false, **options)
132
134
  end
133
135
 
134
136
  # Helper for subclasses to convert an array of string args into a string. It
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@chef.io>)
3
- # Copyright:: Copyright 2008-2017, Chef Software Inc.
3
+ # Copyright:: Copyright 2008-2018, Chef Software Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,7 +27,7 @@ class Chef
27
27
 
28
28
  provides :execute
29
29
 
30
- def_delegators :new_resource, :command, :returns, :environment, :user, :domain, :password, :group, :cwd, :umask, :creates, :elevated
30
+ def_delegators :new_resource, :command, :returns, :environment, :user, :domain, :password, :group, :cwd, :umask, :creates, :elevated, :default_env
31
31
 
32
32
  def load_current_resource
33
33
  current_resource = Chef::Resource::Execute.new(new_resource.name)
@@ -55,7 +55,7 @@ class Chef
55
55
 
56
56
  converge_by("execute #{description}") do
57
57
  begin
58
- shell_out_with_systems_locale!(command, opts)
58
+ shell_out!(command, opts)
59
59
  rescue Mixlib::ShellOut::ShellCommandFailed
60
60
  if sensitive?
61
61
  ex = Mixlib::ShellOut::ShellCommandFailed.new("Command execution failed. STDOUT/STDERR suppressed for sensitive resource")
@@ -97,6 +97,7 @@ class Chef
97
97
  opts[:group] = group if group
98
98
  opts[:cwd] = cwd if cwd
99
99
  opts[:umask] = umask if umask
100
+ opts[:default_env] = default_env
100
101
  opts[:log_level] = :info
101
102
  opts[:log_tag] = new_resource.to_s
102
103
  if (logger.info? || live_stream?) && !sensitive?
@@ -213,7 +213,7 @@ class Chef
213
213
  # which we can fix by replacing them all with our target url (hence the --replace-all option)
214
214
 
215
215
  if multiple_remotes?(remote_status) || !remote_matches?(remote_url, remote_status)
216
- git("config", "--replace-all", "remote.#{remote_name}.url", remote_url, cwd: cwd)
216
+ git("config", "--replace-all", "remote.#{remote_name}.url", %{"#{remote_url}"}, cwd: cwd)
217
217
  end
218
218
  when 1
219
219
  git("remote", "add", remote_name, remote_url, cwd: cwd)
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright 2016-2017, Chef Software Inc.
2
+ # Copyright:: Copyright 2016-2018, Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -95,10 +95,10 @@ class Chef
95
95
 
96
96
  def install_package(names, versions)
97
97
  if new_resource.source
98
- dnf(options, "-y install", new_resource.source)
98
+ dnf(options, "-y", "install", new_resource.source)
99
99
  else
100
100
  resolved_names = names.each_with_index.map { |name, i| available_version(i).to_s unless name.nil? }
101
- dnf(options, "-y install", resolved_names)
101
+ dnf(options, "-y", "install", resolved_names)
102
102
  end
103
103
  flushcache
104
104
  end
@@ -108,7 +108,7 @@ class Chef
108
108
 
109
109
  def remove_package(names, versions)
110
110
  resolved_names = names.each_with_index.map { |name, i| installed_version(i).to_s unless name.nil? }
111
- dnf(options, "-y remove", resolved_names)
111
+ dnf(options, "-y", "remove", resolved_names)
112
112
  flushcache
113
113
  end
114
114
 
@@ -167,7 +167,7 @@ class Chef
167
167
  end
168
168
 
169
169
  def dnf(*args)
170
- shell_out_with_timeout!(a_to_s("dnf", *args))
170
+ shell_out_compact_timeout!("dnf", *args)
171
171
  end
172
172
 
173
173
  def safe_version_array
@@ -39,6 +39,13 @@ class Chef
39
39
  a.assertion { new_resource.source || msi? }
40
40
  a.failure_message Chef::Exceptions::NoWindowsPackageSource, "Source for package #{new_resource.name} must be specified in the resource's source property for package to be installed because the package_name property is used to test for the package installation state for this package type."
41
41
  end
42
+
43
+ unless uri_scheme?(new_resource.source)
44
+ requirements.assert(:install) do |a|
45
+ a.assertion { ::File.exist?(new_resource.source) }
46
+ a.failure_message Chef::Exceptions::Package, "Source for package #{new_resource.name} does not exist"
47
+ end
48
+ end
42
49
  end
43
50
 
44
51
  # load_current_resource is run in Chef::Provider#run_action when not in whyrun_mode?
@@ -117,10 +117,10 @@ class Chef
117
117
  end
118
118
 
119
119
  if new_resource.source
120
- yum(options, "-y #{method}", new_resource.source)
120
+ yum(options, "-y", method, new_resource.source)
121
121
  else
122
122
  resolved_names = names.each_with_index.map { |name, i| available_version(i).to_s unless name.nil? }
123
- yum(options, "-y #{method}", resolved_names)
123
+ yum(options, "-y", method, resolved_names)
124
124
  end
125
125
  flushcache
126
126
  end
@@ -130,7 +130,7 @@ class Chef
130
130
 
131
131
  def remove_package(names, versions)
132
132
  resolved_names = names.each_with_index.map { |name, i| installed_version(i).to_s unless name.nil? }
133
- yum(options, "-y remove", resolved_names)
133
+ yum(options, "-y", "remove", resolved_names)
134
134
  flushcache
135
135
  end
136
136
 
@@ -143,14 +143,14 @@ class Chef
143
143
  # NB: the yum_package provider manages individual single packages, please do not submit issues or PRs to try to add wildcard
144
144
  # support to lock / unlock. The best solution is to write an execute resource which does a not_if `yum versionlock | grep '^pattern`` kind of approach
145
145
  def lock_package(names, versions)
146
- yum("-d0 -e0 -y", options, "versionlock add", resolved_package_lock_names(names))
146
+ yum("-d0", "-e0", "-y", options, "versionlock", "add", resolved_package_lock_names(names))
147
147
  end
148
148
 
149
149
  # NB: the yum_package provider manages individual single packages, please do not submit issues or PRs to try to add wildcard
150
150
  # support to lock / unlock. The best solution is to write an execute resource which does a only_if `yum versionlock | grep '^pattern`` kind of approach
151
151
  def unlock_package(names, versions)
152
152
  # yum versionlock delete on rhel6 needs the glob nonsense in the following command
153
- yum("-d0 -e0 -y", options, "versionlock delete", resolved_package_lock_names(names).map { |n| "'*:#{n}-*'" })
153
+ yum("-d0", "-e0", "-y", options, "versionlock", "delete", resolved_package_lock_names(names).map { |n| "*:#{n}-*" })
154
154
  end
155
155
 
156
156
  private
@@ -171,7 +171,7 @@ class Chef
171
171
  def locked_packages
172
172
  @locked_packages ||=
173
173
  begin
174
- locked = shell_out_with_timeout!("yum versionlock list")
174
+ locked = yum("versionlock", "list")
175
175
  locked.stdout.each_line.map do |line|
176
176
  line.sub(/-[^-]*-[^-]*$/, "").split(":").last.strip
177
177
  end
@@ -260,7 +260,7 @@ class Chef
260
260
  end
261
261
 
262
262
  def yum(*args)
263
- shell_out_with_timeout!(a_to_s(yum_binary, *args))
263
+ shell_out_compact_timeout!(yum_binary, *args)
264
264
  end
265
265
 
266
266
  def safe_version_array