chef 16.3.45-universal-mingw32 → 16.4.35-universal-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/chef-universal-mingw32.gemspec +0 -1
  3. data/lib/chef/action_collection.rb +4 -0
  4. data/lib/chef/api_client/registration.rb +2 -2
  5. data/lib/chef/application.rb +1 -1
  6. data/lib/chef/application/apply.rb +5 -5
  7. data/lib/chef/application/windows_service.rb +27 -27
  8. data/lib/chef/chef_class.rb +0 -1
  9. data/lib/chef/chef_fs/chef_fs_data_store.rb +54 -54
  10. data/lib/chef/chef_fs/file_system/chef_server/acl_entry.rb +10 -10
  11. data/lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb +8 -8
  12. data/lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb +8 -8
  13. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb +2 -2
  14. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +1 -1
  15. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +18 -18
  16. data/lib/chef/chef_fs/file_system/repository/directory.rb +1 -1
  17. data/lib/chef/chef_fs/file_system/repository/file_system_entry.rb +1 -1
  18. data/lib/chef/client.rb +11 -11
  19. data/lib/chef/data_collector/run_end_message.rb +11 -1
  20. data/lib/chef/dsl/platform_introspection.rb +8 -8
  21. data/lib/chef/encrypted_data_bag_item/decryptor.rb +1 -1
  22. data/lib/chef/environment.rb +2 -2
  23. data/lib/chef/exceptions.rb +1 -1
  24. data/lib/chef/file_content_management/tempfile.rb +9 -9
  25. data/lib/chef/http.rb +2 -1
  26. data/lib/chef/json_compat.rb +1 -1
  27. data/lib/chef/knife/bootstrap.rb +2 -2
  28. data/lib/chef/knife/cookbook_download.rb +1 -1
  29. data/lib/chef/knife/cookbook_metadata.rb +1 -1
  30. data/lib/chef/knife/cookbook_upload.rb +23 -23
  31. data/lib/chef/knife/core/generic_presenter.rb +1 -1
  32. data/lib/chef/knife/core/hashed_command_loader.rb +2 -2
  33. data/lib/chef/knife/core/windows_bootstrap_context.rb +32 -24
  34. data/lib/chef/knife/delete.rb +15 -15
  35. data/lib/chef/knife/exec.rb +2 -2
  36. data/lib/chef/knife/ssh.rb +6 -6
  37. data/lib/chef/knife/xargs.rb +19 -19
  38. data/lib/chef/knife/yaml_convert.rb +1 -1
  39. data/lib/chef/mixin/checksum.rb +0 -1
  40. data/lib/chef/mixin/deep_merge.rb +35 -6
  41. data/lib/chef/mixin/openssl_helper.rb +3 -1
  42. data/lib/chef/mixin/shell_out.rb +1 -1
  43. data/lib/chef/mixin/which.rb +1 -1
  44. data/lib/chef/monkey_patches/webrick-utils.rb +10 -10
  45. data/lib/chef/node/attribute.rb +2 -4
  46. data/lib/chef/platform/service_helpers.rb +1 -1
  47. data/lib/chef/property.rb +1 -1
  48. data/lib/chef/provider/cron/unix.rb +0 -2
  49. data/lib/chef/provider/git.rb +5 -5
  50. data/lib/chef/provider/group.rb +0 -2
  51. data/lib/chef/provider/group/suse.rb +5 -5
  52. data/lib/chef/provider/ifconfig.rb +1 -4
  53. data/lib/chef/provider/mount.rb +0 -2
  54. data/lib/chef/provider/package.rb +0 -2
  55. data/lib/chef/provider/package/rubygems.rb +1 -1
  56. data/lib/chef/provider/package/snap.rb +1 -1
  57. data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +9 -9
  58. data/lib/chef/provider/powershell_script.rb +21 -5
  59. data/lib/chef/provider/route.rb +1 -1
  60. data/lib/chef/provider/service/arch.rb +1 -1
  61. data/lib/chef/provider/service/debian.rb +1 -1
  62. data/lib/chef/provider/service/gentoo.rb +2 -2
  63. data/lib/chef/provider/service/macosx.rb +2 -2
  64. data/lib/chef/provider/service/openbsd.rb +1 -4
  65. data/lib/chef/provider/service/redhat.rb +2 -2
  66. data/lib/chef/provider/service/upstart.rb +1 -1
  67. data/lib/chef/provider/service/windows.rb +10 -10
  68. data/lib/chef/provider/systemd_unit.rb +0 -2
  69. data/lib/chef/provider/template/content.rb +1 -0
  70. data/lib/chef/provider/user/dscl.rb +2 -2
  71. data/lib/chef/provider/user/mac.rb +9 -9
  72. data/lib/chef/provider/windows_task.rb +0 -3
  73. data/lib/chef/provider/zypper_repository.rb +0 -1
  74. data/lib/chef/providers.rb +0 -1
  75. data/lib/chef/recipe.rb +1 -1
  76. data/lib/chef/resource.rb +6 -10
  77. data/lib/chef/resource/apt_repository.rb +1 -10
  78. data/lib/chef/resource/chef_client_systemd_timer.rb +2 -2
  79. data/lib/chef/resource/chef_vault_secret.rb +13 -13
  80. data/lib/chef/resource/execute.rb +2 -3
  81. data/lib/chef/resource/homebrew_update.rb +2 -2
  82. data/lib/chef/resource/openssl_dhparam.rb +2 -0
  83. data/lib/chef/resource/openssl_ec_private_key.rb +2 -0
  84. data/lib/chef/resource/openssl_ec_public_key.rb +2 -0
  85. data/lib/chef/resource/openssl_rsa_private_key.rb +2 -0
  86. data/lib/chef/resource/openssl_rsa_public_key.rb +2 -0
  87. data/lib/chef/resource/openssl_x509_certificate.rb +24 -21
  88. data/lib/chef/resource/openssl_x509_crl.rb +2 -0
  89. data/lib/chef/resource/openssl_x509_request.rb +23 -20
  90. data/lib/chef/resource/osx_profile.rb +227 -5
  91. data/lib/chef/resource/powershell_package_source.rb +1 -1
  92. data/lib/chef/resource/powershell_script.rb +24 -30
  93. data/lib/chef/resource/sudo.rb +1 -1
  94. data/lib/chef/resource/sysctl.rb +5 -5
  95. data/lib/chef/resource/windows_ad_join.rb +2 -0
  96. data/lib/chef/resource/windows_audit_policy.rb +3 -0
  97. data/lib/chef/resource/windows_auto_run.rb +2 -0
  98. data/lib/chef/resource/windows_certificate.rb +2 -0
  99. data/lib/chef/resource/windows_dfs_folder.rb +2 -0
  100. data/lib/chef/resource/windows_dfs_namespace.rb +2 -0
  101. data/lib/chef/resource/windows_dfs_server.rb +2 -0
  102. data/lib/chef/resource/windows_dns_record.rb +10 -7
  103. data/lib/chef/resource/windows_dns_zone.rb +12 -7
  104. data/lib/chef/resource/windows_feature.rb +2 -0
  105. data/lib/chef/resource/windows_feature_dism.rb +10 -0
  106. data/lib/chef/resource/windows_feature_powershell.rb +14 -2
  107. data/lib/chef/resource/windows_firewall_profile.rb +4 -2
  108. data/lib/chef/resource/windows_firewall_rule.rb +5 -3
  109. data/lib/chef/resource/windows_font.rb +3 -1
  110. data/lib/chef/resource/windows_pagefile.rb +4 -0
  111. data/lib/chef/resource/windows_printer.rb +17 -18
  112. data/lib/chef/resource/windows_printer_port.rb +14 -13
  113. data/lib/chef/resource/windows_security_policy.rb +2 -0
  114. data/lib/chef/resource/windows_share.rb +5 -3
  115. data/lib/chef/resource/windows_shortcut.rb +2 -0
  116. data/lib/chef/resource/windows_uac.rb +2 -0
  117. data/lib/chef/resource/windows_user_privilege.rb +2 -0
  118. data/lib/chef/resource/windows_workgroup.rb +2 -3
  119. data/lib/chef/resource_collection/stepable_iterator.rb +1 -2
  120. data/lib/chef/role.rb +2 -2
  121. data/lib/chef/run_context/cookbook_compiler.rb +20 -20
  122. data/lib/chef/run_status.rb +2 -6
  123. data/lib/chef/shell.rb +1 -1
  124. data/lib/chef/util/backup.rb +1 -1
  125. data/lib/chef/util/diff.rb +11 -11
  126. data/lib/chef/util/powershell/cmdlet.rb +1 -1
  127. data/lib/chef/version.rb +1 -1
  128. data/lib/chef/win32/file.rb +2 -2
  129. data/lib/chef/win32/file/version_info.rb +5 -5
  130. data/spec/data/ssl/chef-rspec.cert +15 -15
  131. data/spec/functional/resource/aixinit_service_spec.rb +7 -7
  132. data/spec/functional/resource/bff_spec.rb +2 -2
  133. data/spec/functional/resource/cookbook_file_spec.rb +1 -1
  134. data/spec/functional/resource/dsc_resource_spec.rb +1 -1
  135. data/spec/functional/resource/dsc_script_spec.rb +0 -1
  136. data/spec/functional/resource/group_spec.rb +6 -6
  137. data/spec/functional/resource/insserv_spec.rb +4 -4
  138. data/spec/functional/resource/link_spec.rb +20 -20
  139. data/spec/functional/resource/powershell_script_spec.rb +4 -4
  140. data/spec/functional/resource/rpm_spec.rb +2 -2
  141. data/spec/functional/resource/windows_certificate_spec.rb +3 -3
  142. data/spec/functional/resource/windows_font_spec.rb +49 -0
  143. data/spec/functional/resource/windows_security_policy_spec.rb +0 -3
  144. data/spec/functional/run_lock_spec.rb +24 -24
  145. data/spec/functional/win32/registry_spec.rb +8 -8
  146. data/spec/functional/win32/service_manager_spec.rb +1 -1
  147. data/spec/integration/knife/common_options_spec.rb +12 -12
  148. data/spec/integration/knife/config_get_profile_spec.rb +69 -68
  149. data/spec/integration/knife/config_get_spec.rb +126 -125
  150. data/spec/integration/knife/config_list_profiles_spec.rb +181 -180
  151. data/spec/integration/knife/config_use_profile_spec.rb +110 -109
  152. data/spec/integration/knife/diff_spec.rb +3 -1
  153. data/spec/integration/knife/download_spec.rb +3 -1
  154. data/spec/integration/knife/serve_spec.rb +5 -5
  155. data/spec/integration/knife/upload_spec.rb +3 -1
  156. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +1 -1
  157. data/spec/spec_helper.rb +6 -6
  158. data/spec/support/platform_helpers.rb +9 -9
  159. data/spec/support/platforms/win32/spec_service.rb +1 -1
  160. data/spec/support/shared/functional/directory_resource.rb +1 -1
  161. data/spec/support/shared/functional/execute_resource.rb +1 -1
  162. data/spec/support/shared/functional/file_resource.rb +20 -20
  163. data/spec/support/shared/functional/win32_service.rb +1 -1
  164. data/spec/support/shared/functional/windows_script.rb +3 -3
  165. data/spec/support/shared/integration/integration_helper.rb +22 -52
  166. data/spec/support/shared/unit/script_resource.rb +6 -20
  167. data/spec/support/shared/unit/windows_script_resource.rb +15 -28
  168. data/spec/unit/data_collector_spec.rb +22 -0
  169. data/spec/unit/environment_spec.rb +7 -7
  170. data/spec/unit/knife/bootstrap_spec.rb +14 -14
  171. data/spec/unit/knife/cookbook_download_spec.rb +4 -4
  172. data/spec/unit/knife/cookbook_metadata_from_file_spec.rb +1 -1
  173. data/spec/unit/knife/core/hashed_command_loader_spec.rb +3 -3
  174. data/spec/unit/knife/core/windows_bootstrap_context_spec.rb +21 -12
  175. data/spec/unit/knife/supermarket_share_spec.rb +1 -1
  176. data/spec/unit/mixin/template_spec.rb +30 -30
  177. data/spec/unit/mixin/windows_architecture_helper_spec.rb +4 -4
  178. data/spec/unit/node/immutable_collections_spec.rb +6 -2
  179. data/spec/unit/node_spec.rb +5 -5
  180. data/spec/unit/provider/powershell_script_spec.rb +11 -4
  181. data/spec/unit/provider/remote_directory_spec.rb +9 -9
  182. data/spec/unit/provider/service/arch_service_spec.rb +3 -2
  183. data/spec/unit/provider/service/debian_service_spec.rb +1 -1
  184. data/spec/unit/provider/service/gentoo_service_spec.rb +7 -7
  185. data/spec/unit/provider/service/macosx_spec.rb +3 -3
  186. data/spec/unit/provider/service/redhat_spec.rb +2 -2
  187. data/spec/unit/provider/service/upstart_service_spec.rb +3 -3
  188. data/spec/unit/provider_resolver_spec.rb +6 -6
  189. data/spec/unit/resource/batch_spec.rb +6 -6
  190. data/spec/unit/resource/execute_spec.rb +113 -118
  191. data/spec/unit/resource/osx_profile_spec.rb +233 -0
  192. data/spec/unit/resource/powershell_script_spec.rb +11 -29
  193. data/spec/unit/resource/script_spec.rb +6 -1
  194. data/spec/unit/resource/windows_feature_powershell_spec.rb +30 -4
  195. data/spec/unit/role_spec.rb +11 -11
  196. data/tasks/rspec.rb +1 -1
  197. metadata +7 -22
  198. data/lib/chef/provider/osx_profile.rb +0 -255
  199. data/spec/unit/provider/osx_profile_spec.rb +0 -255
