summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/api_client_v1.rb2
-rw-r--r--lib/chef/application/client.rb14
-rw-r--r--lib/chef/application/exit_code.rb4
-rw-r--r--lib/chef/application/knife.rb3
-rw-r--r--lib/chef/application/solo.rb2
-rw-r--r--lib/chef/application/windows_service.rb4
-rw-r--r--lib/chef/application/windows_service_manager.rb8
-rw-r--r--lib/chef/audit/audit_reporter.rb4
-rw-r--r--lib/chef/chef_fs/chef_fs_data_store.rb10
-rw-r--r--lib/chef/chef_fs/config.rb2
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/acl_entry.rb2
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/acls_dir.rb2
-rw-r--r--lib/chef/chef_fs/file_system/repository/acls_dir.rb2
-rw-r--r--lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb4
-rw-r--r--lib/chef/cookbook/file_system_file_vendor.rb2
-rw-r--r--lib/chef/cookbook/manifest_v0.rb2
-rw-r--r--lib/chef/cookbook/metadata.rb40
-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_site_streaming_uploader.rb2
-rw-r--r--lib/chef/cookbook_version.rb4
-rw-r--r--lib/chef/data_bag.rb2
-rw-r--r--lib/chef/data_bag_item.rb2
-rw-r--r--lib/chef/deprecated.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.rb4
-rw-r--r--lib/chef/encrypted_data_bag_item/check_encrypted.rb2
-rw-r--r--lib/chef/environment.rb2
-rw-r--r--lib/chef/event_loggers/windows_eventlog.rb2
-rw-r--r--lib/chef/file_cache.rb6
-rw-r--r--lib/chef/formatters/error_inspectors/api_error_formatting.rb2
-rw-r--r--lib/chef/http/authenticator.rb2
-rw-r--r--lib/chef/http/cookie_manager.rb2
-rw-r--r--lib/chef/http/http_request.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/http/socketless_chef_zero_client.rb2
-rw-r--r--lib/chef/json_compat.rb2
-rw-r--r--lib/chef/key.rb4
-rw-r--r--lib/chef/knife.rb10
-rw-r--r--lib/chef/knife/config_get.rb126
-rw-r--r--lib/chef/knife/cookbook_show.rb8
-rw-r--r--lib/chef/knife/cookbook_upload.rb4
-rw-r--r--lib/chef/knife/core/bootstrap_context.rb6
-rw-r--r--lib/chef/knife/core/hashed_command_loader.rb2
-rw-r--r--lib/chef/knife/data_bag_secret_options.rb4
-rw-r--r--lib/chef/knife/ssh.rb4
-rw-r--r--lib/chef/log/winevt.rb2
-rw-r--r--lib/chef/mixin/deep_merge.rb2
-rw-r--r--lib/chef/mixin/deprecation.rb2
-rw-r--r--lib/chef/mixin/params_validate.rb18
-rw-r--r--lib/chef/mixin/properties.rb4
-rw-r--r--lib/chef/mixin/xml_escape.rb6
-rw-r--r--lib/chef/node.rb18
-rw-r--r--lib/chef/node/attribute.rb12
-rw-r--r--lib/chef/node/attribute_collections.rb4
-rw-r--r--lib/chef/node/mixin/deep_merge_cache.rb2
-rw-r--r--lib/chef/node/mixin/immutablize_array.rb4
-rw-r--r--lib/chef/node/mixin/immutablize_hash.rb4
-rw-r--r--lib/chef/node_map.rb4
-rw-r--r--lib/chef/property.rb28
-rw-r--r--lib/chef/provider/apt_update.rb4
-rw-r--r--lib/chef/provider/cron.rb6
-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/openbsd.rb4
-rw-r--r--lib/chef/provider/service/windows.rb24
-rw-r--r--lib/chef/provider/user/solaris.rb2
-rw-r--r--lib/chef/provider/windows_task.rb8
-rw-r--r--lib/chef/resource.rb6
-rw-r--r--lib/chef/resource/registry_key.rb2
-rw-r--r--lib/chef/resource/windows_service.rb2
-rw-r--r--lib/chef/resource/windows_task.rb6
-rw-r--r--lib/chef/resource_reporter.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/user_v1.rb2
-rw-r--r--lib/chef/util/powershell/cmdlet.rb2
-rw-r--r--lib/chef/util/windows/net_user.rb2
-rw-r--r--lib/chef/version.rb2
-rw-r--r--lib/chef/version_constraint.rb6
-rw-r--r--lib/chef/win32/security.rb12
-rw-r--r--lib/chef/win32/version.rb2
88 files changed, 346 insertions, 217 deletions
diff --git a/lib/chef/api_client_v1.rb b/lib/chef/api_client_v1.rb
index 645016c5b9..fcd4d91c13 100644
--- a/lib/chef/api_client_v1.rb
+++ b/lib/chef/api_client_v1.rb
@@ -44,7 +44,7 @@ class Chef
include Chef::Mixin::ParamsValidate
include Chef::Mixin::ApiVersionRequestHandling
- SUPPORTED_API_VERSIONS = [0, 1]
+ SUPPORTED_API_VERSIONS = [0, 1].freeze
# Create a new Chef::ApiClientV1 object.
def initialize
diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb
index 6e574e682f..7bea2bd845 100644
--- a/lib/chef/application/client.rb
+++ b/lib/chef/application/client.rb
@@ -35,7 +35,7 @@ class Chef::Application::Client < Chef::Application
include ChefConfig::Mixin::DotD
# Mimic self_pipe sleep from Unicorn to capture signals safely
- SELF_PIPE = []
+ SELF_PIPE = [] # rubocop:disable Style/MutableConstant
option :config_file,
short: "-c CONFIG",
@@ -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/exit_code.rb b/lib/chef/application/exit_code.rb
index 917aa16e62..c87592f06b 100644
--- a/lib/chef/application/exit_code.rb
+++ b/lib/chef/application/exit_code.rb
@@ -36,11 +36,11 @@ class Chef
REBOOT_FAILED: 41,
AUDIT_MODE_FAILURE: 42,
CLIENT_UPGRADED: 213,
- }
+ }.freeze
DEPRECATED_RFC_062_EXIT_CODES = {
DEPRECATED_FAILURE: -1,
- }
+ }.freeze
class << self
diff --git a/lib/chef/application/knife.rb b/lib/chef/application/knife.rb
index 2c8d886b27..76dd5707fe 100644
--- a/lib/chef/application/knife.rb
+++ b/lib/chef/application/knife.rb
@@ -23,7 +23,7 @@ require "chef/monkey_patches/net_http.rb"
class Chef::Application::Knife < Chef::Application
- NO_COMMAND_GIVEN = "You need to pass a sub-command (e.g., knife SUB-COMMAND)\n"
+ NO_COMMAND_GIVEN = "You need to pass a sub-command (e.g., knife SUB-COMMAND)\n".freeze
banner "Usage: knife sub-command (options)"
@@ -154,6 +154,7 @@ class Chef::Application::Knife < Chef::Application
# Run knife
def run
+ ChefConfig::PathHelper.per_tool_home_environment = "KNIFE_HOME"
Mixlib::Log::Formatter.show_time = false
validate_and_parse_options
quiet_traps
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..3c73a4925d 100644
--- a/lib/chef/application/windows_service.rb
+++ b/lib/chef/application/windows_service.rb
@@ -59,7 +59,7 @@ class Chef
description: "Set the number of seconds to wait between chef-client runs",
proc: lambda { |s| s.to_i }
- DEFAULT_LOG_LOCATION ||= "#{ENV['SYSTEMDRIVE']}/chef/client.log"
+ DEFAULT_LOG_LOCATION ||= "#{ENV['SYSTEMDRIVE']}/chef/client.log".freeze
def service_init
@service_action_mutex = Mutex.new
@@ -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..2ba1861a5b 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
@@ -163,9 +163,9 @@ class Chef
private
# Just some state constants
- STOPPED = "stopped"
- RUNNING = "running"
- PAUSED = "paused"
+ STOPPED = "stopped".freeze
+ RUNNING = "running".freeze
+ PAUSED = "paused".freeze
def service_exists?
::Win32::Service.exists?(@service_name)
diff --git a/lib/chef/audit/audit_reporter.rb b/lib/chef/audit/audit_reporter.rb
index bb5537b97b..7e3abf2608 100644
--- a/lib/chef/audit/audit_reporter.rb
+++ b/lib/chef/audit/audit_reporter.rb
@@ -28,7 +28,7 @@ class Chef
attr_reader :rest_client, :audit_data, :ordered_control_groups, :run_status
private :rest_client, :audit_data, :ordered_control_groups, :run_status
- PROTOCOL_VERSION = "0.1.1"
+ PROTOCOL_VERSION = "0.1.1".freeze
def initialize(rest_client)
@rest_client = rest_client
@@ -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/config.rb b/lib/chef/chef_fs/config.rb
index 2a41fb5870..83efdad063 100644
--- a/lib/chef/chef_fs/config.rb
+++ b/lib/chef/chef_fs/config.rb
@@ -44,7 +44,7 @@ class Chef
"users" => "user",
"policies" => "policy",
"policy_groups" => "policy_group",
- }
+ }.freeze
INFLECTIONS.each { |k, v| k.freeze; v.freeze }
INFLECTIONS.freeze
diff --git a/lib/chef/chef_fs/file_system/chef_server/acl_entry.rb b/lib/chef/chef_fs/file_system/chef_server/acl_entry.rb
index f4655412fa..3951f1a7e6 100644
--- a/lib/chef/chef_fs/file_system/chef_server/acl_entry.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/acl_entry.rb
@@ -24,7 +24,7 @@ class Chef
module FileSystem
module ChefServer
class AclEntry < RestListEntry
- PERMISSIONS = %w{create read update delete grant}
+ PERMISSIONS = %w{create read update delete grant}.freeze
def api_path
"#{super}/_acl"
diff --git a/lib/chef/chef_fs/file_system/chef_server/acls_dir.rb b/lib/chef/chef_fs/file_system/chef_server/acls_dir.rb
index b9af486203..dbc895f85e 100644
--- a/lib/chef/chef_fs/file_system/chef_server/acls_dir.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/acls_dir.rb
@@ -28,7 +28,7 @@ class Chef
module FileSystem
module ChefServer
class AclsDir < BaseFSDir
- ENTITY_TYPES = %w{clients containers cookbook_artifacts cookbooks data_bags environments groups nodes policies policy_groups roles} # we don't read sandboxes, so we don't read their acls
+ ENTITY_TYPES = %w{clients containers cookbook_artifacts cookbooks data_bags environments groups nodes policies policy_groups roles}.freeze # we don't read sandboxes, so we don't read their acls
def data_handler
@data_handler ||= Chef::ChefFS::DataHandler::AclDataHandler.new
diff --git a/lib/chef/chef_fs/file_system/repository/acls_dir.rb b/lib/chef/chef_fs/file_system/repository/acls_dir.rb
index 110befdf22..ef30bef725 100644
--- a/lib/chef/chef_fs/file_system/repository/acls_dir.rb
+++ b/lib/chef/chef_fs/file_system/repository/acls_dir.rb
@@ -28,7 +28,7 @@ class Chef
module Repository
class AclsDir < Repository::Directory
- BARE_FILES = %w{ organization.json root }
+ BARE_FILES = %w{ organization.json root }.freeze
def can_have_child?(name, is_dir)
is_dir ? Chef::ChefFS::FileSystem::ChefServer::AclsDir::ENTITY_TYPES.include?(name) : BARE_FILES.include?(name)
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..e07a73a118 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
@@ -84,7 +84,7 @@ class Chef
attr_reader :child_paths
attr_reader :versioned_cookbooks
- CHILDREN = %w{org.json invitations.json members.json}
+ CHILDREN = %w{org.json invitations.json members.json}.freeze
def children
@children ||= begin
@@ -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/manifest_v0.rb b/lib/chef/cookbook/manifest_v0.rb
index bb6d8fc6aa..5a6d7401fa 100644
--- a/lib/chef/cookbook/manifest_v0.rb
+++ b/lib/chef/cookbook/manifest_v0.rb
@@ -24,7 +24,7 @@ class Chef
minimum_api_version 0
- COOKBOOK_SEGMENTS = %w{ resources providers recipes definitions libraries attributes files templates root_files }
+ COOKBOOK_SEGMENTS = %w{ resources providers recipes definitions libraries attributes files templates root_files }.freeze
def self.from_hash(hash)
response = Mash.new(hash)
diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb
index 03e2d7a090..8716e502af 100644
--- a/lib/chef/cookbook/metadata.rb
+++ b/lib/chef/cookbook/metadata.rb
@@ -59,12 +59,12 @@ class Chef
:maintainer_email, :license, :platforms, :dependencies,
:providing, :attributes, :recipes, :version,
:source_url, :issues_url, :privacy, :chef_versions, :ohai_versions,
- :gems ]
+ :gems ].freeze
VERSION_CONSTRAINTS = { depends: DEPENDENCIES,
provides: PROVIDING,
chef_version: CHEF_VERSIONS,
- ohai_version: OHAI_VERSIONS }
+ ohai_version: OHAI_VERSIONS }.freeze
include Chef::Mixin::ParamsValidate
include Chef::Mixin::FromFile
@@ -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_site_streaming_uploader.rb b/lib/chef/cookbook_site_streaming_uploader.rb
index 8611357e1a..fdd8f690ae 100644
--- a/lib/chef/cookbook_site_streaming_uploader.rb
+++ b/lib/chef/cookbook_site_streaming_uploader.rb
@@ -31,7 +31,7 @@ class Chef
# inspired by http://stanislavvitvitskiy.blogspot.com/2008/12/multipart-post-in-ruby.html
class CookbookSiteStreamingUploader
- DefaultHeaders = { "accept" => "application/json", "x-chef-version" => ::Chef::VERSION } # rubocop:disable Naming/ConstantName
+ DefaultHeaders = { "accept" => "application/json", "x-chef-version" => ::Chef::VERSION }.freeze # rubocop:disable Naming/ConstantName
class << self
diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb
index 29d74cc252..343b037c8b 100644
--- a/lib/chef/cookbook_version.rb
+++ b/lib/chef/cookbook_version.rb
@@ -42,7 +42,7 @@ class Chef
def_delegator :@cookbook_manifest, :files_for
def_delegator :@cookbook_manifest, :each_file
- COOKBOOK_SEGMENTS = [ :resources, :providers, :recipes, :definitions, :libraries, :attributes, :files, :templates, :root_files ]
+ COOKBOOK_SEGMENTS = [ :resources, :providers, :recipes, :definitions, :libraries, :attributes, :files, :templates, :root_files ].freeze
attr_reader :all_files
@@ -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/deprecated.rb b/lib/chef/deprecated.rb
index 74c600bef9..c0291e057e 100644
--- a/lib/chef/deprecated.rb
+++ b/lib/chef/deprecated.rb
@@ -30,7 +30,7 @@ class Chef
end
class Base
- BASE_URL = "https://docs.chef.io/deprecations_"
+ BASE_URL = "https://docs.chef.io/deprecations_".freeze
attr_reader :message, :location
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.rb b/lib/chef/encrypted_data_bag_item.rb
index c7c6145f61..56135872ac 100644
--- a/lib/chef/encrypted_data_bag_item.rb
+++ b/lib/chef/encrypted_data_bag_item.rb
@@ -47,8 +47,8 @@ require "open-uri"
# such nodes in the infrastructure.
#
class Chef::EncryptedDataBagItem
- ALGORITHM = "aes-256-cbc"
- AEAD_ALGORITHM = "aes-256-gcm"
+ ALGORITHM = "aes-256-cbc".freeze
+ AEAD_ALGORITHM = "aes-256-gcm".freeze
#
# === Synopsis
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/environment.rb b/lib/chef/environment.rb
index 61777fb7b4..fa845cea6f 100644
--- a/lib/chef/environment.rb
+++ b/lib/chef/environment.rb
@@ -29,7 +29,7 @@ require "chef/server_api"
class Chef
class Environment
- DEFAULT = "default"
+ DEFAULT = "default".freeze
include Chef::Mixin::ParamsValidate
include Chef::Mixin::FromFile
diff --git a/lib/chef/event_loggers/windows_eventlog.rb b/lib/chef/event_loggers/windows_eventlog.rb
index 860d049314..950477556a 100644
--- a/lib/chef/event_loggers/windows_eventlog.rb
+++ b/lib/chef/event_loggers/windows_eventlog.rb
@@ -35,7 +35,7 @@ class Chef
LOG_CATEGORY_ID = 11001
# Since we must install the event logger, this is not really configurable
- SOURCE = "Chef"
+ SOURCE = "Chef".freeze
def self.available?
Chef::Platform.windows?
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/formatters/error_inspectors/api_error_formatting.rb b/lib/chef/formatters/error_inspectors/api_error_formatting.rb
index 954eebafdb..a4a97ebb95 100644
--- a/lib/chef/formatters/error_inspectors/api_error_formatting.rb
+++ b/lib/chef/formatters/error_inspectors/api_error_formatting.rb
@@ -23,7 +23,7 @@ class Chef
module APIErrorFormatting
- NETWORK_ERROR_CLASSES = [Errno::ECONNREFUSED, Timeout::Error, Errno::ETIMEDOUT, SocketError]
+ NETWORK_ERROR_CLASSES = [Errno::ECONNREFUSED, Timeout::Error, Errno::ETIMEDOUT, SocketError].freeze
def describe_network_errors(error_description)
error_description.section("Networking Error:", <<~E)
diff --git a/lib/chef/http/authenticator.rb b/lib/chef/http/authenticator.rb
index bfb85785c8..daa582f890 100644
--- a/lib/chef/http/authenticator.rb
+++ b/lib/chef/http/authenticator.rb
@@ -24,7 +24,7 @@ class Chef
class HTTP
class Authenticator
- DEFAULT_SERVER_API_VERSION = "1"
+ DEFAULT_SERVER_API_VERSION = "1".freeze
attr_reader :signing_key_filename
attr_reader :raw_key
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/http_request.rb b/lib/chef/http/http_request.rb
index 774419a58c..8fec34f8b3 100644
--- a/lib/chef/http/http_request.rb
+++ b/lib/chef/http/http_request.rb
@@ -40,7 +40,7 @@ class Chef
engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"
- UA_COMMON = "/#{::Chef::VERSION} (#{engine}-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}; ohai-#{Ohai::VERSION}; #{RUBY_PLATFORM}; +https://chef.io)"
+ UA_COMMON = "/#{::Chef::VERSION} (#{engine}-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}; ohai-#{Ohai::VERSION}; #{RUBY_PLATFORM}; +https://chef.io)".freeze
DEFAULT_UA = "Chef Client" << UA_COMMON
USER_AGENT = "User-Agent".freeze
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/http/socketless_chef_zero_client.rb b/lib/chef/http/socketless_chef_zero_client.rb
index 34a5dbb083..6484a6d540 100644
--- a/lib/chef/http/socketless_chef_zero_client.rb
+++ b/lib/chef/http/socketless_chef_zero_client.rb
@@ -131,7 +131,7 @@ class Chef
505 => "HTTP Version Not Supported",
507 => "Insufficient Storage",
511 => "Network Authentication Required",
- }
+ }.freeze
STATUS_MESSAGE.each_value { |v| v.freeze }
STATUS_MESSAGE.freeze
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..e28ca81f71 100644
--- a/lib/chef/knife.rb
+++ b/lib/chef/knife.rb
@@ -234,7 +234,7 @@ class Chef
end
end
- OFFICIAL_PLUGINS = %w{ec2 rackspace windows openstack azure google linode push vcenter lpar}
+ OFFICIAL_PLUGINS = %w{ec2 rackspace windows openstack azure google linode push vcenter lpar}.freeze
class << self
def list_commands(preferred_category = nil)
@@ -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/config_get.rb b/lib/chef/knife/config_get.rb
new file mode 100644
index 0000000000..23085d177c
--- /dev/null
+++ b/lib/chef/knife/config_get.rb
@@ -0,0 +1,126 @@
+#
+# Author:: Joshua Timberman <opensource@housepub.org>
+# Copyright:: Copyright (c) 2012, Joshua Timberman
+# Copyright:: Copyright (c) 2018, Noah Kantrowitz
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require "chef/knife"
+
+class Chef
+ class Knife
+ class ConfigGet < Knife
+ banner "knife config get [OPTION...] (options)\nDisplays the value of Chef::Config[OPTION] (or all config values)"
+
+ option :all,
+ short: "-a",
+ long: "--all",
+ description: "Include options that are not set in the configuration",
+ default: false
+
+ option :raw,
+ short: "-r",
+ long: "--raw",
+ description: "Display a each value with no formatting",
+ default: false
+
+ def run
+ if config[:format] == "summary" && !config[:raw]
+ # If using the default, human-readable output, also show which config files are being loaded.
+ # Some of this is a bit hacky since it duplicates
+ wcl = self.class.config_loader
+ if wcl.credentials_found
+ loading_from("credentials", ChefConfig::PathHelper.home(".chef", "credentials"))
+ end
+ if wcl.config_location
+ loading_from("configuration", wcl.config_location)
+ end
+ if Chef::Config[:config_d_dir]
+ wcl.find_dot_d(Chef::Config[:config_d_dir]).each do |path|
+ loading_from(".d/ configuration", wcl.config_location)
+ end
+ end
+ end
+
+ # Dump the whole config, including defaults is --all was given.
+ config_data = Chef::Config.save(config[:all])
+ # Two special cases, these are set during knife startup but we don't usually care about them.
+ unless config[:all]
+ config_data.delete(:color)
+ # Only keep these if true, false is much less important because it's the default.
+ config_data.delete(:local_mode) unless config_data[:local_mode]
+ config_data.delete(:enforce_path_sanity) unless config_data[:enforce_path_sanity]
+ end
+
+ # Extract the data to show.
+ output_data = {}
+ if @name_args.empty?
+ output_data = config_data
+ else
+ @name_args.each do |filter|
+ if filter =~ %r{^/(.*)/(i?)$}
+ # It's a regex.
+ filter_re = Regexp.new($1, $2 ? Regexp::IGNORECASE : 0)
+ config_data.each do |key, value|
+ output_data[key] = value if key.to_s =~ filter_re
+ end
+ else
+ # It's a dotted path string.
+ filter_parts = filter.split(/\./)
+ extract = lambda do |memo, filter_part|
+ memo.is_a?(Hash) ? memo[filter_part.to_sym] : nil
+ end
+ # Check against both config_data and all of the data, so that even
+ # in non-all mode, if you ask for a key that isn't in the non-all
+ # data, it will check against the broader set.
+ output_data[filter] = filter_parts.inject(config_data, &extract) || filter_parts.inject(Chef::Config.save(true), &extract)
+ end
+ end
+ end
+
+ # Fix up some values.
+ output_data.each do |key, value|
+ if value == STDOUT
+ output_data[key] = "STDOUT"
+ elsif value == STDERR
+ output_data[key] = "STDERR"
+ end
+ end
+
+ # Show the data.
+ if config[:raw]
+ output_data.each_value do |value|
+ ui.msg(value)
+ end
+ else
+ ui.output(output_data)
+ end
+ end
+
+ private
+
+ # Display a banner about loading from a config file.
+ #
+ # @api private
+ # @param type_of_file [String] Description of the file for the banner.
+ # @param path [String] Path of the file.
+ # @return [nil]
+ def loading_from(type_of_file, path)
+ path = Pathname.new(path).realpath
+ ui.msg(ui.color("Loading from #{type_of_file} file #{path}", :yellow))
+ end
+ end
+ end
+end
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..2b3c6ba948 100644
--- a/lib/chef/knife/cookbook_upload.rb
+++ b/lib/chef/knife/cookbook_upload.rb
@@ -25,7 +25,7 @@ class Chef
class Knife
class CookbookUpload < Knife
- CHECKSUM = "checksum"
+ CHECKSUM = "checksum".freeze
MATCH_CHECKSUM = /[0-9a-f]{32,}/
deps do
@@ -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/core/hashed_command_loader.rb b/lib/chef/knife/core/hashed_command_loader.rb
index 8423c01812..cbe4d558c1 100644
--- a/lib/chef/knife/core/hashed_command_loader.rb
+++ b/lib/chef/knife/core/hashed_command_loader.rb
@@ -24,7 +24,7 @@ class Chef
# for the given command.
#
class HashedCommandLoader < Chef::Knife::SubcommandLoader
- KEY = "_autogenerated_command_paths"
+ KEY = "_autogenerated_command_paths".freeze
attr_accessor :manifest
def initialize(chef_config_dir, plugin_manifest)
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/log/winevt.rb b/lib/chef/log/winevt.rb
index a35f99c52c..7b756e1aab 100644
--- a/lib/chef/log/winevt.rb
+++ b/lib/chef/log/winevt.rb
@@ -36,7 +36,7 @@ class Chef
FATAL_EVENT_ID = 10104
# Since we must install the event logger, this is not really configurable
- SOURCE = "Chef"
+ SOURCE = "Chef".freeze
include Chef::Mixin::Unformatter
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/deprecation.rb b/lib/chef/mixin/deprecation.rb
index 06726b5252..d0e36d5f93 100644
--- a/lib/chef/mixin/deprecation.rb
+++ b/lib/chef/mixin/deprecation.rb
@@ -54,7 +54,7 @@ class Chef
module Deprecation
class DeprecatedObjectProxyBase
- KEEPERS = %w{__id__ __send__ instance_eval == equal? initialize object_id}
+ KEEPERS = %w{__id__ __send__ instance_eval == equal? initialize object_id}.freeze
instance_methods.each { |method_name| undef_method(method_name) unless KEEPERS.include?(method_name.to_s) }
end
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/mixin/xml_escape.rb b/lib/chef/mixin/xml_escape.rb
index 243bb7f044..7011ff4f56 100644
--- a/lib/chef/mixin/xml_escape.rb
+++ b/lib/chef/mixin/xml_escape.rb
@@ -89,18 +89,18 @@ class Chef
156 => 339, # latin small ligature oe
158 => 382, # latin small letter z with caron
159 => 376 # latin capital letter y with diaeresis
- }
+ }.freeze
# http://www.w3.org/TR/REC-xml/#dt-chardata
PREDEFINED = {
38 => "&amp;", # ampersand
60 => "&lt;", # left angle bracket
62 => "&gt;" # right angle bracket
- }
+ }.freeze
# http://www.w3.org/TR/REC-xml/#charsets
VALID = [[0x9, 0xA, 0xD], (0x20..0xD7FF),
- (0xE000..0xFFFD), (0x10000..0x10FFFF)]
+ (0xE000..0xFFFD), (0x10000..0x10FFFF)].freeze
def xml_escape(unescaped_str)
unescaped_str.unpack("U*").map { |char| xml_escape_char!(char) }.join
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..46683d9405 100644
--- a/lib/chef/node/attribute.rb
+++ b/lib/chef/node/attribute.rb
@@ -69,14 +69,14 @@ class Chef
:@env_default,
:@role_default,
:@force_default,
- ]
+ ].freeze
OVERRIDE_COMPONENTS = [
:@override,
:@role_override,
:@env_override,
:@force_override,
- ]
+ ].freeze
[:all?,
:any?,
@@ -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/attribute_collections.rb b/lib/chef/node/attribute_collections.rb
index 2836473b1d..f62eceb646 100644
--- a/lib/chef/node/attribute_collections.rb
+++ b/lib/chef/node/attribute_collections.rb
@@ -55,7 +55,7 @@ class Chef
:sort_by!,
:uniq!,
:unshift,
- ]
+ ].freeze
# For all of the methods that may mutate an Array, we override them to
# also invalidate the cached merged_attributes on the root
@@ -140,7 +140,7 @@ class Chef
:replace,
:select!,
:shift,
- ]
+ ].freeze
# For all of the mutating methods on Mash, override them so that they
# also invalidate the cached `merged_attributes` on the root Attribute
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/mixin/immutablize_array.rb b/lib/chef/node/mixin/immutablize_array.rb
index ba59385d68..000a088410 100644
--- a/lib/chef/node/mixin/immutablize_array.rb
+++ b/lib/chef/node/mixin/immutablize_array.rb
@@ -121,7 +121,7 @@ class Chef
:values_at,
:zip,
:|,
- ]
+ ].freeze
# A list of methods that mutate Array. Each of these is overridden to
# raise an error, making this instances of this class more or less
# immutable.
@@ -160,7 +160,7 @@ class Chef
:uniq!,
:unshift,
:update,
- ]
+ ].freeze
# Redefine all of the methods that mutate a Hash to raise an error when called.
# This is the magic that makes this object "Immutable"
diff --git a/lib/chef/node/mixin/immutablize_hash.rb b/lib/chef/node/mixin/immutablize_hash.rb
index 71d2f754a4..04ac5418ef 100644
--- a/lib/chef/node/mixin/immutablize_hash.rb
+++ b/lib/chef/node/mixin/immutablize_hash.rb
@@ -121,7 +121,7 @@ class Chef
:values,
:values_at,
:zip,
- ]
+ ].freeze
DISALLOWED_MUTATOR_METHODS = [
:[]=,
:clear,
@@ -147,7 +147,7 @@ class Chef
:update,
:write!,
:write,
- ]
+ ].freeze
# Redefine all of the methods that mutate a Hash to raise an error when called.
# This is the magic that makes this object "Immutable"
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/apt_update.rb b/lib/chef/provider/apt_update.rb
index 9d794abcf0..28fc122055 100644
--- a/lib/chef/provider/apt_update.rb
+++ b/lib/chef/provider/apt_update.rb
@@ -25,8 +25,8 @@ class Chef
class AptUpdate < Chef::Provider
provides :apt_update, platform_family: "debian"
- APT_CONF_DIR = "/etc/apt/apt.conf.d"
- STAMP_DIR = "/var/lib/apt/periodic"
+ APT_CONF_DIR = "/etc/apt/apt.conf.d".freeze
+ STAMP_DIR = "/var/lib/apt/periodic".freeze
def load_current_resource
end
diff --git a/lib/chef/provider/cron.rb b/lib/chef/provider/cron.rb
index 70edd89636..f25a58a789 100644
--- a/lib/chef/provider/cron.rb
+++ b/lib/chef/provider/cron.rb
@@ -25,9 +25,9 @@ class Chef
provides :cron, os: ["!aix", "!solaris2"]
- SPECIAL_TIME_VALUES = [:reboot, :yearly, :annually, :monthly, :weekly, :daily, :midnight, :hourly]
- CRON_ATTRIBUTES = [:minute, :hour, :day, :month, :weekday, :time, :command, :mailto, :path, :shell, :home, :environment]
- WEEKDAY_SYMBOLS = [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday]
+ SPECIAL_TIME_VALUES = [:reboot, :yearly, :annually, :monthly, :weekly, :daily, :midnight, :hourly].freeze
+ CRON_ATTRIBUTES = [:minute, :hour, :day, :month, :weekday, :time, :command, :mailto, :path, :shell, :home, :environment].freeze
+ WEEKDAY_SYMBOLS = [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday].freeze
CRON_PATTERN = /\A([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+|[a-zA-Z]{3})\s([-0-9*,\/]+|[a-zA-Z]{3})\s(.*)/
SPECIAL_PATTERN = /\A(@(#{SPECIAL_TIME_VALUES.join('|')}))\s(.*)/
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/openbsd.rb b/lib/chef/provider/service/openbsd.rb
index 126a431742..34e05df504 100644
--- a/lib/chef/provider/service/openbsd.rb
+++ b/lib/chef/provider/service/openbsd.rb
@@ -31,8 +31,8 @@ class Chef
attr_reader :init_command, :rc_conf, :rc_conf_local, :enabled_state_found
- RC_CONF_PATH = "/etc/rc.conf"
- RC_CONF_LOCAL_PATH = "/etc/rc.conf.local"
+ RC_CONF_PATH = "/etc/rc.conf".freeze
+ RC_CONF_LOCAL_PATH = "/etc/rc.conf.local".freeze
def initialize(new_resource, run_context)
super
diff --git a/lib/chef/provider/service/windows.rb b/lib/chef/provider/service/windows.rb
index 2482ce6a5c..59d3fc5a29 100644
--- a/lib/chef/provider/service/windows.rb
+++ b/lib/chef/provider/service/windows.rb
@@ -34,22 +34,22 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service
include Chef::Win32ServiceConstants
# Win32::Service.get_start_type
- AUTO_START = "auto start"
- MANUAL = "demand start"
- DISABLED = "disabled"
+ AUTO_START = "auto start".freeze
+ MANUAL = "demand start".freeze
+ DISABLED = "disabled".freeze
# Win32::Service.get_current_state
- RUNNING = "running"
- STOPPED = "stopped"
- CONTINUE_PENDING = "continue pending"
- PAUSE_PENDING = "pause pending"
- PAUSED = "paused"
- START_PENDING = "start pending"
- STOP_PENDING = "stop pending"
+ RUNNING = "running".freeze
+ STOPPED = "stopped".freeze
+ CONTINUE_PENDING = "continue pending".freeze
+ PAUSE_PENDING = "pause pending".freeze
+ PAUSED = "paused".freeze
+ START_PENDING = "start pending".freeze
+ STOP_PENDING = "stop pending".freeze
TIMEOUT = 60
- SERVICE_RIGHT = "SeServiceLogonRight"
+ SERVICE_RIGHT = "SeServiceLogonRight".freeze
def load_current_resource
@current_resource = Chef::Resource::WindowsService.new(new_resource.name)
@@ -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/provider/user/solaris.rb b/lib/chef/provider/user/solaris.rb
index 38e7f8cb31..2c3222534d 100644
--- a/lib/chef/provider/user/solaris.rb
+++ b/lib/chef/provider/user/solaris.rb
@@ -27,7 +27,7 @@ class Chef
provides :solaris_user
provides :user, os: %w{openindiana opensolaris illumos omnios solaris2 smartos}
- PASSWORD_FILE = "/etc/shadow"
+ PASSWORD_FILE = "/etc/shadow".freeze
def create_user
shell_out!("useradd", universal_options, useradd_options, new_resource.username)
diff --git a/lib/chef/provider/windows_task.rb b/lib/chef/provider/windows_task.rb
index f8df5dc9a8..f10e4adb70 100644
--- a/lib/chef/provider/windows_task.rb
+++ b/lib/chef/provider/windows_task.rb
@@ -47,7 +47,7 @@ class Chef
OCT: TaskScheduler::OCTOBER,
NOV: TaskScheduler::NOVEMBER,
DEC: TaskScheduler::DECEMBER,
- }
+ }.freeze
DAYS_OF_WEEK = { MON: TaskScheduler::MONDAY,
TUE: TaskScheduler::TUESDAY,
@@ -55,14 +55,14 @@ class Chef
THU: TaskScheduler::THURSDAY,
FRI: TaskScheduler::FRIDAY,
SAT: TaskScheduler::SATURDAY,
- SUN: TaskScheduler::SUNDAY }
+ SUN: TaskScheduler::SUNDAY }.freeze
WEEKS_OF_MONTH = {
FIRST: TaskScheduler::FIRST_WEEK,
SECOND: TaskScheduler::SECOND_WEEK,
THIRD: TaskScheduler::THIRD_WEEK,
FOURTH: TaskScheduler::FOURTH_WEEK,
- }
+ }.freeze
DAYS_OF_MONTH = {
1 => TaskScheduler::TASK_FIRST,
@@ -96,7 +96,7 @@ class Chef
29 => TaskScheduler::TASK_TWENTY_NINTH,
30 => TaskScheduler::TASK_THIRTYETH,
31 => TaskScheduler::TASK_THIRTY_FIRST,
- }
+ }.freeze
def load_current_resource
@current_resource = Chef::Resource::WindowsTask.new(new_resource.name)
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index a30504bc91..d341e401de 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
@@ -1181,8 +1181,8 @@ class Chef
# Internal Resource Interface (for Chef)
#
- FORBIDDEN_IVARS = [:@run_context, :@logger, :@not_if, :@only_if, :@enclosing_provider, :@description, :@introduced, :@examples, :@validation_message, :@deprecated]
- HIDDEN_IVARS = [:@allowed_actions, :@resource_name, :@source_line, :@run_context, :@logger, :@name, :@not_if, :@only_if, :@elapsed_time, :@enclosing_provider, :@description, :@introduced, :@examples, :@validation_message, :@deprecated]
+ FORBIDDEN_IVARS = [:@run_context, :@logger, :@not_if, :@only_if, :@enclosing_provider, :@description, :@introduced, :@examples, :@validation_message, :@deprecated].freeze
+ HIDDEN_IVARS = [:@allowed_actions, :@resource_name, :@source_line, :@run_context, :@logger, :@name, :@not_if, :@only_if, :@elapsed_time, :@enclosing_provider, :@description, :@introduced, :@examples, :@validation_message, :@deprecated].freeze
include Chef::Mixin::ConvertToClassName
extend Chef::Mixin::ConvertToClassName
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/resource/windows_service.rb b/lib/chef/resource/windows_service.rb
index 7b550ea11a..a9ce1f454f 100644
--- a/lib/chef/resource/windows_service.rb
+++ b/lib/chef/resource/windows_service.rb
@@ -28,7 +28,7 @@ class Chef
automatic: SERVICE_AUTO_START,
manual: SERVICE_DEMAND_START,
disabled: SERVICE_DISABLED,
- }
+ }.freeze
# Until #1773 is resolved, you need to manually specify the windows_service resource
# to use action :configure_startup and attribute startup_type
diff --git a/lib/chef/resource/windows_task.rb b/lib/chef/resource/windows_task.rb
index 42665ef82c..fd4c93907d 100644
--- a/lib/chef/resource/windows_task.rb
+++ b/lib/chef/resource/windows_task.rb
@@ -63,10 +63,10 @@ class Chef
attr_accessor :exists, :task, :command_arguments
SYSTEM_USERS = ['NT AUTHORITY\SYSTEM', "SYSTEM", 'NT AUTHORITY\LOCALSERVICE', 'NT AUTHORITY\NETWORKSERVICE', 'BUILTIN\USERS', "USERS"].freeze
- VALID_WEEK_DAYS = %w{ mon tue wed thu fri sat sun * }
+ VALID_WEEK_DAYS = %w{ mon tue wed thu fri sat sun * }.freeze
VALID_DAYS_OF_MONTH = ("1".."31").to_a << "last" << "lastday"
- VALID_MONTHS = %w{JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC *}
- VALID_WEEKS = %w{FIRST SECOND THIRD FOURTH LAST LASTDAY}
+ VALID_MONTHS = %w{JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC *}.freeze
+ VALID_WEEKS = %w{FIRST SECOND THIRD FOURTH LAST LASTDAY}.freeze
def after_created
if random_delay
diff --git a/lib/chef/resource_reporter.rb b/lib/chef/resource_reporter.rb
index 1ec25fc79a..3198f84d12 100644
--- a/lib/chef/resource_reporter.rb
+++ b/lib/chef/resource_reporter.rb
@@ -96,7 +96,7 @@ class Chef
attr_reader :exception
attr_reader :error_descriptions
- PROTOCOL_VERSION = "0.1.0"
+ PROTOCOL_VERSION = "0.1.0".freeze
def initialize(rest_client)
if Chef::Config[:enable_reporting] && !Chef::Config[:why_run]
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/user_v1.rb b/lib/chef/user_v1.rb
index 8bd92dfab8..293bec54a7 100644
--- a/lib/chef/user_v1.rb
+++ b/lib/chef/user_v1.rb
@@ -39,7 +39,7 @@ class Chef
include Chef::Mixin::ParamsValidate
include Chef::Mixin::ApiVersionRequestHandling
- SUPPORTED_API_VERSIONS = [0, 1]
+ SUPPORTED_API_VERSIONS = [0, 1].freeze
def initialize
@username = nil
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/util/windows/net_user.rb b/lib/chef/util/windows/net_user.rb
index 6c441a7513..92e8b5cc69 100644
--- a/lib/chef/util/windows/net_user.rb
+++ b/lib/chef/util/windows/net_user.rb
@@ -60,7 +60,7 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows
profile: :usri3_profile,
home_dir_drive: :usri3_home_dir_drive,
password_expired: :usri3_password_expired,
- }
+ }.freeze
def transform_usri3(args)
args.inject({}) do |memo, (k, v)|
diff --git a/lib/chef/version.rb b/lib/chef/version.rb
index c8164e378b..ebc99d6a03 100644
--- a/lib/chef/version.rb
+++ b/lib/chef/version.rb
@@ -23,7 +23,7 @@ require "chef/version_string"
class Chef
CHEF_ROOT = File.expand_path("../..", __FILE__)
- VERSION = Chef::VersionString.new("14.3.25")
+ VERSION = Chef::VersionString.new("14.3.29")
end
#
diff --git a/lib/chef/version_constraint.rb b/lib/chef/version_constraint.rb
index f10325f946..6b57cfefe1 100644
--- a/lib/chef/version_constraint.rb
+++ b/lib/chef/version_constraint.rb
@@ -18,9 +18,9 @@ require "chef/version_class"
class Chef
class VersionConstraint
- DEFAULT_CONSTRAINT = ">= 0.0.0"
- STANDARD_OPS = %w{< > <= >=}
- OPS = %w{< > = <= >= ~>}
+ DEFAULT_CONSTRAINT = ">= 0.0.0".freeze
+ STANDARD_OPS = %w{< > <= >=}.freeze
+ OPS = %w{< > = <= >= ~>}.freeze
PATTERN = /^(#{OPS.join('|')}) *([0-9].*)$/
VERSION_CLASS = Chef::Version
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
diff --git a/lib/chef/win32/version.rb b/lib/chef/win32/version.rb
index f96fd18316..9a506aa740 100644
--- a/lib/chef/win32/version.rb
+++ b/lib/chef/win32/version.rb
@@ -65,7 +65,7 @@ class Chef
"Windows Server 2003" => { major: 5, minor: 2, callable: lambda { |product_type, suite_mask| get_system_metrics(SM_SERVERR2) == 0 } },
"Windows XP" => { major: 5, minor: 1 },
"Windows 2000" => { major: 5, minor: 0 },
- }
+ }.freeze
def initialize
@major_version, @minor_version, @build_number = get_version