chef 17.9.18-universal-mingw32 → 17.9.52-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -3
  3. data/README.md +1 -1
  4. data/lib/chef/application/exit_code.rb +7 -21
  5. data/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb +1 -1
  6. data/lib/chef/chef_fs/file_system/repository/base_file.rb +1 -1
  7. data/lib/chef/chef_fs/file_system/repository/file_system_entry.rb +1 -1
  8. data/lib/chef/compliance/default_attributes.rb +1 -1
  9. data/lib/chef/compliance/input_collection.rb +1 -1
  10. data/lib/chef/compliance/reporter/compliance_enforcer.rb +1 -1
  11. data/lib/chef/compliance/runner.rb +2 -2
  12. data/lib/chef/compliance/waiver_collection.rb +1 -1
  13. data/lib/chef/cookbook/syntax_check.rb +1 -1
  14. data/lib/chef/cookbook_uploader.rb +1 -1
  15. data/lib/chef/cookbook_version.rb +1 -1
  16. data/lib/chef/provider/ifconfig.rb +1 -1
  17. data/lib/chef/provider/package.rb +1 -1
  18. data/lib/chef/provider/user/mac.rb +3 -3
  19. data/lib/chef/resource/archive_file.rb +6 -6
  20. data/lib/chef/resource/habitat/habitat_sup.rb +1 -1
  21. data/lib/chef/resource/habitat/habitat_sup_windows.rb +1 -1
  22. data/lib/chef/resource/homebrew_tap.rb +1 -1
  23. data/lib/chef/resource/inspec_waiver_file_entry.rb +1 -1
  24. data/lib/chef/resource/launchd.rb +2 -2
  25. data/lib/chef/resource/lwrp_base.rb +1 -1
  26. data/lib/chef/resource/remote_file.rb +1 -1
  27. data/lib/chef/resource.rb +3 -2
  28. data/lib/chef/resource_reporter.rb +1 -1
  29. data/lib/chef/run_lock.rb +1 -1
  30. data/lib/chef/secret_fetcher/azure_key_vault.rb +2 -2
  31. data/lib/chef/util/dsc/configuration_generator.rb +1 -1
  32. data/lib/chef/version.rb +1 -1
  33. data/spec/functional/resource/archive_file_spec.rb +3 -2
  34. data/spec/functional/resource/cookbook_file_spec.rb +1 -1
  35. data/spec/functional/resource/dsc_script_spec.rb +2 -2
  36. data/spec/functional/resource/template_spec.rb +1 -1
  37. data/spec/integration/client/client_spec.rb +1 -1
  38. data/spec/spec_helper.rb +3 -5
  39. data/spec/support/platform_helpers.rb +1 -1
  40. data/spec/support/ruby_installer.rb +1 -1
  41. data/spec/support/shared/functional/file_resource.rb +2 -2
  42. data/spec/support/shared/functional/http.rb +9 -9
  43. data/spec/support/shared/unit/provider/useradd_based_user_provider.rb +1 -1
  44. data/spec/unit/compliance/reporter/compliance_enforcer_spec.rb +3 -3
  45. data/spec/unit/dsl/registry_helper_spec.rb +6 -6
  46. data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +1 -1
  47. data/spec/unit/lwrp_spec.rb +2 -2
  48. data/spec/unit/provider/dsc_script_spec.rb +8 -8
  49. data/spec/unit/provider/group/usermod_spec.rb +2 -2
  50. data/spec/unit/provider/ifconfig/aix_spec.rb +14 -14
  51. data/spec/unit/provider/ifconfig/debian_spec.rb +1 -1
  52. data/spec/unit/provider/ifconfig/redhat_spec.rb +1 -1
  53. data/spec/unit/provider/ifconfig_spec.rb +3 -3
  54. data/spec/unit/provider/remote_file/cache_control_data_spec.rb +3 -3
  55. data/spec/unit/provider/service/gentoo_service_spec.rb +2 -2
  56. data/spec/unit/provider/service/upstart_service_spec.rb +3 -3
  57. data/spec/unit/provider/user/solaris_spec.rb +1 -1
  58. data/spec/unit/resource/archive_file_spec.rb +1 -2
  59. data/spec/unit/resource/conditional_spec.rb +4 -4
  60. data/spec/unit/resource_spec.rb +14 -6
  61. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b9715c340b843ce28238b3895f55d35b70fef6fd23e34fde3d84c4a2f1842a4