@@ -151,7 +151,7 @@ class Chef
151
151
  end
152
152
 
153
153
  def exists?
154
- File.exists?(file_path)
154
+ File.exist?(file_path)
155
155
  end
156
156
 
157
157
  protected
@@ -122,7 +122,7 @@ class Chef
122
122
  end
123
123
 
124
124
  def exists?
125
- File.exists?(file_path) && (parent.nil? || parent.can_have_child?(name, dir?))
125
+ File.exist?(file_path) && (parent.nil? || parent.can_have_child?(name, dir?))
126
126
  end
127
127
 
128
128
  def read
@@ -54,7 +54,7 @@ require_relative "platform/rebooter"
54
54
  require_relative "mixin/deprecation"
55
55
  require "chef-utils" unless defined?(ChefUtils::CANARY)
56
56
  require "ohai" unless defined?(Ohai::System)
57
- require "rbconfig"
57
+ require "rbconfig" unless defined?(RbConfig)
58
58
  require_relative "dist"
59
59
  require "forwardable" unless defined?(Forwardable)
60
60
 
@@ -707,16 +707,16 @@ class Chef
707
707
  #
708
708
  def converge(run_context)
709
709
  catch(:end_client_run_early) do
710
- begin
711
- events.converge_start(run_context)
712
- logger.debug("Converging node #{node_name}")
713
- @runner = Chef::Runner.new(run_context)
714
- @runner.converge
715
- events.converge_complete
716
- rescue Exception => e
717
- events.converge_failed(e)
718
- raise e
719
- end
710
+
711
+ events.converge_start(run_context)
712
+ logger.debug("Converging node #{node_name}")
713
+ @runner = Chef::Runner.new(run_context)
714
+ @runner.converge
715
+ events.converge_complete
716
+ rescue Exception => e
717
+ events.converge_failed(e)
718
+ raise e
719
+
720
720
  end
