chef 15.12.22 → 15.16.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +10 -10
  3. data/Rakefile +11 -17
  4. data/chef-universal-mingw32.gemspec +4 -4
  5. data/chef.gemspec +22 -4
  6. data/lib/chef/api_client/registration.rb +2 -2
  7. data/lib/chef/chef_fs/file_system/repository/base_file.rb +1 -0
  8. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb +2 -2
  9. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +1 -1
  10. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +2 -2
  11. data/lib/chef/chef_fs/file_system/repository/directory.rb +1 -1
  12. data/lib/chef/chef_fs/file_system/repository/file_system_entry.rb +1 -1
  13. data/lib/chef/deprecated.rb +4 -0
  14. data/lib/chef/environment.rb +2 -2
  15. data/lib/chef/exceptions.rb +3 -0
  16. data/lib/chef/http.rb +2 -1
  17. data/lib/chef/knife/bootstrap.rb +3 -3
  18. data/lib/chef/knife/bootstrap/train_connector.rb +1 -0
  19. data/lib/chef/knife/cookbook_download.rb +1 -1
  20. data/lib/chef/knife/cookbook_metadata.rb +1 -1
  21. data/lib/chef/knife/core/gem_glob_loader.rb +1 -1
  22. data/lib/chef/knife/core/hashed_command_loader.rb +3 -2
  23. data/lib/chef/knife/core/subcommand_loader.rb +1 -1
  24. data/lib/chef/knife/exec.rb +2 -2
  25. data/lib/chef/knife/ssh.rb +20 -1
  26. data/lib/chef/log.rb +1 -1
  27. data/lib/chef/mixin/openssl_helper.rb +26 -3
  28. data/lib/chef/mixin/template.rb +1 -0
  29. data/lib/chef/node_map.rb +5 -2
  30. data/lib/chef/provider/mount/solaris.rb +0 -1
  31. data/lib/chef/provider/package/dnf/dnf_helper.py +5 -0
  32. data/lib/chef/provider/package/freebsd/pkgng.rb +3 -1
  33. data/lib/chef/provider/package/yum/yum_helper.py +4 -0
  34. data/lib/chef/provider/package/zypper.rb +0 -1
  35. data/lib/chef/provider/service/arch.rb +2 -2
  36. data/lib/chef/provider/service/debian.rb +1 -1
  37. data/lib/chef/provider/service/gentoo.rb +2 -2
  38. data/lib/chef/provider/service/macosx.rb +2 -2
  39. data/lib/chef/provider/service/openbsd.rb +1 -1
  40. data/lib/chef/provider/service/redhat.rb +2 -2
  41. data/lib/chef/provider/service/upstart.rb +1 -1
  42. data/lib/chef/provider/yum_repository.rb +1 -1
  43. data/lib/chef/provider/zypper_repository.rb +1 -1
  44. data/lib/chef/resource.rb +2 -0
  45. data/lib/chef/resource/cron_access.rb +2 -2
  46. data/lib/chef/resource/cron_d.rb +2 -1
  47. data/lib/chef/resource/homebrew_cask.rb +3 -3
  48. data/lib/chef/resource/hostname.rb +18 -18
  49. data/lib/chef/resource/locale.rb +1 -1
  50. data/lib/chef/resource/lwrp_base.rb +7 -0
  51. data/lib/chef/resource/ssh_known_hosts_entry.rb +1 -1
  52. data/lib/chef/resource/sudo.rb +2 -2
  53. data/lib/chef/resource/windows_feature_powershell.rb +6 -2
  54. data/lib/chef/resource/windows_font.rb +2 -1
  55. data/lib/chef/role.rb +2 -2
  56. data/lib/chef/shell.rb +32 -1
  57. data/lib/chef/shell/shell_session.rb +2 -0
  58. data/lib/chef/util/diff.rb +1 -1
  59. data/lib/chef/util/dsc/configuration_generator.rb +1 -1
  60. data/lib/chef/util/powershell/cmdlet.rb +1 -1
  61. data/lib/chef/version.rb +2 -2
  62. data/lib/chef/version_string.rb +1 -1
  63. data/lib/chef/win32/file.rb +2 -2
  64. data/spec/functional/knife/ssh_spec.rb +4 -4
  65. data/spec/functional/resource/aix_service_spec.rb +0 -1
  66. data/spec/functional/resource/aixinit_service_spec.rb +7 -8
  67. data/spec/functional/resource/apt_package_spec.rb +0 -1
  68. data/spec/functional/resource/bff_spec.rb +2 -2
  69. data/spec/functional/resource/cookbook_file_spec.rb +1 -1
  70. data/spec/functional/resource/cron_spec.rb +0 -1
  71. data/spec/functional/resource/dsc_resource_spec.rb +1 -1
  72. data/spec/functional/resource/insserv_spec.rb +4 -5
  73. data/spec/functional/resource/link_spec.rb +17 -17
  74. data/spec/functional/resource/rpm_spec.rb +2 -2
  75. data/spec/functional/resource/user/dscl_spec.rb +1 -1
  76. data/spec/functional/resource/user/mac_user_spec.rb +1 -1
  77. data/spec/functional/resource/windows_certificate_spec.rb +3 -3
  78. data/spec/functional/resource/windows_font_spec.rb +49 -0
  79. data/spec/functional/run_lock_spec.rb +2 -1
  80. data/spec/functional/shell_spec.rb +5 -5
  81. data/spec/functional/util/powershell/cmdlet_spec.rb +1 -1
  82. data/spec/functional/version_spec.rb +1 -1
  83. data/spec/functional/win32/service_manager_spec.rb +1 -1
  84. data/spec/integration/recipes/accumulator_spec.rb +1 -1
  85. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +2 -2
  86. data/spec/integration/recipes/lwrp_spec.rb +1 -1
  87. data/spec/integration/recipes/notifies_spec.rb +1 -1
  88. data/spec/integration/recipes/notifying_block_spec.rb +1 -1
  89. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  90. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +2 -0
  91. data/spec/integration/recipes/resource_load_spec.rb +1 -0
  92. data/spec/integration/recipes/unified_mode_spec.rb +1 -1
  93. data/spec/scripts/ssl-serve.rb +1 -1
  94. data/spec/spec_helper.rb +10 -8
  95. data/spec/support/platform_helpers.rb +12 -42
  96. data/spec/support/platforms/win32/spec_service.rb +1 -1
  97. data/spec/support/shared/functional/directory_resource.rb +1 -1
  98. data/spec/support/shared/functional/execute_resource.rb +1 -1
  99. data/spec/support/shared/functional/file_resource.rb +2 -2
  100. data/spec/support/shared/functional/win32_service.rb +1 -1
  101. data/spec/support/shared/functional/windows_script.rb +3 -3
  102. data/spec/support/shared/integration/knife_support.rb +2 -5
  103. data/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb +2 -4
  104. data/spec/unit/cookbook/gem_installer_spec.rb +2 -1
  105. data/spec/unit/dsl/platform_introspection_spec.rb +1 -0
  106. data/spec/unit/environment_spec.rb +7 -7
  107. data/spec/unit/event_dispatch/dispatcher_spec.rb +3 -0
  108. data/spec/unit/knife/bootstrap_spec.rb +14 -14
  109. data/spec/unit/knife/cookbook_download_spec.rb +4 -4
  110. data/spec/unit/knife/cookbook_metadata_from_file_spec.rb +1 -1
  111. data/spec/unit/knife/cookbook_upload_spec.rb +5 -6
  112. data/spec/unit/knife/core/hashed_command_loader_spec.rb +3 -3
  113. data/spec/unit/knife/ssh_spec.rb +2 -2
  114. data/spec/unit/knife/supermarket_share_spec.rb +5 -3
  115. data/spec/unit/lwrp_spec.rb +4 -4
  116. data/spec/unit/mixin/securable_spec.rb +0 -1
  117. data/spec/unit/property_spec.rb +5 -5
  118. data/spec/unit/provider/package/dnf/python_helper_spec.rb +1 -1
  119. data/spec/unit/provider/package/freebsd/pkgng_spec.rb +1 -1
  120. data/spec/unit/provider/package/rubygems_spec.rb +5 -10
  121. data/spec/unit/provider/package/windows_spec.rb +30 -53
  122. data/spec/unit/provider/service/arch_service_spec.rb +3 -2
  123. data/spec/unit/provider/service/debian_service_spec.rb +1 -1
  124. data/spec/unit/provider/service/gentoo_service_spec.rb +7 -7
  125. data/spec/unit/provider/service/macosx_spec.rb +3 -3
  126. data/spec/unit/provider/service/redhat_spec.rb +2 -2
  127. data/spec/unit/provider/service/upstart_service_spec.rb +3 -3
  128. data/spec/unit/provider/service/windows_spec.rb +2 -6
  129. data/spec/unit/provider/systemd_unit_spec.rb +28 -24
  130. data/spec/unit/provider_spec.rb +1 -0
  131. data/spec/unit/resource/windows_feature_powershell_spec.rb +30 -4
  132. data/spec/unit/resource/windows_package_spec.rb +1 -0
  133. data/spec/unit/role_spec.rb +11 -11
  134. data/spec/unit/run_context/cookbook_compiler_spec.rb +1 -1
  135. data/spec/unit/win32/security_spec.rb +4 -3
  136. metadata +36 -23
