summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2018-07-02 14:55:20 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2018-07-02 15:08:43 -0700
commit21189d25a9385aa9ff3368716824b8333475a08b (patch)
treed4316d70ff88b5a43ffff90d04bd789da51cf9d4 /lib/chef
parentfb6c052ae6d58db2499cf04ef0595d1e06a4c13c (diff)
downloadchef-21189d25a9385aa9ff3368716824b8333475a08b.tar.gz
fix Style/PreferredHashMethods
absolutely hard requirement on the fixes that went into chef-config 2.2.11, so the floor of that gem is bumped up. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/application/client.rb12
-rw-r--r--lib/chef/application/solo.rb2
-rw-r--r--lib/chef/application/windows_service.rb2
-rw-r--r--lib/chef/application/windows_service_manager.rb2
-rw-r--r--lib/chef/audit/audit_reporter.rb2
-rw-r--r--lib/chef/chef_fs/chef_fs_data_store.rb10
-rw-r--r--lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb2
-rw-r--r--lib/chef/cookbook/file_system_file_vendor.rb2
-rw-r--r--lib/chef/cookbook/metadata.rb36
-rw-r--r--lib/chef/cookbook/remote_file_vendor.rb2
-rw-r--r--lib/chef/cookbook/synchronizer.rb2
-rw-r--r--lib/chef/cookbook_loader.rb6
-rw-r--r--lib/chef/cookbook_version.rb2
-rw-r--r--lib/chef/data_bag.rb2
-rw-r--r--lib/chef/data_bag_item.rb2
-rw-r--r--lib/chef/dsl/audit.rb2
-rw-r--r--lib/chef/dsl/definitions.rb2
-rw-r--r--lib/chef/encrypted_data_bag_item/check_encrypted.rb2
-rw-r--r--lib/chef/file_cache.rb6
-rw-r--r--lib/chef/http/cookie_manager.rb2
-rw-r--r--lib/chef/http/json_input.rb2
-rw-r--r--lib/chef/http/json_to_model_output.rb2
-rw-r--r--lib/chef/json_compat.rb2
-rw-r--r--lib/chef/key.rb4
-rw-r--r--lib/chef/knife.rb8
-rw-r--r--lib/chef/knife/cookbook_show.rb8
-rw-r--r--lib/chef/knife/cookbook_upload.rb2
-rw-r--r--lib/chef/knife/core/bootstrap_context.rb6
-rw-r--r--lib/chef/knife/data_bag_secret_options.rb4
-rw-r--r--lib/chef/knife/ssh.rb4
-rw-r--r--lib/chef/mixin/deep_merge.rb2
-rw-r--r--lib/chef/mixin/params_validate.rb18
-rw-r--r--lib/chef/mixin/properties.rb4
-rw-r--r--lib/chef/node.rb18
-rw-r--r--lib/chef/node/attribute.rb8
-rw-r--r--lib/chef/node/mixin/deep_merge_cache.rb2
-rw-r--r--lib/chef/node_map.rb4
-rw-r--r--lib/chef/property.rb28
-rw-r--r--lib/chef/provider/registry_key.rb8
-rw-r--r--lib/chef/provider/remote_file/cache_control_data.rb4
-rw-r--r--lib/chef/provider/service/windows.rb2
-rw-r--r--lib/chef/resource.rb2
-rw-r--r--lib/chef/resource/registry_key.rb2
-rw-r--r--lib/chef/role.rb4
-rw-r--r--lib/chef/run_context.rb4
-rw-r--r--lib/chef/run_list/run_list_expansion.rb2
-rw-r--r--lib/chef/run_list/run_list_item.rb2
-rw-r--r--lib/chef/run_list/versioned_recipe_list.rb2
-rw-r--r--lib/chef/util/powershell/cmdlet.rb2
-rw-r--r--lib/chef/win32/security.rb12
50 files changed, 137 insertions, 135 deletions
diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb
index 6e574e682f..21a926eca1 100644
--- a/lib/chef/application/client.rb
+++ b/lib/chef/application/client.rb
@@ -316,18 +316,18 @@ class Chef::Application::Client < Chef::Application
set_specific_recipes
- Chef::Config[:fips] = config[:fips] if config.has_key? :fips
+ Chef::Config[:fips] = config[:fips] if config.key? :fips
- Chef::Config[:chef_server_url] = config[:chef_server_url] if config.has_key? :chef_server_url
+ Chef::Config[:chef_server_url] = config[:chef_server_url] if config.key? :chef_server_url
- Chef::Config.local_mode = config[:local_mode] if config.has_key?(:local_mode)
+ Chef::Config.local_mode = config[:local_mode] if config.key?(:local_mode)
- if Chef::Config.has_key?(:chef_repo_path) && Chef::Config.chef_repo_path.nil?
+ if Chef::Config.key?(:chef_repo_path) && Chef::Config.chef_repo_path.nil?
Chef::Config.delete(:chef_repo_path)
Chef::Log.warn "chef_repo_path was set in a config file but was empty. Assuming #{Chef::Config.chef_repo_path}"
end
- if Chef::Config.local_mode && !Chef::Config.has_key?(:cookbook_path) && !Chef::Config.has_key?(:chef_repo_path)
+ if Chef::Config.local_mode && !Chef::Config.key?(:cookbook_path) && !Chef::Config.key?(:chef_repo_path)
Chef::Config.chef_repo_path = Chef::Config.find_chef_repo_path(Dir.pwd)
end
@@ -384,7 +384,7 @@ class Chef::Application::Client < Chef::Application
end
def load_config_file
- if !config.has_key?(:config_file) && !config[:disable_config]
+ if !config.key?(:config_file) && !config[:disable_config]
if config[:local_mode]
config[:config_file] = Chef::WorkstationConfigLoader.new(nil, Chef::Log).config_location
else
diff --git a/lib/chef/application/solo.rb b/lib/chef/application/solo.rb
index cd364dc6ae..ee7d1530ed 100644
--- a/lib/chef/application/solo.rb
+++ b/lib/chef/application/solo.rb
@@ -244,7 +244,7 @@ class Chef::Application::Solo < Chef::Application
# For back compat reasons, we need to ensure that we try and use the cache_path as a repo first
Chef::Log.trace "Current chef_repo_path is #{Chef::Config.chef_repo_path}"
- if !Chef::Config.has_key?(:cookbook_path) && !Chef::Config.has_key?(:chef_repo_path)
+ if !Chef::Config.key?(:cookbook_path) && !Chef::Config.key?(:chef_repo_path)
Chef::Config.chef_repo_path = Chef::Config.find_chef_repo_path(Chef::Config[:cache_path])
end
diff --git a/lib/chef/application/windows_service.rb b/lib/chef/application/windows_service.rb
index 5fe4dbb9b7..b49c12c312 100644
--- a/lib/chef/application/windows_service.rb
+++ b/lib/chef/application/windows_service.rb
@@ -228,7 +228,7 @@ class Chef
configure_chef startup_parameters
configure_logging
- Chef::Config[:chef_server_url] = config[:chef_server_url] if config.has_key? :chef_server_url
+ Chef::Config[:chef_server_url] = config[:chef_server_url] if config.key? :chef_server_url
unless Chef::Config[:exception_handlers].any? { |h| Chef::Handler::ErrorReport === h }
Chef::Config[:exception_handlers] << Chef::Handler::ErrorReport.new
end
diff --git a/lib/chef/application/windows_service_manager.rb b/lib/chef/application/windows_service_manager.rb
index bff4a7511a..0572169ca3 100644
--- a/lib/chef/application/windows_service_manager.rb
+++ b/lib/chef/application/windows_service_manager.rb
@@ -80,7 +80,7 @@ class Chef
required_options = [:service_name, :service_display_name, :service_description, :service_file_path]
required_options.each do |req_option|
- if !service_options.has_key?(req_option)
+ if !service_options.key?(req_option)
raise ArgumentError, "Service definition doesn't contain required option #{req_option}"
end
end
diff --git a/lib/chef/audit/audit_reporter.rb b/lib/chef/audit/audit_reporter.rb
index bb5537b97b..1dfb11f53b 100644
--- a/lib/chef/audit/audit_reporter.rb
+++ b/lib/chef/audit/audit_reporter.rb
@@ -78,7 +78,7 @@ class Chef
end
def control_group_started(name)
- if ordered_control_groups.has_key?(name)
+ if ordered_control_groups.key?(name)
raise Chef::Exceptions::AuditControlGroupDuplicate.new(name)
end
metadata = run_context.audits[name].metadata
diff --git a/lib/chef/chef_fs/chef_fs_data_store.rb b/lib/chef/chef_fs/chef_fs_data_store.rb
index c42f08a462..7fa69bf497 100644
--- a/lib/chef/chef_fs/chef_fs_data_store.rb
+++ b/lib/chef/chef_fs/chef_fs_data_store.rb
@@ -210,7 +210,7 @@ class Chef
elsif path[0] == "policy_groups" && path[2] == "policies"
# Just set or create the proper entry in the hash
update_json(to_chef_fs_path(path[0..1]), {}, *options) do |group|
- if policies.has_key?(path[3])
+ if policies.key?(path[3])
raise ChefZero::DataStore::DataAlreadyExistsError.new(path, group)
end
@@ -319,7 +319,7 @@ class Chef
result.each_pair do |key, value|
if value.is_a?(Array)
value.each do |file|
- if file.is_a?(Hash) && file.has_key?("checksum")
+ if file.is_a?(Hash) && file.key?("checksum")
relative = ["file_store", "repo", cookbook_type]
if chef_fs.versioned_cookbooks || cookbook_type == "cookbook_artifacts"
relative << "#{path[1]}-#{path[2]}"
@@ -398,7 +398,7 @@ class Chef
# DELETE /policy_groups/GROUP/policies/POLICY
elsif path[0] == "policy_groups" && path[2] == "policies" && path.length == 4
update_json(to_chef_fs_path(path[0..1]), {}) do |group|
- unless group["policies"] && group["policies"].has_key?(path[3])
+ unless group["policies"] && group["policies"].key?(path[3])
raise ChefZero::DataStore::DataNotFoundError.new(path)
end
group["policies"].delete(path[3])
@@ -581,7 +581,7 @@ class Chef
# /policy_groups/NAME/policies/POLICYNAME
elsif path[0] == "policy_groups" && path[2] == "policies" && path.length == 4
group = get_json(to_chef_fs_path(path[0..1]), {})
- group["policies"] && group["policies"].has_key?(path[3])
+ group["policies"] && group["policies"].key?(path[3])
else
path_always_exists?(path) || Chef::ChefFS::FileSystem.resolve_path(chef_fs, to_chef_fs_path(path)).exists?
@@ -628,7 +628,7 @@ class Chef
cookbook.each_pair do |key, value|
if value.is_a?(Array)
value.each do |file|
- if file.is_a?(Hash) && file.has_key?("checksum")
+ if file.is_a?(Hash) && file.key?("checksum")
file_data = @memory_store.get(["file_store", "checksums", file["checksum"]])
cookbook_fs.add_file(File.join(cookbook_path, file["path"]), file_data)
end
diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb
index 9ea9268ab1..7f14b4d5e8 100644
--- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb
+++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb
@@ -96,7 +96,7 @@ class Chef
def can_have_child?(name, is_dir)
if is_dir
- child_paths.has_key?(name)
+ child_paths.key?(name)
elsif root_dir
CHILDREN.include?(name)
else
diff --git a/lib/chef/cookbook/file_system_file_vendor.rb b/lib/chef/cookbook/file_system_file_vendor.rb
index 1f43095ea3..d8ec9b86d2 100644
--- a/lib/chef/cookbook/file_system_file_vendor.rb
+++ b/lib/chef/cookbook/file_system_file_vendor.rb
@@ -48,7 +48,7 @@ class Chef
# Chef::Config.cookbook_path file hierarchy for the requested
# file.
def get_filename(filename)
- location = File.join(cookbooks[cookbook_name].root_dir, filename) if cookbooks.has_key?(cookbook_name)
+ location = File.join(cookbooks[cookbook_name].root_dir, filename) if cookbooks.key?(cookbook_name)
raise "File #{filename} does not exist for cookbook #{cookbook_name}" unless location && File.exist?(location)
location
end
diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb
index 03e2d7a090..a07844e0a4 100644
--- a/lib/chef/cookbook/metadata.rb
+++ b/lib/chef/cookbook/metadata.rb
@@ -499,24 +499,24 @@ class Chef
end
def from_hash(o)
- @name = o[NAME] if o.has_key?(NAME)
- @description = o[DESCRIPTION] if o.has_key?(DESCRIPTION)
- @long_description = o[LONG_DESCRIPTION] if o.has_key?(LONG_DESCRIPTION)
- @maintainer = o[MAINTAINER] if o.has_key?(MAINTAINER)
- @maintainer_email = o[MAINTAINER_EMAIL] if o.has_key?(MAINTAINER_EMAIL)
- @license = o[LICENSE] if o.has_key?(LICENSE)
- @platforms = o[PLATFORMS] if o.has_key?(PLATFORMS)
- @dependencies = handle_deprecated_constraints(o[DEPENDENCIES]) if o.has_key?(DEPENDENCIES)
- @providing = o[PROVIDING] if o.has_key?(PROVIDING)
- @attributes = o[ATTRIBUTES] if o.has_key?(ATTRIBUTES)
- @recipes = o[RECIPES] if o.has_key?(RECIPES)
- @version = o[VERSION] if o.has_key?(VERSION)
- @source_url = o[SOURCE_URL] if o.has_key?(SOURCE_URL)
- @issues_url = o[ISSUES_URL] if o.has_key?(ISSUES_URL)
- @privacy = o[PRIVACY] if o.has_key?(PRIVACY)
- @chef_versions = gem_requirements_from_array("chef", o[CHEF_VERSIONS]) if o.has_key?(CHEF_VERSIONS)
- @ohai_versions = gem_requirements_from_array("ohai", o[OHAI_VERSIONS]) if o.has_key?(OHAI_VERSIONS)
- @gems = o[GEMS] if o.has_key?(GEMS)
+ @name = o[NAME] if o.key?(NAME)
+ @description = o[DESCRIPTION] if o.key?(DESCRIPTION)
+ @long_description = o[LONG_DESCRIPTION] if o.key?(LONG_DESCRIPTION)
+ @maintainer = o[MAINTAINER] if o.key?(MAINTAINER)
+ @maintainer_email = o[MAINTAINER_EMAIL] if o.key?(MAINTAINER_EMAIL)
+ @license = o[LICENSE] if o.key?(LICENSE)
+ @platforms = o[PLATFORMS] if o.key?(PLATFORMS)
+ @dependencies = handle_deprecated_constraints(o[DEPENDENCIES]) if o.key?(DEPENDENCIES)
+ @providing = o[PROVIDING] if o.key?(PROVIDING)
+ @attributes = o[ATTRIBUTES] if o.key?(ATTRIBUTES)
+ @recipes = o[RECIPES] if o.key?(RECIPES)
+ @version = o[VERSION] if o.key?(VERSION)
+ @source_url = o[SOURCE_URL] if o.key?(SOURCE_URL)
+ @issues_url = o[ISSUES_URL] if o.key?(ISSUES_URL)
+ @privacy = o[PRIVACY] if o.key?(PRIVACY)
+ @chef_versions = gem_requirements_from_array("chef", o[CHEF_VERSIONS]) if o.key?(CHEF_VERSIONS)
+ @ohai_versions = gem_requirements_from_array("ohai", o[OHAI_VERSIONS]) if o.key?(OHAI_VERSIONS)
+ @gems = o[GEMS] if o.key?(GEMS)
self
end
diff --git a/lib/chef/cookbook/remote_file_vendor.rb b/lib/chef/cookbook/remote_file_vendor.rb
index 7db0cb8686..eea2ecf242 100644
--- a/lib/chef/cookbook/remote_file_vendor.rb
+++ b/lib/chef/cookbook/remote_file_vendor.rb
@@ -55,7 +55,7 @@ class Chef
validate_cached_copy(cache_filename)
current_checksum = nil
- if Chef::FileCache.has_key?(cache_filename)
+ if Chef::FileCache.key?(cache_filename)
current_checksum = Chef::CookbookVersion.checksum_cookbook_file(Chef::FileCache.load(cache_filename, false))
end
diff --git a/lib/chef/cookbook/synchronizer.rb b/lib/chef/cookbook/synchronizer.rb
index 6955abd6d7..66ced8a9b9 100644
--- a/lib/chef/cookbook/synchronizer.rb
+++ b/lib/chef/cookbook/synchronizer.rb
@@ -281,7 +281,7 @@ class Chef
def cached_copy_up_to_date?(local_path, expected_checksum)
return true if Chef::Config[:skip_cookbook_sync]
- if cache.has_key?(local_path)
+ if cache.key?(local_path)
current_checksum = CookbookVersion.checksum_cookbook_file(cache.load(local_path, false))
expected_checksum == current_checksum
else
diff --git a/lib/chef/cookbook_loader.rb b/lib/chef/cookbook_loader.rb
index 1cd498496a..32fd71f604 100644
--- a/lib/chef/cookbook_loader.rb
+++ b/lib/chef/cookbook_loader.rb
@@ -93,7 +93,7 @@ class Chef
def load_cookbook(cookbook_name)
preload_cookbooks
- return @cookbooks_by_name[cookbook_name] if @cookbooks_by_name.has_key?(cookbook_name)
+ return @cookbooks_by_name[cookbook_name] if @cookbooks_by_name.key?(cookbook_name)
return nil unless @loaders_by_name.key?(cookbook_name.to_s)
@@ -112,7 +112,7 @@ class Chef
end
end
- if @loaded_cookbooks.has_key?(cookbook_name)
+ if @loaded_cookbooks.key?(cookbook_name)
cookbook_version = @loaded_cookbooks[cookbook_name].cookbook_version
@cookbooks_by_name[cookbook_name] = cookbook_version
@metadata[cookbook_name] = cookbook_version.metadata
@@ -121,7 +121,7 @@ class Chef
end
def [](cookbook)
- if @cookbooks_by_name.has_key?(cookbook.to_sym) || load_cookbook(cookbook.to_sym)
+ if @cookbooks_by_name.key?(cookbook.to_sym) || load_cookbook(cookbook.to_sym)
@cookbooks_by_name[cookbook.to_sym]
else
raise Exceptions::CookbookNotFoundInRepo, "Cannot find a cookbook named #{cookbook}; did you forget to add metadata to a cookbook? (https://docs.chef.io/config_rb_metadata.html)"
diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb
index 29d74cc252..6ac4bb24be 100644
--- a/lib/chef/cookbook_version.rb
+++ b/lib/chef/cookbook_version.rb
@@ -184,7 +184,7 @@ class Chef
# called from DSL
def load_recipe(recipe_name, run_context)
- unless recipe_filenames_by_name.has_key?(recipe_name)
+ unless recipe_filenames_by_name.key?(recipe_name)
raise Chef::Exceptions::RecipeNotFound, "could not find recipe #{recipe_name} for cookbook #{name}"
end
diff --git a/lib/chef/data_bag.rb b/lib/chef/data_bag.rb
index 9a71d89abb..b7b5391c59 100644
--- a/lib/chef/data_bag.rb
+++ b/lib/chef/data_bag.rb
@@ -126,7 +126,7 @@ class Chef
item = Chef::JSONCompat.parse(IO.read(f))
# Check if we have multiple items with similar names (ids) and raise if their content differs
- if data_bag.has_key?(item["id"]) && data_bag[item["id"]] != item
+ if data_bag.key?(item["id"]) && data_bag[item["id"]] != item
raise Chef::Exceptions::DuplicateDataBagItem, "Data bag '#{name}' has items with the same name '#{item["id"]}' but different content."
else
data_bag[item["id"]] = item
diff --git a/lib/chef/data_bag_item.rb b/lib/chef/data_bag_item.rb
index 01ec4cf77e..0d07daa39e 100644
--- a/lib/chef/data_bag_item.rb
+++ b/lib/chef/data_bag_item.rb
@@ -90,7 +90,7 @@ class Chef
end
def object_name
- raise Exceptions::ValidationFailed, "You must have an 'id' or :id key in the raw data" unless raw_data.has_key?("id")
+ raise Exceptions::ValidationFailed, "You must have an 'id' or :id key in the raw data" unless raw_data.key?("id")
raise Exceptions::ValidationFailed, "You must have declared what bag this item belongs to!" unless data_bag
id = raw_data["id"]
diff --git a/lib/chef/dsl/audit.rb b/lib/chef/dsl/audit.rb
index 9ef798df91..927523e976 100644
--- a/lib/chef/dsl/audit.rb
+++ b/lib/chef/dsl/audit.rb
@@ -30,7 +30,7 @@ class Chef
name = args[0]
if name.nil? || name.empty?
raise Chef::Exceptions::AuditNameMissing
- elsif run_context.audits.has_key?(name)
+ elsif run_context.audits.key?(name)
raise Chef::Exceptions::AuditControlGroupDuplicate.new(name)
end
diff --git a/lib/chef/dsl/definitions.rb b/lib/chef/dsl/definitions.rb
index 60b1cf6f61..00f6d91739 100644
--- a/lib/chef/dsl/definitions.rb
+++ b/lib/chef/dsl/definitions.rb
@@ -18,7 +18,7 @@ class Chef
# @api private
def has_resource_definition?(name)
- run_context.definitions.has_key?(name)
+ run_context.definitions.key?(name)
end
# Processes the arguments and block as a resource definition.
diff --git a/lib/chef/encrypted_data_bag_item/check_encrypted.rb b/lib/chef/encrypted_data_bag_item/check_encrypted.rb
index cc378194ff..a266df6dd6 100644
--- a/lib/chef/encrypted_data_bag_item/check_encrypted.rb
+++ b/lib/chef/encrypted_data_bag_item/check_encrypted.rb
@@ -39,7 +39,7 @@ class Chef::EncryptedDataBagItem
# true only when there is an exact match between the VersionXEncryptor
# keys and the hash's keys.
def looks_like_encrypted?(data)
- return false unless data.is_a?(Hash) && data.has_key?("version")
+ return false unless data.is_a?(Hash) && data.key?("version")
case data["version"]
when 1
Chef::EncryptedDataBagItem::Encryptor::Version1Encryptor.encryptor_keys.sort == data.keys.sort
diff --git a/lib/chef/file_cache.rb b/lib/chef/file_cache.rb
index f1c261ecd0..eb1fd1f582 100644
--- a/lib/chef/file_cache.rb
+++ b/lib/chef/file_cache.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -175,7 +175,7 @@ class Chef
# === Returns
# True:: If the file exists
# False:: If it does not
- def has_key?(path)
+ def key?(path)
validate(
{
path: path,
@@ -192,6 +192,8 @@ class Chef
end
end
+ alias_method :has_key?, :key?
+
# Create a full path to a given file in the cache. By default,
# also creates the path if it does not exist.
#
diff --git a/lib/chef/http/cookie_manager.rb b/lib/chef/http/cookie_manager.rb
index 18824a8eff..723b26ad87 100644
--- a/lib/chef/http/cookie_manager.rb
+++ b/lib/chef/http/cookie_manager.rb
@@ -33,7 +33,7 @@ class Chef
def handle_request(method, url, headers = {}, data = false)
@host, @port = url.host, url.port
- if @cookies.has_key?("#{@host}:#{@port}")
+ if @cookies.key?("#{@host}:#{@port}")
headers["Cookie"] = @cookies["#{@host}:#{@port}"]
end
[method, url, headers, data]
diff --git a/lib/chef/http/json_input.rb b/lib/chef/http/json_input.rb
index 7cf2e4012f..e2c8b3e2ee 100644
--- a/lib/chef/http/json_input.rb
+++ b/lib/chef/http/json_input.rb
@@ -36,7 +36,7 @@ class Chef
headers.delete_if { |key, _value| key.casecmp("content-type") == 0 }
headers["Content-Type"] = "application/json"
json_opts = {}
- json_opts[:validate_utf8] = opts[:validate_utf8] if opts.has_key?(:validate_utf8)
+ json_opts[:validate_utf8] = opts[:validate_utf8] if opts.key?(:validate_utf8)
data = Chef::JSONCompat.to_json(data, json_opts)
# Force encoding to binary to fix SSL related EOFErrors
# cf. http://tickets.opscode.com/browse/CHEF-2363
diff --git a/lib/chef/http/json_to_model_output.rb b/lib/chef/http/json_to_model_output.rb
index 12ca1a90aa..997ceb8b1f 100644
--- a/lib/chef/http/json_to_model_output.rb
+++ b/lib/chef/http/json_to_model_output.rb
@@ -26,7 +26,7 @@ class Chef
# a `json_class` key.
class JSONToModelOutput < JSONOutput
def initialize(opts = {})
- opts[:inflate_json_class] = true if !opts.has_key?(:inflate_json_class)
+ opts[:inflate_json_class] = true if !opts.key?(:inflate_json_class)
super
end
end
diff --git a/lib/chef/json_compat.rb b/lib/chef/json_compat.rb
index b819d5e57d..00052208d2 100644
--- a/lib/chef/json_compat.rb
+++ b/lib/chef/json_compat.rb
@@ -59,7 +59,7 @@ class Chef
opts ||= {}
options_map = {}
options_map[:pretty] = true
- options_map[:indent] = opts[:indent] if opts.has_key?(:indent)
+ options_map[:indent] = opts[:indent] if opts.key?(:indent)
to_json(obj, options_map).chomp
end
diff --git a/lib/chef/key.rb b/lib/chef/key.rb
index 1020d60ac6..80315cc551 100644
--- a/lib/chef/key.rb
+++ b/lib/chef/key.rb
@@ -203,9 +203,9 @@ class Chef
class << self
def from_hash(key_hash)
- if key_hash.has_key?("user")
+ if key_hash.key?("user")
key = Chef::Key.new(key_hash["user"], "user")
- elsif key_hash.has_key?("client")
+ elsif key_hash.key?("client")
key = Chef::Key.new(key_hash["client"], "client")
else
raise Chef::Exceptions::MissingKeyAttribute, "The hash passed to from_hash does not contain the key 'user' or 'client'. Please pass a hash that defines one of those keys."
diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb
index dfaecb34cd..ebb6841055 100644
--- a/lib/chef/knife.rb
+++ b/lib/chef/knife.rb
@@ -340,7 +340,7 @@ class Chef
# overwrite.
def config_file_settings
cli_keys.each_with_object({}) do |key, memo|
- memo[key] = Chef::Config[:knife][key] if Chef::Config[:knife].has_key?(key)
+ memo[key] = Chef::Config[:knife][key] if Chef::Config[:knife].key?(key)
end
end
@@ -380,11 +380,11 @@ class Chef
Chef::Config[:chef_server_url] = config[:chef_server_url] if config[:chef_server_url]
Chef::Config[:environment] = config[:environment] if config[:environment]
- Chef::Config.local_mode = config[:local_mode] if config.has_key?(:local_mode)
+ Chef::Config.local_mode = config[:local_mode] if config.key?(:local_mode)
- Chef::Config.listen = config[:listen] if config.has_key?(:listen)
+ Chef::Config.listen = config[:listen] if config.key?(:listen)
- if Chef::Config.local_mode && !Chef::Config.has_key?(:cookbook_path) && !Chef::Config.has_key?(:chef_repo_path)
+ if Chef::Config.local_mode && !Chef::Config.key?(:cookbook_path) && !Chef::Config.key?(:chef_repo_path)
Chef::Config.chef_repo_path = Chef::Config.find_chef_repo_path(Dir.pwd)
end
Chef::Config.chef_zero.host = config[:chef_zero_host] if config[:chef_zero_host]
diff --git a/lib/chef/knife/cookbook_show.rb b/lib/chef/knife/cookbook_show.rb
index 78951d00c7..46ed7a1aa6 100644
--- a/lib/chef/knife/cookbook_show.rb
+++ b/lib/chef/knife/cookbook_show.rb
@@ -58,13 +58,13 @@ class Chef
case @name_args.length
when 4 # We are showing a specific file
node = Hash.new
- node[:fqdn] = config[:fqdn] if config.has_key?(:fqdn)
- node[:platform] = config[:platform] if config.has_key?(:platform)
- node[:platform_version] = config[:platform_version] if config.has_key?(:platform_version)
+ node[:fqdn] = config[:fqdn] if config.key?(:fqdn)
+ node[:platform] = config[:platform] if config.key?(:platform)
+ node[:platform_version] = config[:platform_version] if config.key?(:platform_version)
class << node
def attribute?(name) # rubocop:disable Lint/NestedMethodDefinition
- has_key?(name)
+ key?(name)
end
end
diff --git a/lib/chef/knife/cookbook_upload.rb b/lib/chef/knife/cookbook_upload.rb
index b19c352b79..67a5580860 100644
--- a/lib/chef/knife/cookbook_upload.rb
+++ b/lib/chef/knife/cookbook_upload.rb
@@ -169,7 +169,7 @@ class Chef
upload_set = {}
@name_args.each do |cookbook_name|
begin
- if ! upload_set.has_key?(cookbook_name)
+ if ! upload_set.key?(cookbook_name)
upload_set[cookbook_name] = cookbook_repo[cookbook_name]
if config[:depends]
upload_set[cookbook_name].metadata.dependencies.each_key { |dep| @name_args << dep }
diff --git a/lib/chef/knife/core/bootstrap_context.rb b/lib/chef/knife/core/bootstrap_context.rb
index bb20780590..4e21564c52 100644
--- a/lib/chef/knife/core/bootstrap_context.rb
+++ b/lib/chef/knife/core/bootstrap_context.rb
@@ -45,7 +45,7 @@ class Chef
end
def validation_key
- if @chef_config.has_key?(:validation_key) &&
+ if @chef_config.key?(:validation_key) &&
File.exist?(File.expand_path(@chef_config[:validation_key]))
IO.read(File.expand_path(@chef_config[:validation_key]))
else
@@ -105,14 +105,14 @@ class Chef
# We configure :verify_api_cert only when it's overridden on the CLI
# or when specified in the knife config.
- if !@config[:node_verify_api_cert].nil? || knife_config.has_key?(:verify_api_cert)
+ if !@config[:node_verify_api_cert].nil? || knife_config.key?(:verify_api_cert)
value = @config[:node_verify_api_cert].nil? ? knife_config[:verify_api_cert] : @config[:node_verify_api_cert]
client_rb << %Q{verify_api_cert #{value}\n}
end
# We configure :ssl_verify_mode only when it's overridden on the CLI
# or when specified in the knife config.
- if @config[:node_ssl_verify_mode] || knife_config.has_key?(:ssl_verify_mode)
+ if @config[:node_ssl_verify_mode] || knife_config.key?(:ssl_verify_mode)
value = case @config[:node_ssl_verify_mode]
when "peer"
:verify_peer
diff --git a/lib/chef/knife/data_bag_secret_options.rb b/lib/chef/knife/data_bag_secret_options.rb
index 62a3e71ec5..6e800add89 100644
--- a/lib/chef/knife/data_bag_secret_options.rb
+++ b/lib/chef/knife/data_bag_secret_options.rb
@@ -118,7 +118,7 @@ class Chef
end
def has_cl_secret?
- Chef::Config[:knife].has_key?(:cl_secret)
+ Chef::Config[:knife].key?(:cl_secret)
end
def self.set_cl_secret(s)
@@ -126,7 +126,7 @@ class Chef
end
def has_cl_secret_file?
- Chef::Config[:knife].has_key?(:cl_secret_file)
+ Chef::Config[:knife].key?(:cl_secret_file)
end
def self.set_cl_secret_file(sf)
diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb
index 74e457ac8e..cd29b62b75 100644
--- a/lib/chef/knife/ssh.rb
+++ b/lib/chef/knife/ssh.rb
@@ -561,7 +561,7 @@ class Chef
# use ssh_password_ng to determine if we're coming from knife ssh or from the other utilities. The other utilties can
# also be patched to use ssh_password_ng easily as long they follow the convention that the default is false.
def configure_password
- if config.has_key?(:ssh_password_ng) && config[:ssh_password_ng].nil?
+ if config.key?(:ssh_password_ng) && config[:ssh_password_ng].nil?
# If the parameter is called on the command line with no value
# it will set :ssh_password_ng = nil
# This is where we want to trigger a prompt for password
@@ -571,7 +571,7 @@ class Chef
# using an old config[:ssh_password]. this is backwards compatibility. all knife cloud plugins should
# be updated to use ssh_password_ng with a default of false and ssh_password should be retired, (but
# we'll still need to use the ssh_password out of knife.rb if we find that).
- ssh_password = config.has_key?(:ssh_password_ng) ? config[:ssh_password_ng] : config[:ssh_password]
+ ssh_password = config.key?(:ssh_password_ng) ? config[:ssh_password_ng] : config[:ssh_password]
# Otherwise, the password has either been specified on the command line,
# in knife.rb, or key based auth will be attempted
config[:ssh_password] = get_stripped_unfrozen_value(ssh_password ||
diff --git a/lib/chef/mixin/deep_merge.rb b/lib/chef/mixin/deep_merge.rb
index 9ec2b397d4..1ecd00eb2d 100644
--- a/lib/chef/mixin/deep_merge.rb
+++ b/lib/chef/mixin/deep_merge.rb
@@ -106,7 +106,7 @@ class Chef
if merge_onto.kind_of?(Hash) && merge_with.kind_of?(Hash)
merge_with.each do |key, merge_with_value|
value =
- if merge_onto.has_key?(key)
+ if merge_onto.key?(key)
hash_only_merge(merge_onto[key], merge_with_value)
else
merge_with_value
diff --git a/lib/chef/mixin/params_validate.rb b/lib/chef/mixin/params_validate.rb
index 4ed4b3ab3b..f77adecd60 100644
--- a/lib/chef/mixin/params_validate.rb
+++ b/lib/chef/mixin/params_validate.rb
@@ -106,7 +106,7 @@ class Chef
when false
true
when Hash
- @validation_message[key] = validation.delete(:validation_message) if validation.has_key?(:validation_message)
+ @validation_message[key] = validation.delete(:validation_message) if validation.key?(:validation_message)
validation.each do |check, carg|
check_method = "_pv_#{check}"
if respond_to?(check_method, true)
@@ -132,14 +132,14 @@ class Chef
private
def _validation_message(key, default)
- @validation_message.has_key?(key) ? @validation_message[key] : default
+ @validation_message.key?(key) ? @validation_message[key] : default
end
# Return the value of a parameter, or nil if it doesn't exist.
def _pv_opts_lookup(opts, key)
- if opts.has_key?(key.to_s)
+ if opts.key?(key.to_s)
opts[key.to_s]
- elsif opts.has_key?(key.to_sym)
+ elsif opts.key?(key.to_sym)
opts[key.to_sym]
else
nil
@@ -149,8 +149,8 @@ class Chef
# Raise an exception if the parameter is not found.
def _pv_required(opts, key, is_required = true, explicitly_allows_nil = false)
if is_required
- return true if opts.has_key?(key.to_s) && (explicitly_allows_nil || !opts[key.to_s].nil?)
- return true if opts.has_key?(key.to_sym) && (explicitly_allows_nil || !opts[key.to_sym].nil?)
+ return true if opts.key?(key.to_s) && (explicitly_allows_nil || !opts[key.to_s].nil?)
+ return true if opts.key?(key.to_sym) && (explicitly_allows_nil || !opts[key.to_sym].nil?)
raise Exceptions::ValidationFailed, _validation_message(key, "Required argument #{key.inspect} is missing!")
end
true
@@ -404,7 +404,7 @@ class Chef
# ```
#
def _pv_is(opts, key, to_be)
- return true if !opts.has_key?(key.to_s) && !opts.has_key?(key.to_sym)
+ return true if !opts.key?(key.to_s) && !opts.key?(key.to_sym)
value = _pv_opts_lookup(opts, key)
to_be = [ to_be ].flatten(1)
errors = []
@@ -454,10 +454,10 @@ class Chef
# ```
#
def _pv_coerce(opts, key, coercer)
- if opts.has_key?(key.to_s)
+ if opts.key?(key.to_s)
raise Exceptions::CannotValidateStaticallyError, "coerce must be evaluated for each resource." if self == Chef::Mixin::ParamsValidate
opts[key.to_s] = instance_exec(opts[key], &coercer)
- elsif opts.has_key?(key.to_sym)
+ elsif opts.key?(key.to_sym)
raise Exceptions::CannotValidateStaticallyError, "coerce must be evaluated for each resource." if self == Chef::Mixin::ParamsValidate
opts[key.to_sym] = instance_exec(opts[key], &coercer)
end
diff --git a/lib/chef/mixin/properties.rb b/lib/chef/mixin/properties.rb
index fb765fbb3a..f72a22db2d 100644
--- a/lib/chef/mixin/properties.rb
+++ b/lib/chef/mixin/properties.rb
@@ -102,14 +102,14 @@ class Chef
options = options.inject({}) { |memo, (key, value)| memo[key.to_sym] = value; memo }
- options[:instance_variable_name] = :"@#{name}" if !options.has_key?(:instance_variable_name)
+ options[:instance_variable_name] = :"@#{name}" if !options.key?(:instance_variable_name)
options[:name] = name
options[:declared_in] = self
if type == NOT_PASSED
# If a type is not passed, the property derives from the
# superclass property (if any)
- if properties.has_key?(name)
+ if properties.key?(name)
property = properties[name].derive(**options)
else
property = property_type(**options)
diff --git a/lib/chef/node.rb b/lib/chef/node.rb
index b9a005e419..c31fc99279 100644
--- a/lib/chef/node.rb
+++ b/lib/chef/node.rb
@@ -524,8 +524,8 @@ class Chef
node = new
node.name(o["name"])
- node.policy_name = o["policy_name"] if o.has_key?("policy_name")
- node.policy_group = o["policy_group"] if o.has_key?("policy_group")
+ node.policy_name = o["policy_name"] if o.key?("policy_name")
+ node.policy_group = o["policy_group"] if o.key?("policy_group")
unless node.policy_group.nil?
node.chef_environment(o["policy_group"])
@@ -533,17 +533,17 @@ class Chef
node.chef_environment(o["chef_environment"])
end
- if o.has_key?("attributes")
+ if o.key?("attributes")
node.normal_attrs = o["attributes"]
end
- node.automatic_attrs = Mash.new(o["automatic"]) if o.has_key?("automatic")
- node.normal_attrs = Mash.new(o["normal"]) if o.has_key?("normal")
- node.default_attrs = Mash.new(o["default"]) if o.has_key?("default")
- node.override_attrs = Mash.new(o["override"]) if o.has_key?("override")
+ node.automatic_attrs = Mash.new(o["automatic"]) if o.key?("automatic")
+ node.normal_attrs = Mash.new(o["normal"]) if o.key?("normal")
+ node.default_attrs = Mash.new(o["default"]) if o.key?("default")
+ node.override_attrs = Mash.new(o["override"]) if o.key?("override")
- if o.has_key?("run_list")
+ if o.key?("run_list")
node.run_list.reset!(o["run_list"])
- elsif o.has_key?("recipes")
+ elsif o.key?("recipes")
o["recipes"].each { |r| node.recipes << r }
end
diff --git a/lib/chef/node/attribute.rb b/lib/chef/node/attribute.rb
index cd6061e24f..8cb45d2584 100644
--- a/lib/chef/node/attribute.rb
+++ b/lib/chef/node/attribute.rb
@@ -427,7 +427,7 @@ class Chef
def has_key?(key)
COMPONENTS.any? do |component_ivar|
- instance_variable_get(component_ivar).has_key?(key)
+ instance_variable_get(component_ivar).key?(key)
end
end
# method-style access to attributes (has to come after the prepended ImmutablizeHash)
@@ -497,7 +497,7 @@ class Chef
if !val.respond_to?(:has_key?)
# Have an Array-like thing
val[path_arg]
- elsif val.has_key?(path_arg)
+ elsif val.key?(path_arg)
# Hash-like thing (must check has_key? first to protect against Autovivification)
val[path_arg]
else
@@ -578,7 +578,7 @@ class Chef
if merge_onto.kind_of?(Hash) && merge_with.kind_of?(Hash)
merge_with.each do |key, merge_with_value|
value =
- if merge_onto.has_key?(key)
+ if merge_onto.key?(key)
deep_merge!(safe_dup(merge_onto[key]), merge_with_value)
else
merge_with_value
@@ -614,7 +614,7 @@ class Chef
if merge_onto.kind_of?(Hash) && merge_with.kind_of?(Hash)
merge_with.each do |key, merge_with_value|
value =
- if merge_onto.has_key?(key)
+ if merge_onto.key?(key)
hash_only_merge!(safe_dup(merge_onto[key]), merge_with_value)
else
merge_with_value
diff --git a/lib/chef/node/mixin/deep_merge_cache.rb b/lib/chef/node/mixin/deep_merge_cache.rb
index b18d6b10cb..54e48b10cf 100644
--- a/lib/chef/node/mixin/deep_merge_cache.rb
+++ b/lib/chef/node/mixin/deep_merge_cache.rb
@@ -46,7 +46,7 @@ class Chef
alias :reset :reset_cache
def [](key)
- if deep_merge_cache.has_key?(key.to_s)
+ if deep_merge_cache.key?(key.to_s)
# return the cache of the deep merged values by top-level key
deep_merge_cache[key.to_s]
else
diff --git a/lib/chef/node_map.rb b/lib/chef/node_map.rb
index 6496d91de7..62efbc12d6 100644
--- a/lib/chef/node_map.rb
+++ b/lib/chef/node_map.rb
@@ -138,7 +138,7 @@ EOH
# @return [Object] Class
#
def get(node, key, canonical: nil)
- return nil unless map.has_key?(key)
+ return nil unless map.key?(key)
map[key].map do |matcher|
return matcher[:klass] if node_matches?(node, matcher) && canonical_matches?(canonical, matcher)
end
@@ -158,7 +158,7 @@ EOH
# @return [Object] Class
#
def list(node, key, canonical: nil)
- return [] unless map.has_key?(key)
+ return [] unless map.key?(key)
map[key].select do |matcher|
node_matches?(node, matcher) && canonical_matches?(canonical, matcher)
end.map { |matcher| matcher[:klass] }
diff --git a/lib/chef/property.rb b/lib/chef/property.rb
index 3ad28fad10..0d7b0f06cf 100644
--- a/lib/chef/property.rb
+++ b/lib/chef/property.rb
@@ -121,9 +121,9 @@ class Chef
options[:instance_variable_name] = options[:instance_variable_name].to_sym if options[:instance_variable_name]
# Replace name_attribute with name_property
- if options.has_key?(:name_attribute)
+ if options.key?(:name_attribute)
# If we have both name_attribute and name_property and they differ, raise an error
- if options.has_key?(:name_property)
+ if options.key?(:name_property)
raise ArgumentError, "name_attribute and name_property are functionally identical and both cannot be specified on a property at once. Use just one on property #{self}"
end
# replace name_property with name_attribute in place
@@ -131,7 +131,7 @@ class Chef
@options = options
end
- if options.has_key?(:default) && options.has_key?(:name_property)
+ if options.key?(:default) && options.key?(:name_property)
raise ArgumentError, "A property cannot be both a name_property/name_attribute and have a default value. Use one or the other on property #{self}"
end
@@ -208,7 +208,7 @@ class Chef
# @return [Symbol]
#
def instance_variable_name
- if options.has_key?(:instance_variable_name)
+ if options.key?(:instance_variable_name)
options[:instance_variable_name]
elsif name
:"@#{name}"
@@ -224,7 +224,7 @@ class Chef
# `nil`
#
def default
- return options[:default] if options.has_key?(:default)
+ return options[:default] if options.key?(:default)
return Chef::DelayedEvaluator.new { name } if name_property?
nil
end
@@ -246,7 +246,7 @@ class Chef
# @return [Boolean]
#
def desired_state?
- return true if !options.has_key?(:desired_state)
+ return true if !options.key?(:desired_state)
options[:desired_state]
end
@@ -265,7 +265,7 @@ class Chef
# @return [Boolean]
#
def has_default?
- options.has_key?(:default) || name_property?
+ options.key?(:default) || name_property?
end
#
@@ -403,7 +403,7 @@ class Chef
def set(resource, value)
value = set_value(resource, input_to_stored_value(resource, value))
- if options.has_key?(:deprecated)
+ if options.key?(:deprecated)
Chef.deprecated(:property, options[:deprecated])
end
@@ -463,7 +463,7 @@ class Chef
# this property.
#
def coerce(resource, value)
- if options.has_key?(:coerce)
+ if options.key?(:coerce)
# nil is never coerced
unless value.nil?
value = exec_in_resource(resource, options[:coerce], value)
@@ -511,9 +511,9 @@ class Chef
# if you specify one of them in modified_options it overrides anything in
# the original options.
options = self.options
- if modified_options.has_key?(:name_property) ||
- modified_options.has_key?(:name_attribute) ||
- modified_options.has_key?(:default)
+ if modified_options.key?(:name_property) ||
+ modified_options.key?(:name_attribute) ||
+ modified_options.key?(:default)
options = options.reject { |k, v| k == :name_attribute || k == :name_property || k == :default }
end
self.class.new(options.merge(modified_options))
@@ -599,8 +599,8 @@ class Chef
#
# @api private
def explicitly_accepts_nil?(resource)
- options.has_key?(:coerce) ||
- (options.has_key?(:is) && Chef::Mixin::ParamsValidate.send(:_pv_is, { name => nil }, name, options[:is]))
+ options.key?(:coerce) ||
+ (options.key?(:is) && Chef::Mixin::ParamsValidate.send(:_pv_is, { name => nil }, name, options[:is]))
rescue Chef::Exceptions::ValidationFailed, Chef::Exceptions::CannotValidateStaticallyError
false
end
diff --git a/lib/chef/provider/registry_key.rb b/lib/chef/provider/registry_key.rb
index a4a0465e11..7c7b190b95 100644
--- a/lib/chef/provider/registry_key.rb
+++ b/lib/chef/provider/registry_key.rb
@@ -68,7 +68,7 @@ class Chef
def key_missing?(values, name)
values.each do |v|
- return true unless v.has_key?(name)
+ return true unless v.key?(name)
end
false
end
@@ -120,7 +120,7 @@ class Chef
end
end
new_resource.unscrubbed_values.each do |value|
- if @name_hash.has_key?(value[:name].downcase)
+ if @name_hash.key?(value[:name].downcase)
current_value = @name_hash[value[:name].downcase]
if [:dword, :dword_big_endian, :qword].include? value[:type]
value[:data] = value[:data].to_i
@@ -151,7 +151,7 @@ class Chef
end
end
new_resource.unscrubbed_values.each do |value|
- unless @name_hash.has_key?(value[:name].downcase)
+ unless @name_hash.key?(value[:name].downcase)
converge_by_value = value
converge_by_value[:data] = "*sensitive value suppressed*" if new_resource.sensitive
@@ -165,7 +165,7 @@ class Chef
def action_delete
if registry.key_exists?(new_resource.key)
new_resource.unscrubbed_values.each do |value|
- if @name_hash.has_key?(value[:name].downcase)
+ if @name_hash.key?(value[:name].downcase)
converge_by_value = value
converge_by_value[:data] = "*sensitive value suppressed*" if new_resource.sensitive
diff --git a/lib/chef/provider/remote_file/cache_control_data.rb b/lib/chef/provider/remote_file/cache_control_data.rb
index 32c1542d57..5c59d112db 100644
--- a/lib/chef/provider/remote_file/cache_control_data.rb
+++ b/lib/chef/provider/remote_file/cache_control_data.rb
@@ -146,11 +146,11 @@ class Chef
def load_json_data
path = sanitized_cache_file_path(sanitized_cache_file_basename)
- if Chef::FileCache.has_key?(path)
+ if Chef::FileCache.key?(path)
Chef::FileCache.load(path)
else
old_path = sanitized_cache_file_path(sanitized_cache_file_basename_md5)
- if Chef::FileCache.has_key?(old_path)
+ if Chef::FileCache.key?(old_path)
# We found an old cache control data file. We started using sha256 instead of md5
# to name these. Upgrade the file to the new name.
Chef::Log.trace("Found old cache control data file at #{old_path}. Moving to #{path}.")
diff --git a/lib/chef/provider/service/windows.rb b/lib/chef/provider/service/windows.rb
index 2482ce6a5c..325367322d 100644
--- a/lib/chef/provider/service/windows.rb
+++ b/lib/chef/provider/service/windows.rb
@@ -94,7 +94,7 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service
logger.info "#{@new_resource} configured with #{new_config.inspect}"
# LocalSystem is the default runas user, which is a special service account that should ultimately have the rights of BUILTIN\Administrators, but we wouldn't see that from get_account_right
- if new_config.has_key?(:service_start_name) && new_config[:service_start_name].casecmp("localsystem") != 0
+ if new_config.key?(:service_start_name) && new_config[:service_start_name].casecmp("localsystem") != 0
unless Chef::ReservedNames::Win32::Security.get_account_right(canonicalize_username(new_config[:service_start_name])).include?(SERVICE_RIGHT)
grant_service_logon(new_config[:service_start_name])
end
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index a30504bc91..a90a018d2f 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -691,7 +691,7 @@ class Chef
safe_ivars = instance_variables.map { |ivar| ivar.to_sym } - FORBIDDEN_IVARS
safe_ivars.each do |iv|
key = iv.to_s.sub(/^@/, "").to_sym
- next if result.has_key?(key)
+ next if result.key?(key)
result[key] = instance_variable_get(iv)
end
result
diff --git a/lib/chef/resource/registry_key.rb b/lib/chef/resource/registry_key.rb
index 84abb98699..36a6db1100 100644
--- a/lib/chef/resource/registry_key.rb
+++ b/lib/chef/resource/registry_key.rb
@@ -82,7 +82,7 @@ class Chef
end
@values.each do |v|
- raise ArgumentError, "Missing name key in RegistryKey values hash" unless v.has_key?(:name)
+ raise ArgumentError, "Missing name key in RegistryKey values hash" unless v.key?(:name)
v.each_key do |key|
raise ArgumentError, "Bad key #{key} in RegistryKey values hash" unless [:name, :type, :data].include?(key)
end
diff --git a/lib/chef/role.rb b/lib/chef/role.rb
index f0c4cdd542..73d5cf5743 100644
--- a/lib/chef/role.rb
+++ b/lib/chef/role.rb
@@ -86,7 +86,7 @@ class Chef
end
def active_run_list_for(environment)
- @env_run_lists.has_key?(environment) ? environment : "_default"
+ @env_run_lists.key?(environment) ? environment : "_default"
end
# Per environment run lists
@@ -175,7 +175,7 @@ class Chef
# _default run_list is in 'run_list' for newer clients, and
# 'recipes' for older clients.
- env_run_list_hash = { "_default" => (o.has_key?("run_list") ? o["run_list"] : o["recipes"]) }
+ env_run_list_hash = { "_default" => (o.key?("run_list") ? o["run_list"] : o["recipes"]) }
# Clients before 0.10 do not include env_run_lists, so only
# merge if it's there.
diff --git a/lib/chef/run_context.rb b/lib/chef/run_context.rb
index a11cc676eb..657caf0f81 100644
--- a/lib/chef/run_context.rb
+++ b/lib/chef/run_context.rb
@@ -433,7 +433,7 @@ ERROR_MESSAGE
# @return [Boolean] `true` if the recipe has been loaded, `false` otherwise.
#
def loaded_fully_qualified_recipe?(cookbook, recipe)
- loaded_recipes_hash.has_key?("#{cookbook}::#{recipe}")
+ loaded_recipes_hash.key?("#{cookbook}::#{recipe}")
end
#
@@ -468,7 +468,7 @@ ERROR_MESSAGE
# @return [Boolean] `true` if the recipe has been loaded, `false` otherwise.
#
def loaded_fully_qualified_attribute?(cookbook, attribute_file)
- loaded_attributes_hash.has_key?("#{cookbook}::#{attribute_file}")
+ loaded_attributes_hash.key?("#{cookbook}::#{attribute_file}")
end
#
diff --git a/lib/chef/run_list/run_list_expansion.rb b/lib/chef/run_list/run_list_expansion.rb
index 085dd9f6be..161574e884 100644
--- a/lib/chef/run_list/run_list_expansion.rb
+++ b/lib/chef/run_list/run_list_expansion.rb
@@ -112,7 +112,7 @@ class Chef
end
def applied_role?(role_name)
- @applied_roles.has_key?(role_name)
+ @applied_roles.key?(role_name)
end
# Returns an array of role names that were expanded; this
diff --git a/lib/chef/run_list/run_list_item.rb b/lib/chef/run_list/run_list_item.rb
index 1c75907dd8..74b4741eba 100644
--- a/lib/chef/run_list/run_list_item.rb
+++ b/lib/chef/run_list/run_list_item.rb
@@ -32,7 +32,7 @@ class Chef
assert_hash_is_valid_run_list_item!(item)
@type = (item["type"] || item[:type]).to_sym
@name = item["name"] || item[:name]
- if item.has_key?("version") || item.has_key?(:version)
+ if item.key?("version") || item.key?(:version)
@version = item["version"] || item[:version]
end
when String
diff --git a/lib/chef/run_list/versioned_recipe_list.rb b/lib/chef/run_list/versioned_recipe_list.rb
index d9b3c17db3..e2933d45cd 100644
--- a/lib/chef/run_list/versioned_recipe_list.rb
+++ b/lib/chef/run_list/versioned_recipe_list.rb
@@ -30,7 +30,7 @@ class Chef
end
def add_recipe(name, version = nil)
- if version && @versions.has_key?(name)
+ if version && @versions.key?(name)
unless Chef::Version.new(@versions[name]) == Chef::Version.new(version)
raise Chef::Exceptions::CookbookVersionConflict, "Run list requires #{name} at versions #{@versions[name]} and #{version}"
end
diff --git a/lib/chef/util/powershell/cmdlet.rb b/lib/chef/util/powershell/cmdlet.rb
index edd3e92da1..6b9ba7c208 100644
--- a/lib/chef/util/powershell/cmdlet.rb
+++ b/lib/chef/util/powershell/cmdlet.rb
@@ -58,7 +58,7 @@ class Chef
json_depth = 5
- if @json_format && @output_format_options.has_key?(:depth)
+ if @json_format && @output_format_options.key?(:depth)
json_depth = @output_format_options[:depth]
end
diff --git a/lib/chef/win32/security.rb b/lib/chef/win32/security.rb
index 2f903d6c93..58f47e885b 100644
--- a/lib/chef/win32/security.rb
+++ b/lib/chef/win32/security.rb
@@ -537,14 +537,14 @@ class Chef
# Determine the security_information flags
security_information = 0
- security_information |= OWNER_SECURITY_INFORMATION if args.has_key?(:owner)
- security_information |= GROUP_SECURITY_INFORMATION if args.has_key?(:group)
- security_information |= DACL_SECURITY_INFORMATION if args.has_key?(:dacl)
- security_information |= SACL_SECURITY_INFORMATION if args.has_key?(:sacl)
- if args.has_key?(:dacl_inherits)
+ security_information |= OWNER_SECURITY_INFORMATION if args.key?(:owner)
+ security_information |= GROUP_SECURITY_INFORMATION if args.key?(:group)
+ security_information |= DACL_SECURITY_INFORMATION if args.key?(:dacl)
+ security_information |= SACL_SECURITY_INFORMATION if args.key?(:sacl)
+ if args.key?(:dacl_inherits)
security_information |= (args[:dacl_inherits] ? UNPROTECTED_DACL_SECURITY_INFORMATION : PROTECTED_DACL_SECURITY_INFORMATION)
end
- if args.has_key?(:sacl_inherits)
+ if args.key?(:sacl_inherits)
security_information |= (args[:sacl_inherits] ? UNPROTECTED_SACL_SECURITY_INFORMATION : PROTECTED_SACL_SECURITY_INFORMATION)
end