721
721
  end
722
722
 
@@ -133,7 +133,17 @@ class Chef
133
133
  end
134
134
 
135
135
  hash["conditional"] = action_record.conditional.to_text if action_record.status == :skipped
136
- hash["error_message"] = action_record.exception.message unless action_record.exception.nil?
136
+
137
+ unless action_record.exception.nil?
138
+ hash["error_message"] = action_record.exception.message
139
+
140
+ hash["error"] = {
141
+ "class" => action_record.exception.class,
142
+ "message" => action_record.exception.message,
143
+ "backtrace" => action_record.exception.backtrace,
144
+ "description" => action_record.error_description,
145
+ }
146
+ end
137
147
 
138
148
  hash
139
149
  end
@@ -17,7 +17,7 @@
17
17
  #
18
18
 
19
19
  require "chef-utils" unless defined?(ChefUtils::CANARY)
20
- require "chef/mixin/chef_utils_wiring" unless defined?(Chef::Mixin::ChefUtilsWiring)
20
+ require_relative "../mixin/chef_utils_wiring" unless defined?(Chef::Mixin::ChefUtilsWiring)
21
21
 
22
22
  class Chef
23
23
  module DSL
@@ -79,14 +79,14 @@ class Chef
79
79
  key_matches = []
80
80
  keys = @values[platform].keys