4
- data.tar.gz: 48cd99e12be9c6b51e5ac471463797cb67e6604c2896d1d4a9f1d50ccb5a8e23
3
+ metadata.gz: ef4f4acb5e1adc0f97c4eaf653095911e5206dfb761b740b710cbaf78358c0dc
4
+ data.tar.gz: 38ad6e54f2c3671b389ca4eafa897c3ccea722774aca326aaf65b3dbc8164e28
5
5
  SHA512:
6
- metadata.gz: c9242f73aafc766b8c088c2afa2e187c7332440ad4ac5f6fe9b8e54283f28ca093c1249916eec30e61431488c4ad443cf49cab0e80e0e92a44b9ca1683a12416
7
- data.tar.gz: ce3ae2b7a7f5f562644fbc445e3180c2f1b1b351bba11bb39d4ba5b79363be19c52b7924cf66f2fb94bdd4c3cf6194d7a71dbadeda88abc9d59ac2a439d69fb5
6
+ metadata.gz: d48d9f5d33b520dd732ba953e0d1c3624412f34e00585085fbe6c81d4d19664a240d2d716b3362a2a310b1754a3a50c4378c83c43abe33af78c62afd045dcf90
7
+ data.tar.gz: 94d27dfbc0507da0f0cf9df56efc0f14039e33fd3c21d410667ed54f0438333fdac5655b789b9972afdcb57ae6bb14fbf5bb0e15dbd35111efce3dafe4215fb5
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source "https://rubygems.org"
2
2
 
3
3
  gem "chef", path: "."
4
4
 
5
- gem "ohai", git: "https://github.com/chef/ohai.git", branch: "main"
5
+ gem "ohai", git: "https://github.com/chef/ohai.git", branch: "17-stable"
6
6
 
7
7
  gem "chef-utils", path: File.expand_path("chef-utils", __dir__) if File.exist?(File.expand_path("chef-utils", __dir__))
8
8
  gem "chef-config", path: File.expand_path("chef-config", __dir__) if File.exist?(File.expand_path("chef-config", __dir__))
@@ -15,7 +15,7 @@ else
15
15
  gem "chef-bin" # rubocop:disable Bundler/DuplicatedGem
16
16
  end
17
17
 
18
- gem "cheffish", ">= 17"
18
+ gem "cheffish", "~> 17.0"
19
19
 
20
20
  group(:omnibus_package) do
21
21
  gem "appbundler"
@@ -29,7 +29,7 @@ group(:omnibus_package, :pry) do
29
29
  # some work is ongoing? https://github.com/deivid-rodriguez/pry-byebug/issues/343
30
30
  gem "pry", "= 0.13.0"
31
31
  # byebug does not install on freebsd on ruby 3.0
32
- gem "pry-byebug" unless RUBY_PLATFORM =~ /freebsd/i
32
+ gem "pry-byebug" unless RUBY_PLATFORM.match?(/freebsd/i)
33
33
  gem "pry-stack_explorer"
34
34
  end