@@ -125,7 +125,7 @@ class Chef
125
125
  #
126
126
  def find_subcommands_via_dirglob
127
127
  # The "require paths" of the core knife subcommands bundled with chef
128
- files = Dir[File.join(Chef::Util::PathHelper.escape_glob_dir(File.expand_path("../../../knife", __FILE__)), "*.rb")]
128
+ files = Dir[File.join(Chef::Util::PathHelper.escape_glob_dir(File.expand_path("../../knife", __dir__)), "*.rb")]
129
129
  subcommand_files = {}
130
130
  files.each do |knife_file|
131
131
  rel_path = knife_file[/#{CHEF_ROOT}#{Regexp.escape(File::SEPARATOR)}(.*)\.rb/, 1]
@@ -76,7 +76,7 @@ class Chef::Knife::Exec < Chef::Knife
76
76
  def find_script(x)
77
77
  # Try to find a script. First try expanding the path given.
78
78
  script = File.expand_path(x)
79
- return script if File.exists?(script)
79
+ return script if File.exist?(script)
80
80
 
81
81
  # Failing that, try searching the script path. If we can't find
82
82
  # anything, fail gracefully.
@@ -86,7 +86,7 @@ class Chef::Knife::Exec < Chef::Knife
86
86
  path = File.expand_path(path)
87
87
  test = File.join(path, x)
88
88
  Chef::Log.trace("Testing: #{test}")
89
- if File.exists?(test)
89
+ if File.exist?(test)
90
90
  script = test
91
91
  Chef::Log.trace("Found: #{test}")
92
92
  return script
@@ -298,6 +298,10 @@ class Chef
298
298
  opts[:keepalive] = true
299
299
  opts[:keepalive_interval] = ssh_config[:keepalive_interval]
300
300
  end
301
+ # maintain support for legacy key types / ciphers / key exchange algorithms.
302
+ # most importantly this adds back support for DSS host keys
303
+ # See https://github.com/net-ssh/net-ssh/pull/709
304
+ opts[:append_all_supported_algorithms] = true
301
305
  end
302
306
  end
303
307
 
@@ -358,11 +362,21 @@ class Chef
358
362
  subsession ||= session
359
363
  command = fixup_sudo(command)
360
364
  command.force_encoding("binary") if command.respond_to?(:force_encoding)
365
+ begin
366
+ open_session(subsession, command)
367
+ rescue => e
368
+ open_session(subsession, command, true)
369
+ end
370
+ end
371
+
372
+ def open_session(subsession, command, pty = false)
373
+ stderr = ""
374
+ exit_status = 0
361
375
  subsession.open_channel do |chan|
362
376
  if config[:on_error] && exit_status != 0
363
377
  chan.close
364
378
  else
365
- chan.request_pty
379
+ chan.request_pty if pty
366
380
  chan.exec command do |ch, success|
367
381
  raise ArgumentError, "Cannot execute #{command}" unless success
368
382
 
@@ -373,6 +387,11 @@ class Chef
373
387
  ichannel.send_data("#{get_password}\n")
374
388
  end
375
389
  end
390
+
391
+ ch.on_extended_data do |_, _type, data|
392
+ stderr += data
393
+ end
394
+
376
395
  ch.on_request "exit-status" do |ichannel, data|
377
396
  exit_status = [exit_status, data.read_long].max
378
397
  end
data/lib/chef/log.rb CHANGED
@@ -47,7 +47,7 @@ class Chef
47
47
  def self.caller_location
48
48
  # Pick the first caller that is *not* part of the Chef gem, that's the
49
49
  # thing the user wrote. Or failing that, the most recent caller.
50
- chef_gem_path = File.expand_path("../..", __FILE__)
50
+ chef_gem_path = File.expand_path("..", __dir__)
51
51
  caller(0..20).find { |c| !c.start_with?(chef_gem_path) } || caller(0..1)[0]
52
52
  end
53
53
 
@@ -282,7 +282,9 @@ class Chef
282
282
  ef.issuer_certificate = info["issuer"]
283
283
  end
284
284
  ef.subject_certificate = cert
285
- ef.config = ::OpenSSL::Config.load(::OpenSSL::Config::DEFAULT_CONFIG_FILE)
285
+ if openssl_config = __openssl_config
286
+ ef.config = openssl_config
287
+ end
286
288
 
287
289
  cert.extensions = extension
288
290
  cert.add_extension ef.create_extension("subjectKeyIdentifier", "hash")
@@ -313,7 +315,9 @@ class Chef
313
315
  crl.last_update = Time.now
314
316
  crl.next_update = Time.now + 3600 * 24 * info["validity"]
315
317
 
316
- ef.config = ::OpenSSL::Config.load(::OpenSSL::Config::DEFAULT_CONFIG_FILE)
318
+ if openssl_config = __openssl_config
319
+ ef.config = openssl_config
320
+ end
317
321
  ef.issuer_certificate = info["issuer"]
318
322
 
319
323
  crl.add_extension ::OpenSSL::X509::Extension.new("crlNumber", ::OpenSSL::ASN1::Integer(1))
@@ -391,7 +395,9 @@ class Chef
391
395
  crl.next_update = crl.last_update + 3600 * 24 * info["validity"]
392
396
 
393
397
  ef = ::OpenSSL::X509::ExtensionFactory.new
394
- ef.config = ::OpenSSL::Config.load(::OpenSSL::Config::DEFAULT_CONFIG_FILE)
398
+ if openssl_config = __openssl_config
399
+ ef.config = openssl_config
400
+ end
395
401
  ef.issuer_certificate = info["issuer"]
396
402
 
397
403
  crl.extensions = [ ::OpenSSL::X509::Extension.new("crlNumber",
@@ -422,6 +428,23 @@ class Chef
422
428
 
423
429
  resp
424
430
  end
431
+
432
+ private
433
+
434
+ def __openssl_config
435
+ path = if File.exist?(::OpenSSL::Config::DEFAULT_CONFIG_FILE)
436
+ OpenSSL::Config::DEFAULT_CONFIG_FILE
437
+ else
438
+ Dir[File.join(RbConfig::CONFIG["prefix"], "**", "openssl.cnf")].first
439
+ end
440
+
441
+ if File.exist?(path)
442
+ ::OpenSSL::Config.load(path)
443
+ else
444
+ Chef::Log.warn("Couldn't find OpenSSL config file")
445
+ nil
446
+ end
447
+ end
425
448
  end
426
449
  end
427
450
  end
@@ -213,6 +213,7 @@ class Chef
213
213
 
214
214
  class TemplateError < RuntimeError
215
215
  attr_reader :original_exception, :context, :options
216
+
216
217
  SOURCE_CONTEXT_WINDOW = 2
217
218
 
218
219
  def initialize(original_exception, template, context, options)
data/lib/chef/node_map.rb CHANGED
@@ -35,10 +35,13 @@
35
35
  #
36
36
  # XXX: confusingly, in the *_priority_map the :klass may be an array of Strings of class names
37
37
  #
38
+
39
+ require_relative "dist"
40
+
38
41
  class Chef
39
42
  class NodeMap
40
43
  COLLISION_WARNING = <<~EOH.gsub(/\s+/, " ").strip
41
- %{type_caps} %{key} from the client is overriding the %{type} from a cookbook. Please upgrade your cookbook
44
+ %{type_caps} %{key} built into %{client_name} is being overridden by the %{type} from a cookbook. Please upgrade your cookbook
42
45
  or remove the cookbook from your run_list.
43
46
  EOH
44
47
 
@@ -84,7 +87,7 @@ class Chef
84
87
  else
85
88
  klass.superclass.to_s
86
89
  end
87
- Chef::Log.warn( COLLISION_WARNING % { type: type_of_thing, key: key, type_caps: type_of_thing.capitalize } )
90
+ Chef::Log.warn( COLLISION_WARNING % { type: type_of_thing, key: key, type_caps: type_of_thing.capitalize, client_name: Chef::Dist::PRODUCT } )
88
91
  end
89
92
 
90
93
  # The map is sorted in order of preference already; we just need to find
@@ -1,4 +1,3 @@
1
- # Encoding: utf-8
2
1
  # Author:: Hugo Fichter
3
2
  # Author:: Lamont Granquist (<lamont@chef.io>)
4
3
  # Author:: Joshua Timberman (<joshua@chef.io>)
@@ -101,6 +101,11 @@ while 1:
101
101
  if ppid == 1:
102
102
  sys.exit(0)
103
103
  line = sys.stdin.readline()
104
+
105
+ # only way to detect EOF in python
106
+ if line == "":
107
+ break
108
+
104
109
  command = json.loads(line)
105
110
  if command['action'] == "whatinstalled":
106
111
  query(command)
@@ -42,7 +42,9 @@ class Chef
42
42
  end
43
43
 
44
44
  def current_installed_version
45
- pkg_info = shell_out!("pkg", "info", new_resource.package_name, env: nil, returns: [0, 70])
45
+ # pkgng up to version 1.15.99.7 returns 70 for pkg not found,
46
+ # later versions return 1
47
+ pkg_info = shell_out!("pkg", "info", new_resource.package_name, env: nil, returns: [0, 1, 70])
46
48
  pkg_info.stdout[/^Version +: (.+)$/, 1]
47
49
  end
48
50
 
@@ -196,6 +196,10 @@ try:
196
196
  setup_exit_handler()
197
197
  line = inpipe.readline()
198
198
 
199
+ # only way to detect EOF in python
200
+ if line == "":
201
+ break
202
+
199
203
  try:
200
204
  command = json.loads(line)
201
205
  except ValueError, e:
@@ -1,4 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
1
  #
3
2
  # Authors:: Adam Jacob (<adam@chef.io>)
4
3
  # Ionuț Arțăriși (<iartarisi@suse.cz>)
@@ -32,8 +32,8 @@ class Chef::Provider::Service::Arch < Chef::Provider::Service::Init
32
32
  end
33
33
 
34
34
  def load_current_resource
35
- raise Chef::Exceptions::Service, "Could not find /etc/rc.conf" unless ::File.exists?("/etc/rc.conf")
36
- raise Chef::Exceptions::Service, "No DAEMONS found in /etc/rc.conf" unless ::File.read("/etc/rc.conf") =~ /DAEMONS=\((.*)\)/m
35
+ raise Chef::Exceptions::Service, "Could not find /etc/rc.conf" unless ::File.exist?("/etc/rc.conf")
36
+ raise Chef::Exceptions::Service, "No DAEMONS found in /etc/rc.conf" unless /DAEMONS=\((.*)\)/m.match?(::File.read("/etc/rc.conf"))
37
37
 
38
38
  super
39
39
 
@@ -45,7 +45,7 @@ class Chef
45
45
  shared_resource_requirements
46
46
  requirements.assert(:all_actions) do |a|
47
47
  update_rcd = "/usr/sbin/update-rc.d"
48
- a.assertion { ::File.exists? update_rcd }
48
+ a.assertion { ::File.exist? update_rcd }
49
49
  a.failure_message Chef::Exceptions::Service, "#{update_rcd} does not exist!"
50
50
  # no whyrun recovery - this is a base system component of debian
51
51
  # distros and must be present
@@ -34,7 +34,7 @@ class Chef::Provider::Service::Gentoo < Chef::Provider::Service::Init
34
34
  @current_resource.enabled(
35
35
  Dir.glob("/etc/runlevels/**/#{Chef::Util::PathHelper.escape_glob_dir(@current_resource.service_name)}").any? do |file|
36
36
  @found_script = true
37
- exists = ::File.exists? file
37
+ exists = ::File.exist? file
38
38
  readable = ::File.readable? file
39
39
  logger.trace "#{@new_resource} exists: #{exists}, readable: #{readable}"
40
40
  exists && readable
@@ -47,7 +47,7 @@ class Chef::Provider::Service::Gentoo < Chef::Provider::Service::Init
47
47
 
48
48
  def define_resource_requirements
49
49
  requirements.assert(:all_actions) do |a|
50
- a.assertion { ::File.exists?("/sbin/rc-update") }
50
+ a.assertion { ::File.exist?("/sbin/rc-update") }
51
51
  a.failure_message Chef::Exceptions::Service, "/sbin/rc-update does not exist"
52
52
  # no whyrun recovery -t his is a core component whose presence is
53
53
  # unlikely to be affected by what we do in the course of a chef run
@@ -84,7 +84,7 @@ class Chef
84
84
  end
85
85
 
86
86
  requirements.assert(:all_actions) do |a|
87
- a.assertion { ::File.exists?(@plist.to_s) }
87
+ a.assertion { ::File.exist?(@plist.to_s) }
88
88
  a.failure_message Chef::Exceptions::Service,
89
89
  "Could not find plist for #{@new_resource}"
90
90
  end
@@ -215,7 +215,7 @@ class Chef
215
215
  return nil if @plist.nil?
216
216
 
217
217
  # Plist must exist by this point
218
- raise Chef::Exceptions::FileNotFound, "Cannot find #{@plist}!" unless ::File.exists?(@plist)
218
+ raise Chef::Exceptions::FileNotFound, "Cannot find #{@plist}!" unless ::File.exist?(@plist)
219
219
 
220
220
  # Most services have the same internal label as the name of the
221
221
  # plist file. However, there is no rule saying that *has* to be
@@ -132,7 +132,7 @@ class Chef
132
132
  end
133
133
 
134
134
  def update_rcl(value)
135
- FileUtils.touch RC_CONF_LOCAL_PATH unless ::File.exists? RC_CONF_LOCAL_PATH
135
+ FileUtils.touch RC_CONF_LOCAL_PATH unless ::File.exist? RC_CONF_LOCAL_PATH
136
136
  ::File.write(RC_CONF_LOCAL_PATH, value)
137
137
  @rc_conf_local = value
138
138
  end
@@ -56,7 +56,7 @@ class Chef
56
56
 
57
57
  requirements.assert(:all_actions) do |a|
58
58
  chkconfig_file = "/sbin/chkconfig"
59
- a.assertion { ::File.exists? chkconfig_file }
59
+ a.assertion { ::File.exist? chkconfig_file }
60
60
  a.failure_message Chef::Exceptions::Service, "#{chkconfig_file} does not exist!"
61
61
  end
62
62
 
@@ -80,7 +80,7 @@ class Chef
80
80
 
81
81
  super
82
82
 
83
- if ::File.exists?("/sbin/chkconfig")
83
+ if ::File.exist?("/sbin/chkconfig")
84
84
  chkconfig = shell_out!("/sbin/chkconfig --list #{current_resource.service_name}", returns: [0, 1])
85
85
  unless run_levels.nil? || run_levels.empty?
86
86
  all_levels_match = true
@@ -135,7 +135,7 @@ class Chef
135
135
  end
136
136
  end
137
137
  # Get enabled/disabled state by reading job configuration file
138
- if ::File.exists?("#{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}")
138
+ if ::File.exist?("#{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}")
139
139
  logger.trace("#{@new_resource} found #{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}")
140
140
  ::File.open("#{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}", "r") do |file|
141
141
  while line = file.gets
@@ -37,7 +37,7 @@ class Chef
37
37
  if template_available?(new_resource.source)
38
38
  source new_resource.source
39
39
  else
40
- source ::File.expand_path("../support/yum_repo.erb", __FILE__)
40
+ source ::File.expand_path("support/yum_repo.erb", __dir__)
41
41
  local true
42
42
  end
43
43
  sensitive new_resource.sensitive
@@ -41,7 +41,7 @@ class Chef
41
41
  if template_available?(new_resource.source)
42
42
  source new_resource.source
43
43
  else
44
- source ::File.expand_path("../support/zypper_repo.erb", __FILE__)
44
+ source ::File.expand_path("support/zypper_repo.erb", __dir__)
45
45
  local true
46
46
  end
47
47
  sensitive new_resource.sensitive
data/lib/chef/resource.rb CHANGED
@@ -613,6 +613,7 @@ class Chef
613
613
  # Do NOT use this. It may be removed. It is for internal purposes only.
614
614
  # @api private
615
615
  attr_reader :resource_initializing
616
+
616
617
  def resource_initializing=(value)
617
618
  if value
618
619
  @resource_initializing = true
@@ -863,6 +864,7 @@ class Chef
863
864
  # have.
864
865
  #
865
866
  attr_writer :allowed_actions
867
+
866
868
  def allowed_actions(value = NOT_PASSED)
867
869
  if value != NOT_PASSED
868
870
  self.allowed_actions = value
@@ -66,7 +66,7 @@ class Chef
66
66
 
67
67
  with_run_context :root do
68
68
  edit_resource(:template, allow_path) do |new_resource|
69
- source ::File.expand_path("../support/cron_access.erb", __FILE__)
69
+ source ::File.expand_path("support/cron_access.erb", __dir__)
70
70
  local true
71
71
  mode "0600"
72
72
  variables["users"] ||= []
@@ -83,7 +83,7 @@ class Chef
83
83
 
84
84
  with_run_context :root do
85
85
  edit_resource(:template, deny_path) do |new_resource|
86
- source ::File.expand_path("../support/cron_access.erb", __FILE__)
86
+ source ::File.expand_path("support/cron_access.erb", __dir__)
87
87
  local true
88
88
  mode "0600"
89
89
  variables["users"] ||= []
@@ -289,9 +289,10 @@ class Chef
289
289
 
290
290
  # @todo this is Chef 12 era cleanup. Someday we should remove it all
291
291
  template "/etc/cron.d/#{sanitized_name}" do
292
- source ::File.expand_path("../support/cron.d.erb", __FILE__)
292
+ source ::File.expand_path("support/cron.d.erb", __dir__)
293
293
  local true
294
294
  mode new_resource.mode
295
+ sensitive new_resource.sensitive
295
296
  variables(
296
297
  name: sanitized_name,
297
298
  predefined_value: new_resource.predefined_value,
@@ -59,7 +59,7 @@ class Chef
59
59
 
60
60
  unless casked?
61
61
  converge_by("install cask #{new_resource.cask_name} #{new_resource.options}") do
62
- shell_out!("#{new_resource.homebrew_path} cask install #{new_resource.cask_name} #{new_resource.options}",
62
+ shell_out!("#{new_resource.homebrew_path} install --cask #{new_resource.cask_name} #{new_resource.options}",
63
63
  user: new_resource.owner,
64
64
  env: { "HOME" => ::Dir.home(new_resource.owner), "USER" => new_resource.owner },
65
65
  cwd: ::Dir.home(new_resource.owner))
@@ -74,7 +74,7 @@ class Chef
74
74
 
75
75
  if casked?
76
76
  converge_by("uninstall cask #{new_resource.cask_name}") do
77
- shell_out!("#{new_resource.homebrew_path} cask uninstall #{new_resource.cask_name}",
77
+ shell_out!("#{new_resource.homebrew_path} uninstall --cask #{new_resource.cask_name}",
78
78
  user: new_resource.owner,
79
79
  env: { "HOME" => ::Dir.home(new_resource.owner), "USER" => new_resource.owner },
80
80
  cwd: ::Dir.home(new_resource.owner))
@@ -92,7 +92,7 @@ class Chef
92
92
  # @return [Boolean]
93
93
  def casked?
94
94
  unscoped_name = new_resource.cask_name.split("/").last
95
- shell_out!("#{new_resource.homebrew_path} cask list 2>/dev/null",
95
+ shell_out!("#{new_resource.homebrew_path} list --cask 2>/dev/null",
96
96
  user: new_resource.owner,
97
97
  env: { "HOME" => ::Dir.home(new_resource.owner), "USER" => new_resource.owner },
98
98
  cwd: ::Dir.home(new_resource.owner)).stdout.split.include?(unscoped_name)
@@ -67,8 +67,7 @@ class Chef
67
67
  def updated_ec2_config_xml
68
68
  begin
69
69
  require "rexml/document" unless defined?(REXML::Document)
70
- config_file = 'C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml'
71
- config = REXML::Document.new(::File.read(config_file))
70
+ config = REXML::Document.new(::File.read(WINDOWS_EC2_CONFIG))
72
71
  # find an element named State with a sibling element whose value is Ec2SetComputerName
73
72
  REXML::XPath.each(config, "//Plugin/State[../Name/text() = 'Ec2SetComputerName']") do |element|
74
73
  element.text = "Disabled"
@@ -220,35 +219,36 @@ class Chef
220
219
  end
221
220
 
222
221
  else # windows
222
+ WINDOWS_EC2_CONFIG = 'C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml'.freeze
223
+
223
224
  raise "Windows hostnames cannot contain a period." if new_resource.hostname.match?(/\./)
224
225
 
225
226
  # suppress EC2 config service from setting our hostname
226
- if ::File.exist?('C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml')
227
+ if ::File.exist?(WINDOWS_EC2_CONFIG)
227
228
  xml_contents = updated_ec2_config_xml
228
229
  if xml_contents.empty?
229
230
  Chef::Log.warn('Unable to properly parse and update C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml contents. Skipping file update.')
230
231
  else
231
- declare_resource(:file, 'C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml') do
232
+ file WINDOWS_EC2_CONFIG do
232
233
  content xml_contents
233
234
  end
234
235
  end
235
236
  end
236
237
 
237
- # update via netdom
238
- declare_resource(:powershell_script, "set hostname") do
239
- code <<-EOH
240
- $sysInfo = Get-WmiObject -Class Win32_ComputerSystem
241
- $sysInfo.Rename("#{new_resource.hostname}")
242
- EOH
243
- notifies :request_reboot, "reboot[setting hostname]"
244
- not_if { Socket.gethostbyname(Socket.gethostname).first == new_resource.hostname }
245
- end
238
+ unless Socket.gethostbyname(Socket.gethostname).first == new_resource.hostname
239
+ converge_by "set hostname to #{new_resource.hostname}" do
240
+ powershell_out! <<~EOH
241
+ $sysInfo = Get-WmiObject -Class Win32_ComputerSystem
242
+ $sysInfo.Rename("#{new_resource.hostname}")
243
+ EOH
244
+ end
246
245
 
247
- # reboot because $windows
248
- declare_resource(:reboot, "setting hostname") do
249
- reason "#{Chef::Dist::PRODUCT} updated system hostname"
250
- action :nothing
251
- only_if { new_resource.windows_reboot }
246
+ # reboot because $windows
247
+ reboot "setting hostname" do
248
+ reason "#{Chef::Dist::PRODUCT} updated system hostname"
249
+ only_if { new_resource.windows_reboot }
250
+ action :request_reboot
251
+ end
252
252
  end
253
253
  end
254
254
  end