81
81
  keys.each do |k|
82
- begin
83
- if Chef::VersionConstraint::Platform.new(k).include?(node_version)
84
- key_matches << k
85
- end
86
- rescue Chef::Exceptions::InvalidVersionConstraint => e
87
- Chef::Log.trace "Caught InvalidVersionConstraint. This means that a key in value_for_platform cannot be interpreted as a Chef::VersionConstraint::Platform."
88
- Chef::Log.trace(e)
82
+
83
+ if Chef::VersionConstraint::Platform.new(k).include?(node_version)
84
+ key_matches << k
89
85
  end
86
+ rescue Chef::Exceptions::InvalidVersionConstraint => e
87
+ Chef::Log.trace "Caught InvalidVersionConstraint. This means that a key in value_for_platform cannot be interpreted as a Chef::VersionConstraint::Platform."
88
+ Chef::Log.trace(e)
89
+
90
90
  end
91
91
  return @values[platform][version] if key_matches.include?(version)
92
92
 
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "yaml"
19
+ require "yaml" unless defined?(YAML)
20
20
  require_relative "../json_compat"
21
21
  require "openssl" unless defined?(OpenSSL)
22
22
  require "base64"
@@ -254,11 +254,11 @@ class Chef
254
254
  js_file = File.join(Chef::Config[:environment_path], "#{name}.json")