35
35
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Chef Infra
2
2
  [![Code Climate](https://codeclimate.com/github/chef/chef.svg)](https://codeclimate.com/github/chef/chef)
3
- [![Build Status](https://badge.buildkite.com/c82093430ceec7d27af05febb9dcafe3aa331fff9d74c0ab9d.svg?branch=master)](https://buildkite.com/chef-oss/chef-chef-master-verify)
3
+ [![Build Status](https://badge.buildkite.com/c82093430ceec7d27af05febb9dcafe3aa331fff9d74c0ab9d.svg?branch=chef-17)](https://buildkite.com/chef-oss/chef-chef-chef-17-verify)
4
4
  [![Gem Version](https://badge.fury.io/rb/chef.svg)](https://badge.fury.io/rb/chef)
5
5
  [![](https://img.shields.io/badge/Release%20Policy-Cadence%20Release-brightgreen.svg)](https://github.com/chef/chef/blob/master/docs/dev/design_documents/client_release_cadence.md)
6
6
 
@@ -90,45 +90,31 @@ class Chef
90
90
  end
91
91
 
92
92
  def reboot_scheduled?(exception)
93
- resolve_exception_array(exception).any? do |e|
94
- e.is_a? Chef::Exceptions::Reboot
95
- end
93
+ resolve_exception_array(exception).any?(Chef::Exceptions::Reboot)
96
94
  end
97
95
 
98
96
  def reboot_needed?(exception)
99
- resolve_exception_array(exception).any? do |e|
100
- e.is_a? Chef::Exceptions::RebootPending
101
- end
97
+ resolve_exception_array(exception).any?(Chef::Exceptions::RebootPending)
102
98
  end
103
99
 
104
100
  def reboot_failed?(exception)
105
- resolve_exception_array(exception).any? do |e|
106
- e.is_a? Chef::Exceptions::RebootFailed
107
- end
101
+ resolve_exception_array(exception).any?(Chef::Exceptions::RebootFailed)
108
102
  end
109
103
 
110
104
  def configuration_failure?(exception)
111
- resolve_exception_array(exception).any? do |e|
112
- e.is_a? Chef::Exceptions::ConfigurationError
113
- end
105
+ resolve_exception_array(exception).any?(Chef::Exceptions::ConfigurationError)
114
106
  end
115
107
 
116
108
  def client_upgraded?(exception)
117
- resolve_exception_array(exception).any? do |e|
118
- e.is_a? Chef::Exceptions::ClientUpgraded
119
- end
109
+ resolve_exception_array(exception).any?(Chef::Exceptions::ClientUpgraded)
120
110
  end
121
111
 
122
112
  def sigint_received?(exception)
123
- resolve_exception_array(exception).any? do |e|
124
- e.is_a? Chef::Exceptions::SigInt
125
- end
113
+ resolve_exception_array(exception).any?(Chef::Exceptions::SigInt)
126
114
  end
127
115
 
128
116
  def sigterm_received?(exception)
129
- resolve_exception_array(exception).any? do |e|
130
- e.is_a? Chef::Exceptions::SigTerm
131
- end
117
+ resolve_exception_array(exception).any?(Chef::Exceptions::SigTerm)
132
118
  end
133
119
 
134
120
  def resolve_exception_array(exception)
@@ -38,7 +38,7 @@ class Chef
38
38
 
39
39
  def read
40
40
  tmpfile = rest.streaming_request(file[:url])
41
- File.open(tmpfile, "rb", &:read)
41
+ File.binread(tmpfile)
42
42
  rescue Timeout::Error => e
43
43
  raise Chef::ChefFS::FileSystem::OperationFailedError.new(:read, self, e, "Timeout reading #{file[:url]}: #{e}")
44
44
  rescue Net::HTTPClientException => e
@@ -123,7 +123,7 @@ class Chef
123
123
  if is_ruby_file?
124
124
  data_handler.from_ruby(file_path).to_json
125
125
  else
126
- File.open(file_path, "rb", &:read)
126
+ File.binread(file_path)
127
127
  end
128
128
  rescue Errno::ENOENT
129
129
  raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
@@ -126,7 +126,7 @@ class Chef
126
126
  end
127
127
 
128
128
  def read
129
- File.open(file_path, "rb", &:read)
129
+ File.binread(file_path)
130
130
  rescue Errno::ENOENT
131
131
  raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
132
132
  end
@@ -27,7 +27,7 @@ class Chef
27
27
 
28
28
  # Controls what is done with the resulting report after the Chef InSpec run.
29
29
  # Accepts a single string value or an array of multiple values.
30
- # Accepted values: 'chef-server-automate', 'chef-automate', 'json-file', 'audit-enforcer', 'cli'
30
+ # Accepted values: 'chef-server-automate', 'chef-automate', 'json-file', 'audit-enforcer', 'compliance-enforcer', 'cli'
31
31
  "reporter" => nil,
32
32
 
33
33
  # Controls if Chef InSpec profiles should be fetched from Chef Automate or Chef Infra Server
@@ -57,7 +57,7 @@ class Chef
57
57
  # @return [Array<Input>] inspec inputs which are enabled in a form suitable to pass to inspec
58
58
  #
59
59
  def inspec_data
60
- select(&:enabled?).each_with_object({}) { |input, hash| hash.merge(input.inspec_data) }
60
+ select(&:enabled?).each_with_object({}) { |input, hash| hash.merge!(input.inspec_data) }
61
61
  end
62
62
 
63
63
  # DSL method to enable input files. This matches on the filename of the input file.
@@ -1,7 +1,7 @@
1
1
  class Chef
2
2
  module Compliance
3
3
  module Reporter
4
- class AuditEnforcer
4
+ class ComplianceEnforcer
5
5
  class ControlFailure < StandardError; end
6
6
 
7
7
  def send_report(report)
@@ -7,7 +7,7 @@ class Chef
7
7
  class Runner < EventDispatch::Base
8
8
  extend Forwardable
9
9
 
10
- SUPPORTED_REPORTERS = %w{chef-automate chef-server-automate json-file audit-enforcer cli}.freeze
10
+ SUPPORTED_REPORTERS = %w{chef-automate chef-server-automate json-file audit-enforcer compliance-enforcer cli}.freeze
11
11
  SUPPORTED_FETCHERS = %w{chef-automate chef-server}.freeze
12
12
 
13
13
  attr_accessor :run_id
@@ -300,7 +300,7 @@ class Chef
300
300
  require_relative "reporter/json_file"
301
301
  path = node.dig("audit", "json_file", "location")
302
302
  Chef::Compliance::Reporter::JsonFile.new(file: path)
303
- when "audit-enforcer"
303
+ when "audit-enforcer", "compliance-enforcer"
304
304
  require_relative "reporter/compliance_enforcer"
305
305
  Chef::Compliance::Reporter::ComplianceEnforcer.new
306
306
  when "cli"
@@ -57,7 +57,7 @@ class Chef
57
57
  # @return [Array<Waiver>] inspec waivers which are enabled in a form suitable to pass to inspec
58
58
  #
59
59
  def inspec_data
60
- select(&:enabled?).each_with_object({}) { |waiver, hash| hash.merge(waiver.inspec_data) }
60
+ select(&:enabled?).each_with_object({}) { |waiver, hash| hash.merge!(waiver.inspec_data) }
61
61
  end
62
62
 
63
63
  # DSL method to enable waiver files. This matches on the filename of the waiver file.
@@ -113,7 +113,7 @@ class Chef
113
113
  end
114
114
 
115
115
  def remove_uninteresting_ruby_files(file_list)
116
- file_list.reject { |f| f =~ %r{#{Regexp.quote(cookbook_path)}/(files|templates)/} }
116
+ file_list.grep_v(%r{#{Regexp.quote(cookbook_path)}/(files|templates)/})
117
117
  end
118
118
 
119
119
  def ruby_files
@@ -119,7 +119,7 @@ class Chef
119
119
  # but we need the base64 encoding for the content-md5
120
120
  # header
121
121
  checksum64 = Base64.encode64([checksum].pack("H*")).strip
122
- file_contents = File.open(file, "rb", &:read)
122
+ file_contents = File.binread(file)
123
123
 
124
124
  # Custom headers. 'content-type' disables JSON serialization of the request body.
125
125
  headers = { "content-type" => "application/x-binary", "content-md5" => checksum64, "accept" => "application/json" }
@@ -598,7 +598,7 @@ class Chef
598
598
  filename = record[:name]
599
599
  base_dup_name = File.join(File.dirname(filename), File.basename(filename, File.extname(filename)))
600
600
  yml_files.each do |other|
601
- if other[:name] =~ /#{(File.extname(filename) == ".yml") ? "#{base_dup_name}.yaml" : "#{base_dup_name}.yml"}$/
601
+ if /#{(File.extname(filename) == ".yml") ? "#{base_dup_name}.yaml" : "#{base_dup_name}.yml"}$/.match?(other[:name])
602
602
  raise Chef::Exceptions::AmbiguousYAMLFile.new("Cookbook #{name}@#{version} contains ambiguous files: #{filename} and #{other[:name]}. Please update the cookbook to remove the incorrect file.")
603
603
  end
604
604
  end
@@ -120,7 +120,7 @@ class Chef
120
120
  @status = shell_out("ifconfig")
121
121
  @status.stdout.each_line do |line|
122
122
  addr_regex = /^((\w|-)+):?(\d*):?\ .+$/
123
- if line =~ addr_regex
123
+ if line&.match?(addr_regex)
124
124
  if line.match(addr_regex).nil?
125
125
  @int_name = "nil"
126
126
  elsif line.match(addr_regex)[3] == ""
@@ -658,7 +658,7 @@ class Chef
658
658
  end
659
659
 
660
660
  def allow_downgrade
661
- if new_resource.respond_to?("allow_downgrade")
661
+ if new_resource.respond_to?(:allow_downgrade)
662
662
  new_resource.allow_downgrade
663
663
  else
664
664
  true
@@ -339,7 +339,7 @@ class Chef
339
339
  end
340
340
 
341
341
  def locked?
342
- user_plist[:auth_authority].any? { |tag| tag == ";DisabledUser;" }
342
+ user_plist[:auth_authority].any?(";DisabledUser;")
343
343
  rescue
344
344
  false
345
345
  end
@@ -411,7 +411,7 @@ class Chef
411
411
  end
412
412
 
413
413
  def secure_token_enabled?
414
- user_plist[:auth_authority].any? { |tag| tag == ";SecureToken;" }
414
+ user_plist[:auth_authority].any?(";SecureToken;")
415
415
  rescue
416
416
  false
417
417
  end
@@ -505,7 +505,7 @@ class Chef
505
505
  end
506
506
 
507
507
  def admin_user?
508
- admin_group_plist[:group_members].any? { |mem| mem == user_plist[:guid][0] }
508
+ admin_group_plist[:group_members].any?(user_plist[:guid][0])
509
509
  rescue
510
510
  false
511
511
  end
@@ -20,6 +20,12 @@
20
20
 
21
21
  require_relative "../resource"
22
22
  require "fileutils" unless defined?(FileUtils)
23
+ begin
24
+ # ffi-libarchive must be eager loaded see: https://github.com/chef/chef/issues/12228
25
+ require "ffi-libarchive" unless defined?(Archive::Reader)
26
+ rescue LoadError
27
+ STDERR.puts "ffi-libarchive could not be loaded, libarchive is probably not installed on system, archive_file will not be available"
28
+ end
23
29
 
24
30
  class Chef
25
31
  class Resource
@@ -92,8 +98,6 @@ class Chef
92
98
 
93
99
  action :extract, description: "Extract and archive file." do
94
100
 
95
- require_libarchive
96
-
97
101
  unless ::File.exist?(new_resource.path)
98
102
  raise Errno::ENOENT, "No archive found at #{new_resource.path}! Cannot continue."
99
103
  end
@@ -131,10 +135,6 @@ class Chef
131
135
  end
132
136
 
133
137
  action_class do
134
- def require_libarchive
135
- require "ffi-libarchive"
136
- end
137
-
138
138
  def define_resource_requirements
139
139
  if new_resource.mode.is_a?(Integer)
140
140
  Chef.deprecated(:archive_file_integer_file_mode, "The mode property should be passed to archive_file resources as a String and not an Integer to ensure the value is properly interpreted.")
@@ -284,7 +284,7 @@ class Chef
284
284
  if new_resource.peer
285
285
  peer_list = []
286
286
  new_resource.peer.each do |p|
287
- peer_list << if p !~ /.*:.*/
287
+ peer_list << if !/.*:.*/.match?(p)
288
288
  p + ":9632"
289
289
  else
290
290
  p
@@ -15,7 +15,7 @@
15
15
  # limitations under the License.
16
16
  #
17
17
 
18
- require "win32/service" if RUBY_PLATFORM =~ /mswin|mingw32|windows/
18
+ require "win32/service" if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
19
19
  require_relative "habitat_sup"
20
20
 
21
21
  class Chef
@@ -53,7 +53,7 @@ class Chef
53
53
  action :tap, description: "Add a Homebrew tap." do
54
54
  unless tapped?(new_resource.tap_name)
55
55
  converge_by("tap #{new_resource.tap_name}") do
56
- shell_out!("#{new_resource.homebrew_path} tap #{new_resource.full ? "--full" : ""} #{new_resource.tap_name} #{new_resource.url || ""}",
56
+ shell_out!("#{new_resource.homebrew_path} tap #{new_resource.tap_name} #{new_resource.url || ""}",
57
57
  user: new_resource.owner,
58
58
  env: { "HOME" => ::Dir.home(new_resource.owner), "USER" => new_resource.owner },
59
59
  cwd: ::Dir.home(new_resource.owner))
@@ -135,7 +135,7 @@ class Chef
135
135
 
136
136
  action_class do
137
137
  def load_waiver_file_to_hash(file_name)
138
- if file_name =~ %r{(/|C:\\).*(.yaml|.yml)}i
138
+ if %r{(/|C:\\).*(.yaml|.yml)}i.match?(file_name)
139
139
  if ::File.exist?(file_name)
140
140
  hash = ::YAML.load_file(file_name)
141
141
  if hash == false || hash.nil? || hash == ""
@@ -84,7 +84,7 @@ class Chef
84
84
  end
85
85
 
86
86
  # Check to make sure that our array only has hashes
87
- unless array.all? { |obj| obj.is_a?(Hash) }
87
+ unless array.all?(Hash)
88
88
  error_msg = "start_calendar_interval must be a single hash or an array of hashes!"
89
89
  raise Chef::Exceptions::ValidationFailed, error_msg
90
90
  end
@@ -98,7 +98,7 @@ class Chef
98
98
  raise Chef::Exceptions::ValidationFailed, error_msg
99
99
  end
100
100
 
101
- unless entry.values.all? { |val| val.is_a?(Integer) }
101
+ unless entry.values.all?(Integer)
102
102
  failed_values = entry.values.reject { |val| val.is_a?(Integer) }.join(", ")
103
103
  error_msg = "Invalid value(s) (#{failed_values}) for start_calendar_interval item. Values must be integers!"
104
104
  raise Chef::Exceptions::ValidationFailed, error_msg
@@ -54,7 +54,7 @@ class Chef
54
54
  resource_class.run_context = run_context
55
55
  resource_class.class_from_file(filename)
56
56
 
57
- if !resource_class.unified_mode && !deprecated_class(resource_class)
57
+ if !resource_class.unified_mode && !deprecated_class(resource_class) && cookbook_name.to_s != "chef_client_updater"
58
58
  Chef.deprecated :unified_mode, "The #{resource_class.resource_name} resource in the #{cookbook_name} cookbook should declare `unified_mode true`", filename
59
59
  end
60
60
 
@@ -138,7 +138,7 @@ class Chef
138
138
  nil
139
139
  elsif args[0].is_a?(Chef::DelayedEvaluator) && args.count == 1
140
140
  args[0]
141
- elsif args.any? { |a| a.is_a?(Chef::DelayedEvaluator) } && args.count > 1
141
+ elsif args.any?(Chef::DelayedEvaluator) && args.count > 1
142
142
  raise Exceptions::InvalidRemoteFileURI, "Only 1 source argument allowed when using a lazy evaluator"
143
143
  else
144
144
  Array(args).flatten
data/lib/chef/resource.rb CHANGED
@@ -311,7 +311,7 @@ class Chef
311
311
  # file '/foo.txt' do
312
312
  # content 'hi'
313
313
  # action :nothing
314
- # subscribes :create, '/bar.txt'
314
+ # subscribes :create, bar
315
315
  # end
316
316
  # @example Multiple resources by string
317
317
  # file '/foo.txt' do
@@ -341,6 +341,7 @@ class Chef
341
341
  def subscribes(action, resources, timing = :delayed)
342
342
  resources = [resources].flatten
343
343
  resources.each do |resource|
344
+ validate_resource_spec!(resource)
344
345
  if resource.is_a?(String)
345
346
  resource = UnresolvedSubscribes.new(resource, run_context)
346
347
  end
@@ -1096,7 +1097,7 @@ class Chef
1096
1097
  rescue NameError => e
1097
1098
  # This can happen when attempting to load a provider in a platform-specific
1098
1099
  # environment where we have not required the necessary files yet
1099
- raise unless e.message =~ /uninitialized constant/
1100
+ raise unless /uninitialized constant/.match?(e.message)
1100
1101
  end
1101
1102
 
1102
1103
  # Define a method to load up this resource's properties with the current
@@ -34,7 +34,7 @@ class Chef
34
34
  as_hash["after"] = new_resource.state_for_resource_reporter
35
35
  as_hash["before"] = current_resource ? current_resource.state_for_resource_reporter : {}
36
36
  as_hash["duration"] = ( action_record.elapsed_time * 1000 ).to_i.to_s
37
- as_hash["delta"] = new_resource.diff if new_resource.respond_to?("diff")
37
+ as_hash["delta"] = new_resource.diff if new_resource.respond_to?(:diff)
38
38
  as_hash["delta"] = "" if as_hash["delta"].nil?
39
39
 
40
40
  # TODO: rename as "action"
data/lib/chef/run_lock.rb CHANGED
@@ -144,7 +144,7 @@ class Chef
144
144
  # If we support FD_CLOEXEC, then use it.
145
145
  # NB: ruby-2.0.0-p195 sets FD_CLOEXEC by default, but not
146
146
  # ruby-1.8.7/1.9.3
147
- if Fcntl.const_defined?("F_SETFD") && Fcntl.const_defined?("FD_CLOEXEC")
147
+ if Fcntl.const_defined?(:F_SETFD) && Fcntl.const_defined?(:FD_CLOEXEC)
148
148
  runlock.fcntl(Fcntl::F_SETFD, runlock.fcntl(Fcntl::F_GETFD, 0) | Fcntl::FD_CLOEXEC)
149
149
  end
150
150
  # Flock will return 0 if it can acquire the lock otherwise it
@@ -59,7 +59,7 @@ class Chef
59
59
  end
60
60
 
61
61
  def validate!
62
- raise Chef::Exceptions::Secret::ConfigurationInvalid, "You may only specify one (these are mutually exclusive): :object_id, :client_id, or :mi_res_id" if [object_id, client_id, mi_res_id].select { |x| !x.nil? }.length > 1
62
+ raise Chef::Exceptions::Secret::ConfigurationInvalid, "You may only specify one (these are mutually exclusive): :object_id, :client_id, or :mi_res_id" if [object_id, client_id, mi_res_id].count { |x| !x.nil? } > 1
63
63
  end
64
64
 
65
65
  private
@@ -123,7 +123,7 @@ class Chef
123
123
  body["access_token"]
124
124
  when Net::HTTPBadRequest
125
125
  body = JSON.parse(response.body)
126
- raise Chef::Exceptions::Secret::Azure::IdentityNotFound if body["error_description"] =~ /identity not found/i
126
+ raise Chef::Exceptions::Secret::Azure::IdentityNotFound if /identity not found/i.match?(body["error_description"])
127
127
  else
128
128
  body = JSON.parse(response.body)
129
129
  body["access_token"]
@@ -175,7 +175,7 @@ class Chef::Util::DSC
175
175
  end
176
176
 
177
177
  def get_configuration_document(document_path)
178
- ::File.open(document_path, "rb", &:read)
178
+ ::File.binread(document_path)
179
179
  end
180
180
  end
181
181
  end
data/lib/chef/version.rb CHANGED
@@ -23,7 +23,7 @@ require_relative "version_string"
23
23
 
24
24
  class Chef
25
25
  CHEF_ROOT = File.expand_path("..", __dir__)
26
- VERSION = Chef::VersionString.new("17.9.18")
26
+ VERSION = Chef::VersionString.new("17.9.52")
27
27
  end
28
28
 
29
29
  #
@@ -18,8 +18,9 @@
18
18
  require "spec_helper"
19
19
  require "tmpdir"
20
20
 
21
- # Exclude this test on platforms where ffi-libarchive loading is broken
22
- describe Chef::Resource::ArchiveFile, :libarchive_loading_broken do
21
+ # AIX is broken, see https://github.com/chef/omnibus-software/issues/1566
22
+ # Windows tests are disbled since we'd need libarchive on windows testers in buildkite for PRs
23
+ describe Chef::Resource::ArchiveFile, :not_supported_on_aix, :not_supported_on_windows do
23
24
  include RecipeDSLHelper
24
25
 
25
26
  let(:tmp_path) { Dir.mktmpdir }
@@ -25,7 +25,7 @@ describe Chef::Resource::CookbookFile do
25
25
  let(:source) { "java.response" }
26
26
  let(:cookbook_name) { "java" }
27
27
  let(:expected_content) do
28
- content = File.open(File.join(CHEF_SPEC_DATA, "cookbooks", "java", "files", "default", "java.response"), "rb", &:read)
28
+ content = File.binread(File.join(CHEF_SPEC_DATA, "cookbooks", "java", "files", "default", "java.response"))
29
29
  content.force_encoding(Encoding::BINARY) if content.respond_to?(:force_encoding)
30
30
  content
31
31
  end
@@ -345,7 +345,7 @@ describe Chef::Resource::DscScript, :windows_powershell_dsc_only, :ruby64_only d
345
345
  let(:config_param_section) { config_params }
346
346
  let(:config_flags) { { "#{dsc_user_prefix_param_name}": (dsc_user_prefix).to_s, "#{dsc_user_suffix_param_name}": (dsc_user_suffix).to_s } }
347
347
  it "does not directly contain the user name" do
348
- configuration_script_content = ::File.open(dsc_test_resource.command, &:read)
348
+ configuration_script_content = ::File.read(dsc_test_resource.command)
349
349
  expect(configuration_script_content.include?(dsc_user)).to be(false)
350
350
  end
351
351
  it_behaves_like "a dsc_script with configuration data"
@@ -355,7 +355,7 @@ describe Chef::Resource::DscScript, :windows_powershell_dsc_only, :ruby64_only d
355
355
  let(:dsc_user_code) { dsc_user_env_code }
356
356
 
357
357
  it "does not directly contain the user name" do
358
- configuration_script_content = ::File.open(dsc_test_resource.command, &:read)
358
+ configuration_script_content = ::File.read(dsc_test_resource.command)
359
359
  expect(configuration_script_content.include?(dsc_user)).to be(false)
360
360
  end
361
361
  it_behaves_like "a dsc_script with configuration data"
@@ -21,7 +21,7 @@ require "spec_helper"
21
21
  describe Chef::Resource::Template do
22
22
 
23
23
  def binread(file)
24
- File.open(file, "rb", &:read)
24
+ File.binread(file)
25
25
  end
26
26
 
27
27
  include_context Chef::Resource::File
@@ -22,7 +22,7 @@ describe "chef-client" do
22
22
  # just a normal file
23
23
  # (expected_content should be uncompressed)
24
24
  @api.get("/recipes.tgz", 200) do
25
- File.open(recipes_filename, "rb", &:read)
25
+ File.binread(recipes_filename)
26
26
  end
27
27
  end
28
28
 
data/spec/spec_helper.rb CHANGED
@@ -78,9 +78,9 @@ require "spec/support/recipe_dsl_helper"
78
78
  # Excludes support/platforms by default
79
79
  # Do not change the gsub.
80
80
  Dir["spec/support/**/*.rb"]
81
- .reject { |f| f =~ %r{^spec/support/platforms} }
82
- .reject { |f| f =~ %r{^spec/support/pedant} }
83
- .reject { |f| f =~ %r{^spec/support/shared/integration/knife_support} }
81
+ .grep_v(%r{^spec/support/platforms})
82
+ .grep_v(%r{^spec/support/pedant})
83
+ .grep_v(%r{^spec/support/shared/integration/knife_support})
84
84
  .map { |f| f.gsub(/.rb$/, "") }
85
85
  .map { |f| f.gsub(%r{spec/}, "") }
86
86
  .each { |f| require f }
@@ -187,8 +187,6 @@ RSpec.configure do |config|
187
187
  config.filter_run_excluding not_rhel7: true if rhel7?
188
188
  config.filter_run_excluding not_intel_64bit: true if intel_64bit?
189
189
 
190
- config.filter_run_excluding libarchive_loading_broken: true if aix? || amazon_linux? || rhel7?
191
-
192
190
  # these let us use chef: ">= 13" or ruby: "~> 2.0.0" or any other Gem::Dependency-style constraint
193
191
  config.filter_run_excluding chef: DependencyProc.with(Chef::VERSION)
194
192
  config.filter_run_excluding ruby: DependencyProc.with(RUBY_VERSION)
@@ -172,7 +172,7 @@ def wpar?
172
172
  end
173
173
 
174
174
  def supports_cloexec?
175
- Fcntl.const_defined?("F_SETFD") && Fcntl.const_defined?("FD_CLOEXEC")
175
+ Fcntl.const_defined?(:F_SETFD) && Fcntl.const_defined?(:FD_CLOEXEC)
176
176
  end
177
177
 
178
178
  def selinux_enabled?
@@ -48,4 +48,4 @@ rescue LoadError
48
48
  $stderr.puts "Failed to load ruby_installer. Assuming Ruby Installer is not being used."
49
49
  end
50
50
 
51
- add_libarchive_dll_directory if RUBY_PLATFORM =~ /mswin|mingw32|windows/
51
+ add_libarchive_dll_directory if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
@@ -157,7 +157,7 @@ shared_examples_for "a file with the wrong content" do
157
157
 
158
158
  context "when running :create action" do
159
159
  let(:provider) { resource.provider_for_action(:create) }
160
- let(:reporter_messages) { provider.instance_variable_get("@converge_actions").actions[0][0] }
160
+ let(:reporter_messages) { provider.instance_variable_get(:@converge_actions).actions[0][0] }
161
161
 
162
162
  before do
163
163
  provider.run_action
@@ -391,7 +391,7 @@ shared_examples_for "a configured file resource" do
391
391
  end
392
392
 
393
393
  def binread(file)
394
- content = File.open(file, "rb", &:read)
394
+ content = File.binread(file)
395
395
  content.force_encoding(Encoding::BINARY) if "".respond_to?(:force_encoding)
396
396
  content
397
397
  end