255
255
  rb_file = File.join(Chef::Config[:environment_path], "#{name}.rb")
256
256
 
257
- if File.exists?(js_file)
257
+ if File.exist?(js_file)
258
258
  # from_json returns object.class => json_class in the JSON.
259
259
  hash = Chef::JSONCompat.parse(IO.read(js_file))
260
260
  from_hash(hash)
261
- elsif File.exists?(rb_file)
261
+ elsif File.exist?(rb_file)
262
262
  environment = Chef::Environment.new
263
263
  environment.name(name)
264
264
  environment.from_file(rb_file)
@@ -423,7 +423,7 @@ class Chef
423
423
 
424
424
  class ChecksumMismatch < RuntimeError
425
425
  def initialize(res_cksum, cont_cksum)
426
- super "Checksum on resource (#{res_cksum}) does not match checksum on content (#{cont_cksum})"
426
+ super "Checksum on resource (#{res_cksum}...) does not match checksum on content (#{cont_cksum}...)"
427
427
  end
428
428
  end
429
429
 
@@ -39,15 +39,15 @@ class Chef
39
39
  errors = [ ]
40
40
 
41
41
  tempfile_dirnames.each do |tempfile_dirname|
42
- begin
43
- # preserving the file extension of the target filename should be considered a public API
44
- tf = ::Tempfile.open([tempfile_basename, tempfile_extension], tempfile_dirname)
45
- break
46
- rescue SystemCallError => e
47
- message = "Creating temp file under '#{tempfile_dirname}' failed with: '#{e.message}'"
48
- Chef::Log.trace(message)
49
- errors << message
50
- end
42
+
43
+ # preserving the file extension of the target filename should be considered a public API
44
+ tf = ::Tempfile.open([tempfile_basename, tempfile_extension], tempfile_dirname)
45
+ break
46
+ rescue SystemCallError => e
47
+ message = "Creating temp file under '#{tempfile_dirname}' failed with: '#{e.message}'"
48
+ Chef::Log.trace(message)
49
+ errors << message
50
+
51
51
  end
52
52
 
53
53
  raise Chef::Exceptions::FileContentStagingError, errors if tf.nil?
@@ -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"
@@ -20,7 +20,7 @@
20
20
  require "ffi_yajl" unless defined?(FFI_Yajl)
21
21
  require_relative "exceptions"
22
22
  # We're requiring this to prevent breaking consumers using Hash.to_json
23
- require "json"
23
+ require "json" unless defined?(JSON)
24
24
 
25
25
  class Chef
26
26
  class JSONCompat
@@ -480,7 +480,7 @@ class Chef
480
480
  template = bootstrap_template
481
481
 
482
482
  # Use the template directly if it's a path to an actual file
483
- if File.exists?(template)
483
+ if File.exist?(template)
484
484
  Chef::Log.trace("Using the specified bootstrap template: #{File.dirname(template)}")
485
485
  return template
486
486
  end
@@ -495,7 +495,7 @@ class Chef
495
495
 
496
496
  template_file = Array(bootstrap_files).find do |bootstrap_template|
497
497
  Chef::Log.trace("Looking for bootstrap template in #{File.dirname(bootstrap_template)}")
498
- File.exists?(bootstrap_template)
498
+ File.exist?(bootstrap_template)
499
499
  end
500
500
 
501
501
  unless template_file
@@ -73,7 +73,7 @@ class Chef
73
73
  manifest = cookbook.cookbook_manifest
74
74
 
75
75
  basedir = File.join(config[:download_directory], "#{@cookbook_name}-#{cookbook.version}")
76
- if File.exists?(basedir)
76
+ if File.exist?(basedir)
77
77
  if config[:force]
78
78
  Chef::Log.trace("Deleting #{basedir}")
79
79
  FileUtils.rm_rf(basedir)
@@ -62,7 +62,7 @@ class Chef
62
62
  def generate_metadata(cookbook)
63
63
  Array(config[:cookbook_path]).reverse_each do |path|
64
64
  file = File.expand_path(File.join(path, cookbook, "metadata.rb"))
65
- if File.exists?(file)
65
+ if File.exist?(file)
66
66
  generate_metadata_from_file(cookbook, file)
67
67
  else
68
68
  validate_metadata_json(path, cookbook)
@@ -132,20 +132,20 @@ class Chef
132
132
  end
133
133
  else
134
134
  tmp_cl.each do |cookbook_name, cookbook|
135
- begin
136
- upload([cookbook], justify_width)
137
- upload_ok += 1
138
- rescue Exceptions::CookbookNotFoundInRepo => e
139
- upload_failures += 1
140
- ui.error("Could not find cookbook #{cookbook_name} in your cookbook path, skipping it")
141
- Log.debug(e)
142
- upload_failures += 1
143
- rescue Exceptions::CookbookFrozen
144
- ui.warn("Not updating version constraints for #{cookbook_name} in the environment as the cookbook is frozen.")
145
- upload_failures += 1
146
- rescue SystemExit => e
147
- raise exit e.status
148
- end
135
+
136
+ upload([cookbook], justify_width)
137
+ upload_ok += 1
138
+ rescue Exceptions::CookbookNotFoundInRepo => e
139
+ upload_failures += 1
140
+ ui.error("Could not find cookbook #{cookbook_name} in your cookbook path, skipping it")
141
+ Log.debug(e)
142
+ upload_failures += 1
143
+ rescue Exceptions::CookbookFrozen
144
+ ui.warn("Not updating version constraints for #{cookbook_name} in the environment as the cookbook is frozen.")
145
+ upload_failures += 1
146
+ rescue SystemExit => e
147
+ raise exit e.status
148
+
149
149
  end
150
150
 
151
151
  if upload_failures == 0
@@ -172,17 +172,17 @@ class Chef
172
172
  else
173
173
  upload_set = {}
174
174
  @name_args.each do |cookbook_name|
175
- begin
176
- unless upload_set.key?(cookbook_name)
177
- upload_set[cookbook_name] = cookbook_repo[cookbook_name]
178
- if config[:depends]
179
- upload_set[cookbook_name].metadata.dependencies.each_key { |dep| @name_args << dep }
180
- end
175
+
176
+ unless upload_set.key?(cookbook_name)
177
+ upload_set[cookbook_name] = cookbook_repo[cookbook_name]
178
+ if config[:depends]
179
+ upload_set[cookbook_name].metadata.dependencies.each_key { |dep| @name_args << dep }
181
180
  end
182
- rescue Exceptions::CookbookNotFoundInRepo => e
183
- ui.error(e.message)
184
- Log.debug(e)
185
181
  end
182
+ rescue Exceptions::CookbookNotFoundInRepo => e
183
+ ui.error(e.message)
184
+ Log.debug(e)
185
+
186
186
  end
187
187
  upload_set
188
188
  end
@@ -87,7 +87,7 @@ class Chef
87
87
  when :json
88
88
  Chef::JSONCompat.to_json_pretty(data)
89
89
  when :yaml
90
- require "yaml"
90
+ require "yaml" unless defined?(YAML)
91
91
  YAML.dump(data)
92
92
  when :pp
93
93
  require "stringio" unless defined?(StringIO)
@@ -53,7 +53,7 @@ class Chef
53
53
  paths = manifest[KEY]["plugins_paths"][command]
54
54
  if paths && paths.is_a?(Array)
55
55
  # It is only an error if all the paths don't exist
56
- if paths.all? { |sc| !File.exists?(sc) }
56
+ if paths.all? { |sc| !File.exist?(sc) }
57
57
  errors[command] = paths
58
58
  end
59
59
  end
@@ -77,7 +77,7 @@ class Chef
77
77
  false
78
78
  else
79
79
  paths.each do |sc|
80
- if File.exists?(sc)
80
+ if File.exist?(sc)
81
81
  Kernel.load sc
82
82
  else
83
83
  return false
@@ -41,20 +41,6 @@ class Chef
41
41
  super(config, run_list, chef_config, secret)
42
42
  end
43
43
 
44
- # This is a duplicate of ChefConfig::PathHelper.cleanpath, however
45
- # this presumes Windows so we can avoid changing the method definitions
46
- # across Chef, ChefConfig, and ChefUtils for the circumstance where
47
- # the methods are being run for a system other than the one Ruby is
48
- # executing on.
49
- #
50
- # We only need to cleanpath the paths that we are passing to cmd.exe,
51
- # anything written to a configuration file or passed as an argument
52
- # will be interpreted by ruby later and do the right thing.
53
- def cleanpath(path)
54
- path = Pathname.new(path).cleanpath.to_s
55
- path.gsub(File::SEPARATOR, '\\')
56
- end
57
-
58
44
  def validation_key
59
45
  if File.exist?(File.expand_path(chef_config[:validation_key]))
60
46
  IO.read(File.expand_path(chef_config[:validation_key]))
@@ -72,12 +58,21 @@ class Chef
72
58
  end
73
59
 
74
60
  def config_content
61
+ # The windows: true / windows: false in the block that follows is more than a bit weird. The way to read this is that we need
62
+ # the e.g. var_chef_dir to be rendered for the windows value ("C:\chef"), but then we are rendering into a file to be read by
63
+ # ruby, so we don't actually care about forward-vs-backslashes and by rendering into unix we avoid having to deal with the
64
+ # double-backwhacking of everything. So we expect to see:
65
+ #
66
+ # file_cache_path "C:/chef"
67
+ #
68
+ # Which is mildly odd, but should be entirely correct as far as ruby cares.
69
+ #
75
70
  client_rb = <<~CONFIG
76
71
  chef_server_url "#{chef_config[:chef_server_url]}"
77
72
  validation_client_name "#{chef_config[:validation_client_name]}"
78
- file_cache_path "#{ChefConfig::Config.var_chef_dir(true)}/cache"
79
- file_backup_path "#{ChefConfig::Config.var_chef_dir(true)}/backup"
80
- cache_options ({:path => "#{ChefConfig::Config.etc_chef_dir(true)}/cache/checksums", :skip_expires => true})
73
+ file_cache_path "#{ChefConfig::PathHelper.escapepath(ChefConfig::Config.var_chef_dir(windows: true))}\\\\cache"
74
+ file_backup_path "#{ChefConfig::PathHelper.escapepath(ChefConfig::Config.var_chef_dir(windows: true))}\\\\backup"
75
+ cache_options ({:path => "#{ChefConfig::PathHelper.escapepath(ChefConfig::Config.etc_chef_dir(windows: true))}\\\\cache\\\\checksums", :skip_expires => true})
81
76
  CONFIG
82
77
 
83
78
  unless chef_config[:chef_license].nil?
@@ -90,8 +85,8 @@ class Chef
90
85
  client_rb << "# Using default node name (fqdn)\n"
91
86
  end
92
87
 
93
- if chef_config[:config_log_level]
94
- client_rb << %Q{log_level :#{chef_config[:config_log_level]}\n}
88
+ if config[:config_log_level]
89
+ client_rb << %Q{log_level :#{config[:config_log_level]}\n}
95
90
  else
96
91
  client_rb << "log_level :auto\n"
97
92
  end
@@ -140,11 +135,11 @@ class Chef
140
135
  end
141
136
 
142
137
  if config[:secret]
143
- client_rb << %Q{encrypted_data_bag_secret "#{ChefConfig::Config.etc_chef_dir(true)}/encrypted_data_bag_secret"\n}
138
+ client_rb << %Q{encrypted_data_bag_secret "#{ChefConfig::Config.etc_chef_dir(windows: true)}/encrypted_data_bag_secret"\n}
144
139
  end
145
140
 
146
141
  unless trusted_certs_script.empty?
147
- client_rb << %Q{trusted_certs_dir "#{ChefConfig::Config.etc_chef_dir(true)}/trusted_certs"\n}
142
+ client_rb << %Q{trusted_certs_dir "#{ChefConfig::Config.etc_chef_dir(windows: true)}/trusted_certs"\n}
148
143
  end
149
144
 
150
145
  if chef_config[:fips]
@@ -173,9 +168,14 @@ class Chef
173
168
  end
174
169
 
175
170
  def start_chef
171
+ c_opscode_dir = ChefConfig::PathHelper.cleanpath(ChefConfig::Config.c_opscode_dir, windows: true)
172
+ client_rb = clean_etc_chef_file("client.rb")
173
+ first_boot = clean_etc_chef_file("first-boot.json")
174
+
176
175
  bootstrap_environment_option = bootstrap_environment.nil? ? "" : " -E #{bootstrap_environment}"
177
- start_chef = "SET \"PATH=%SystemRoot%\\system32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SYSTEMROOT%\\System32\\WindowsPowerShell\\v1.0\\;C:\\ruby\\bin;#{ChefConfig::Config.c_opscode_dir}\\bin;#{ChefConfig::Config.c_opscode_dir}\\embedded\\bin\;%PATH%\"\n"
178
- start_chef << "#{Chef::Dist::CLIENT} -c #{ChefConfig::Config.etc_chef_dir(true)}/client.rb -j #{ChefConfig::Config.etc_chef_dir(true)}/first-boot.json#{bootstrap_environment_option}\n"
176
+
177
+ start_chef = "SET \"PATH=%SYSTEM32%;%SystemRoot%;%SYSTEM32%\\Wbem;%SYSTEM32%\\WindowsPowerShell\\v1.0\\;C:\\ruby\\bin;#{c_opscode_dir}\\bin;#{c_opscode_dir}\\embedded\\bin\;%PATH%\"\n"
178
+ start_chef << "#{Chef::Dist::CLIENT} -c #{client_rb} -j #{first_boot}#{bootstrap_environment_option}\n"
179
179
  end
180
180
 
181
181
  def win_wget
@@ -275,8 +275,16 @@ class Chef
275
275
  install_command('"') + "\n" + fallback_install_task_command
276
276
  end
277
277
 
278
+ def clean_etc_chef_file(path)
279
+ ChefConfig::PathHelper.cleanpath(etc_chef_file(path), windows: true)
280
+ end
281
+
282
+ def etc_chef_file(path)
283
+ "#{bootstrap_directory}/#{path}"
284
+ end
285
+
278
286
  def bootstrap_directory
279
- cleanpath(ChefConfig::Config.etc_chef_dir(true))
287
+ ChefConfig::Config.etc_chef_dir(windows: true)
280
288
  end
281
289
 
282
290
  def local_download_path
@@ -96,21 +96,21 @@ class Chef
96
96
  found_any = false
97
97
  error = false
98
98
  results.each do |result|
99
- begin
100
- result.delete(config[:recurse])
101
- deleted_any = true
102
- found_any = true
103
- rescue Chef::ChefFS::FileSystem::NotFoundError
104
- # This is not an error unless *all* of them were not found
105
- rescue Chef::ChefFS::FileSystem::MustDeleteRecursivelyError => e
106
- ui.error "#{format_path_with_root(e.entry)} must be deleted recursively! Pass -r to knife delete."
107
- found_any = true
108
- error = true
109
- rescue Chef::ChefFS::FileSystem::OperationNotAllowedError => e
110
- ui.error "#{format_path_with_root(e.entry)} #{e.reason}."
111
- found_any = true
112
- error = true
113
- end
99
+
100
+ result.delete(config[:recurse])
101
+ deleted_any = true
102
+ found_any = true
103
+ rescue Chef::ChefFS::FileSystem::NotFoundError
104
+ # This is not an error unless *all* of them were not found
105
+ rescue Chef::ChefFS::FileSystem::MustDeleteRecursivelyError => e
106
+ ui.error "#{format_path_with_root(e.entry)} must be deleted recursively! Pass -r to knife delete."
107
+ found_any = true
108
+ error = true
109
+ rescue Chef::ChefFS::FileSystem::OperationNotAllowedError => e
110
+ ui.error "#{format_path_with_root(e.entry)} #{e.reason}."
111
+ found_any = true
112
+ error = true
113
+
114
114
  end
115
115
  if deleted_any
116
116
  output("Deleted #{format_path(results[0])}")