summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStuart Preston <stuart@chef.io>2018-07-03 23:06:40 +0100
committerStuart Preston <stuart@chef.io>2018-07-03 23:06:40 +0100
commit059335c5cf232cdd5a14e7fd1cb2f2995e7cd15f (patch)
tree0363dad76063870ccb63f2443a5da370d4d5a721
parentf99fdfa1fdb8e3ce804642913698b22e9569bf98 (diff)
parent37517d1c380d9d4cbc9d8bd2803da521be89184e (diff)
downloadchef-059335c5cf232cdd5a14e7fd1cb2f2995e7cd15f.tar.gz
Merge branch 'master' into sp/7412
Signed-off-by: <>
-rw-r--r--.travis.yml36
-rw-r--r--CHANGELOG.md9
-rw-r--r--Gemfile.lock14
-rw-r--r--RELEASE_NOTES.md22
-rw-r--r--Rakefile2
-rw-r--r--VERSION2
-rw-r--r--chef-config/chef-config.gemspec2
-rw-r--r--chef-config/lib/chef-config/config.rb20
-rw-r--r--chef-config/lib/chef-config/mixin/credentials.rb2
-rw-r--r--chef-config/lib/chef-config/mixin/dot_d.rb25
-rw-r--r--chef-config/lib/chef-config/path_helper.rb18
-rw-r--r--chef-config/lib/chef-config/version.rb2
-rw-r--r--chef-config/lib/chef-config/workstation_config_loader.rb50
-rw-r--r--chef-config/spec/unit/config_spec.rb18
-rw-r--r--chef-config/spec/unit/workstation_config_loader_spec.rb64
-rw-r--r--ext/win32-eventlog/Rakefile14
-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
-rw-r--r--spec/integration/knife/config_get_spec.rb183
-rw-r--r--spec/scripts/ssl-serve.rb2
-rw-r--r--spec/support/shared/functional/securable_resource_with_reporting.rb2
-rw-r--r--spec/support/shared/integration/knife_support.rb8
-rw-r--r--spec/tiny_server.rb12
-rw-r--r--spec/unit/application/solo_spec.rb2
-rw-r--r--spec/unit/audit/audit_reporter_spec.rb8
-rw-r--r--spec/unit/chef_fs/file_system/repository/directory_spec.rb2
-rw-r--r--spec/unit/cookbook/metadata_spec.rb4
-rw-r--r--spec/unit/cookbook/synchronizer_spec.rb24
-rw-r--r--spec/unit/data_bag_item_spec.rb2
-rw-r--r--spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb2
-rw-r--r--spec/unit/mixin/shell_out_spec.rb4
-rw-r--r--spec/unit/node/attribute_spec.rb14
-rw-r--r--spec/unit/provider/apt_repository_spec.rb4
-rw-r--r--spec/unit/provider/group/dscl_spec.rb6
-rw-r--r--spec/unit/provider/mount/windows_spec.rb4
-rw-r--r--spec/unit/provider/remote_file/cache_control_data_spec.rb14
-rw-r--r--spec/unit/provider/zypper_repository_spec.rb4
-rw-r--r--spec/unit/provider_resolver_spec.rb2
-rw-r--r--spec/unit/role_spec.rb2
-rw-r--r--tasks/cbgb.rb4
-rw-r--r--tasks/maintainers.rb10
127 files changed, 842 insertions, 340 deletions
diff --git a/.travis.yml b/.travis.yml
index 40b2e7ddef..3f9bede22d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -116,23 +116,25 @@ matrix:
# rvm: 2.5.1
### START TEST KITCHEN ONLY ###
#
- - rvm: 2.4.4
- services: docker
- sudo: required
- gemfile: kitchen-tests/Gemfile
- before_install:
- - gem update --system $(grep rubygems omnibus_overrides.rb | cut -d'"' -f2)
- - gem install bundler -v $(grep :bundler omnibus_overrides.rb | cut -d'"' -f2)
- before_script:
- - sudo iptables -L DOCKER || ( echo "DOCKER iptables chain missing" ; sudo iptables -N DOCKER )
- - cd kitchen-tests
- script:
- - bundle exec kitchen test end-to-end-amazonlinux-2
- after_failure:
- - cat .kitchen/logs/kitchen.log
- env:
- - AMAZON=2
- - KITCHEN_YAML=kitchen.travis.yml
+ # Amazon Linux 2 disabled pending fixes in omnitruck/mixlib-install
+ #
+ # - rvm: 2.4.4
+ # services: docker
+ # sudo: required
+ # gemfile: kitchen-tests/Gemfile
+ # before_install:
+ # - gem update --system $(grep rubygems omnibus_overrides.rb | cut -d'"' -f2)
+ # - gem install bundler -v $(grep :bundler omnibus_overrides.rb | cut -d'"' -f2)
+ # before_script:
+ # - sudo iptables -L DOCKER || ( echo "DOCKER iptables chain missing" ; sudo iptables -N DOCKER )
+ # - cd kitchen-tests
+ # script:
+ # - bundle exec kitchen test end-to-end-amazonlinux-2
+ # after_failure:
+ # - cat .kitchen/logs/kitchen.log
+ # env:
+ # - AMAZON=2
+ # - KITCHEN_YAML=kitchen.travis.yml
- rvm: 2.4.4
services: docker
sudo: required
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 36fa0f70bd..7eb628bccf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,15 +1,18 @@
<!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ -->
-<!-- latest_release 14.3.25 -->
-## [v14.3.25](https://github.com/chef/chef/tree/v14.3.25) (2018-07-02)
+<!-- latest_release 14.3.29 -->
+## [v14.3.29](https://github.com/chef/chef/tree/v14.3.29) (2018-07-03)
#### Merged Pull Requests
-- Chefstyle fixes [#7414](https://github.com/chef/chef/pull/7414) ([lamont-granquist](https://github.com/lamont-granquist))
+- knife config and a bunch of UX improvements [#7390](https://github.com/chef/chef/pull/7390) ([coderanger](https://github.com/coderanger))
<!-- latest_release -->
<!-- release_rollup since=14.2.0 -->
### Changes since 14.2.0 release
#### Merged Pull Requests
+- knife config and a bunch of UX improvements [#7390](https://github.com/chef/chef/pull/7390) ([coderanger](https://github.com/coderanger)) <!-- 14.3.29 -->
+- chefstyle: fix Style/MutableConstant [#7417](https://github.com/chef/chef/pull/7417) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 14.3.28 -->
+- More chefstyle updates [#7415](https://github.com/chef/chef/pull/7415) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 14.3.27 -->
- Chefstyle fixes [#7414](https://github.com/chef/chef/pull/7414) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 14.3.25 -->
- Pull in new InSpec and win32-service [#7405](https://github.com/chef/chef/pull/7405) ([tas50](https://github.com/tas50)) <!-- 14.3.24 -->
- Rename the kitchen base test suite to end-to-end [#7385](https://github.com/chef/chef/pull/7385) ([tas50](https://github.com/tas50)) <!-- 14.3.23 -->
diff --git a/Gemfile.lock b/Gemfile.lock
index 09976d50c7..07ff8835fa 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -9,10 +9,10 @@ GIT
PATH
remote: .
specs:
- chef (14.3.25)
+ chef (14.3.29)
addressable
bundler (>= 1.10)
- chef-config (= 14.3.25)
+ chef-config (= 14.3.29)
chef-zero (>= 13.0)
diff-lcs (~> 1.2, >= 1.2.4)
erubis (~> 2.7)
@@ -40,10 +40,10 @@ PATH
specinfra (~> 2.10)
syslog-logger (~> 1.6)
uuidtools (~> 2.1.5)
- chef (14.3.25-universal-mingw32)
+ chef (14.3.29-universal-mingw32)
addressable
bundler (>= 1.10)
- chef-config (= 14.3.25)
+ chef-config (= 14.3.29)
chef-zero (>= 13.0)
diff-lcs (~> 1.2, >= 1.2.4)
erubis (~> 2.7)
@@ -86,10 +86,10 @@ PATH
PATH
remote: chef-config
specs:
- chef-config (14.3.25)
+ chef-config (14.3.29)
addressable
fuzzyurl
- mixlib-config (~> 2.0)
+ mixlib-config (>= 2.2.11, < 3.0)
mixlib-shellout (~> 2.0)
tomlrb (~> 1.2)
@@ -179,7 +179,7 @@ GEM
mixlib-log
mixlib-authentication (2.1.1)
mixlib-cli (1.7.0)
- mixlib-config (2.2.10)
+ mixlib-config (2.2.11)
tomlrb
mixlib-log (2.0.4)
mixlib-shellout (2.3.2)
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 167e04fa3a..6b601bd569 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -1,5 +1,27 @@
This file holds "in progress" release notes for the current release under development and is intended for consumption by the Chef Documentation team. Please see <https://docs.chef.io/release_notes.html> for the official Chef release notes.
+## New `knife config get` command
+
+The `knife config get` command has been added to help with debugging configuration
+issues with `knife` and other tools that use the `knife.rb` file.
+
+With no arguments, it will display all options you've set:
+
+```bash
+$ knife config get
+Loading from configuration file /Users/.../.chef/knife.rb
+chef_server_url: https://...
+client_key: /Users/.../.chef/user.pem
+config_file: /Users/.../.chef/knife.rb
+log_level: warn
+log_location: STDERR
+node_name: ...
+validation_key:
+```
+
+You can also pass specific keys to only display those `knife config get node_name client_key`,
+or use `--all` to display everything (including options that are using the default value).
+
## Simplification of `shell_out` APIs
The following methods are deprecated:
diff --git a/Rakefile b/Rakefile
index 2ec934c432..97ec59ae5d 100644
--- a/Rakefile
+++ b/Rakefile
@@ -61,7 +61,7 @@ end
begin
require "yard"
- DOC_FILES = [ "README.rdoc", "LICENSE", "spec/tiny_server.rb", "lib/**/*.rb" ]
+ DOC_FILES = [ "README.rdoc", "LICENSE", "spec/tiny_server.rb", "lib/**/*.rb" ].freeze
namespace :yard do
desc "Create YARD documentation"
diff --git a/VERSION b/VERSION
index 411b904785..1d4c697072 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-14.3.26 \ No newline at end of file
+14.3.29 \ No newline at end of file
diff --git a/chef-config/chef-config.gemspec b/chef-config/chef-config.gemspec
index 532b1699d7..f372f944c6 100644
--- a/chef-config/chef-config.gemspec
+++ b/chef-config/chef-config.gemspec
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]
spec.add_dependency "mixlib-shellout", "~> 2.0"
- spec.add_dependency "mixlib-config", "~> 2.0"
+ spec.add_dependency "mixlib-config", ">= 2.2.11", "< 3.0"
spec.add_dependency "fuzzyurl"
spec.add_dependency "addressable"
spec.add_dependency "tomlrb", "~> 1.2"
diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb
index 07be3e9ef6..3bba8af7f4 100644
--- a/chef-config/lib/chef-config/config.rb
+++ b/chef-config/lib/chef-config/config.rb
@@ -286,7 +286,7 @@ module ChefConfig
# the cache path.
unless path_accessible?(primary_cache_path) || path_accessible?(primary_cache_root)
secondary_cache_path = PathHelper.join(user_home, ".chef")
- ChefConfig.logger.info("Unable to access cache at #{primary_cache_path}. Switching cache to #{secondary_cache_path}")
+ ChefConfig.logger.trace("Unable to access cache at #{primary_cache_path}. Switching cache to #{secondary_cache_path}")
secondary_cache_path
else
primary_cache_path
@@ -656,7 +656,15 @@ module ChefConfig
#
# If chef-zero is enabled, this defaults to nil (no authentication).
default(:validation_key) { chef_zero.enabled ? nil : platform_specific_path("/etc/chef/validation.pem") }
- default :validation_client_name, "chef-validator"
+ default :validation_client_name do
+ # If the URL is set and looks like a normal Chef Server URL, extract the
+ # org name and use that as part of the default.
+ if chef_server_url.to_s =~ %r{/organizations/(.*)$}
+ "#{$1}-validator"
+ else
+ "chef-validator"
+ end
+ end
default :validation_key_contents, nil
# When creating a new client via the validation_client account, Chef 11
@@ -962,10 +970,10 @@ module ChefConfig
# TODO add some post-file-parsing logic that automatically calls this so
# users don't have to
def self.export_proxies
- export_proxy("http", http_proxy, http_proxy_user, http_proxy_pass) if http_proxy
- export_proxy("https", https_proxy, https_proxy_user, https_proxy_pass) if https_proxy
- export_proxy("ftp", ftp_proxy, ftp_proxy_user, ftp_proxy_pass) if ftp_proxy
- export_no_proxy(no_proxy) if no_proxy
+ export_proxy("http", http_proxy, http_proxy_user, http_proxy_pass) if has_key?(:http_proxy) && http_proxy
+ export_proxy("https", https_proxy, https_proxy_user, https_proxy_pass) if has_key?(:https_proxy) && https_proxy
+ export_proxy("ftp", ftp_proxy, ftp_proxy_user, ftp_proxy_pass) if has_key?(:ftp_proxy) && ftp_proxy
+ export_no_proxy(no_proxy) if has_key?(:no_proxy) && no_proxy
end
# Character classes for Addressable
diff --git a/chef-config/lib/chef-config/mixin/credentials.rb b/chef-config/lib/chef-config/mixin/credentials.rb
index 4c0192fff8..5a73a49add 100644
--- a/chef-config/lib/chef-config/mixin/credentials.rb
+++ b/chef-config/lib/chef-config/mixin/credentials.rb
@@ -28,7 +28,7 @@ module ChefConfig
return unless File.file?(credentials_file)
- context = File.read(context_file) if File.file?(context_file)
+ context = File.read(context_file).strip if File.file?(context_file)
environment = ENV.fetch("CHEF_PROFILE", nil)
diff --git a/chef-config/lib/chef-config/mixin/dot_d.rb b/chef-config/lib/chef-config/mixin/dot_d.rb
index 778c25d7f9..4c9c998908 100644
--- a/chef-config/lib/chef-config/mixin/dot_d.rb
+++ b/chef-config/lib/chef-config/mixin/dot_d.rb
@@ -19,17 +19,22 @@ require "chef-config/path_helper"
module ChefConfig
module Mixin
module DotD
+ # Find available configuration files in a `.d/` style include directory.
+ #
+ # @api internal
+ # @param path [String] Base .d/ path to load from.
+ # @return [Array<String>]
+ def find_dot_d(path)
+ Dir["#{PathHelper.escape_glob_dir(path)}/*.rb"].select { |entry| File.file?(entry) }.sort
+ end
+
+ # Load configuration from a `.d/` style include directory.
+ #
+ # @api internal
+ # @param path [String] Base .d/ path to load from.
+ # @return [void]
def load_dot_d(path)
- dot_d_files =
- begin
- entries = Array.new
- entries << Dir.glob(File.join(
- ChefConfig::PathHelper.escape_glob_dir(path), "*.rb"))
- entries.flatten.select do |entry|
- File.file?(entry)
- end
- end
- dot_d_files.sort.map do |conf|
+ find_dot_d(path).each do |conf|
apply_config(IO.read(conf), conf)
end
end
diff --git a/chef-config/lib/chef-config/path_helper.rb b/chef-config/lib/chef-config/path_helper.rb
index 6341ffe4e6..fbb413578a 100644
--- a/chef-config/lib/chef-config/path_helper.rb
+++ b/chef-config/lib/chef-config/path_helper.rb
@@ -172,6 +172,18 @@ module ChefConfig
Pathname.new(cleanpath(to)).relative_path_from(Pathname.new(cleanpath(from)))
end
+ # Set the project-specific home directory environment variable.
+ #
+ # This can be used to allow per-tool home directory aliases like $KNIFE_HOME.
+ #
+ # @param [env_var] Key for an environment variable to use.
+ # @return [nil]
+ def self.per_tool_home_environment=(env_var)
+ @@per_tool_home_environment = env_var
+ # Reset this in case .home was already called.
+ @@home_dir = nil
+ end
+
# Retrieves the "home directory" of the current user while trying to ascertain the existence
# of said directory. The path returned uses / for all separators (the ruby standard format).
# If the home directory doesn't exist or an error is otherwise encountered, nil is returned.
@@ -185,7 +197,9 @@ module ChefConfig
# Home-path discovery is performed once. If a path is discovered, that value is memoized so
# that subsequent calls to home_dir don't bounce around.
#
- # See self.all_homes.
+ # @see all_homes
+ # @param args [Array<String>] Path components to look for under the home directory.
+ # @return [String]
def self.home(*args)
@@home_dir ||= all_homes { |p| break p }
if @@home_dir
@@ -203,6 +217,8 @@ module ChefConfig
# if no block is provided.
def self.all_homes(*args)
paths = []
+ paths << ENV[@@per_tool_home_environment] if defined?(@@per_tool_home_environment) && @@per_tool_home_environment && ENV[@@per_tool_home_environment]
+ paths << ENV["CHEF_HOME"] if ENV["CHEF_HOME"]
if ChefConfig.windows?
# By default, Ruby uses the the following environment variables to determine Dir.home:
# HOME
diff --git a/chef-config/lib/chef-config/version.rb b/chef-config/lib/chef-config/version.rb
index 0f88a18675..3e55a244a6 100644
--- a/chef-config/lib/chef-config/version.rb
+++ b/chef-config/lib/chef-config/version.rb
@@ -21,7 +21,7 @@
module ChefConfig
CHEFCONFIG_ROOT = File.expand_path("../..", __FILE__)
- VERSION = "14.3.25"
+ VERSION = "14.3.29".freeze
end
#
diff --git a/chef-config/lib/chef-config/workstation_config_loader.rb b/chef-config/lib/chef-config/workstation_config_loader.rb
index 13187d9975..2afe8de547 100644
--- a/chef-config/lib/chef-config/workstation_config_loader.rb
+++ b/chef-config/lib/chef-config/workstation_config_loader.rb
@@ -83,6 +83,8 @@ module ChefConfig
end
load_dot_d(Config[:config_d_dir]) if Config[:config_d_dir]
+
+ apply_defaults
end
# (Private API, public for test purposes)
@@ -210,6 +212,54 @@ module ChefConfig
raise ChefConfig::ConfigurationError, message
end
+ # Apply default configuration values for workstation-style tools.
+ #
+ # Global defaults should go in {ChefConfig::Config} instead, this is only
+ # for things like `knife` and `chef`.
+ #
+ # @api private
+ # @since 14.3
+ # @return [void]
+ def apply_defaults
+ # If we don't have a better guess use the username.
+ Config[:node_name] ||= Etc.getlogin
+ # If we don't have a key (path or inline) check user.pem and $node_name.pem.
+ unless Config.has_key?(:client_key) || Config.has_key?(:client_key_contents)
+ Config[:client_key] = find_default_key(["#{Config[:node_name]}.pem", "user.pem"])
+ end
+ # Similarly look for a validation key file, though this should be less
+ # common these days.
+ unless Config.has_key?(:validation_key) || Config.has_key?(:validation_key_contents)
+ Config[:validation_key] = find_default_key(["#{Config[:validation_client_name]}.pem", "validator.pem", "validation.pem"])
+ end
+ end
+
+ # Look for a default key file.
+ #
+ # This searches for any of a list of possible default keys, checking both
+ # the local `.chef/` folder and the home directory `~/.chef/`. Returns `nil`
+ # if no matching file is found.
+ #
+ # @api private
+ # @since 14.3
+ # @param key_names [Array<String>] A list of possible filenames to check for.
+ # The first one found will be returned.
+ # @return [String, nil]
+ def find_default_key(key_names)
+ key_names.each do |filename|
+ path = Pathname.new(filename)
+ # If we have a config location (like ./.chef/), look there first.
+ if config_location
+ local_path = path.expand_path(File.dirname(config_location))
+ return local_path.to_s if local_path.exist?
+ end
+ # Then check ~/.chef.
+ home_path = path.expand_path(home_chef_dir)
+ return home_path.to_s if home_path.exist?
+ end
+ nil
+ end
+
def highlight_config_error(file, line)
config_file_lines = []
IO.readlines(file).each_with_index { |l, i| config_file_lines << "#{(i + 1).to_s.rjust(3)}: #{l.chomp}" }
diff --git a/chef-config/spec/unit/config_spec.rb b/chef-config/spec/unit/config_spec.rb
index 71ea158840..7e32a1e742 100644
--- a/chef-config/spec/unit/config_spec.rb
+++ b/chef-config/spec/unit/config_spec.rb
@@ -1191,4 +1191,22 @@ RSpec.describe ChefConfig::Config do
end
+ describe "validation_client_name" do
+ context "with a normal server URL" do
+ before { ChefConfig::Config[:chef_server_url] = "https://chef.example/organizations/myorg" }
+
+ it "sets the validation client to myorg-validator" do
+ expect(ChefConfig::Config[:validation_client_name]).to eq "myorg-validator"
+ end
+ end
+
+ context "with an unusual server URL" do
+ before { ChefConfig::Config[:chef_server_url] = "https://chef.example/myorg" }
+
+ it "sets the validation client to chef-validator" do
+ expect(ChefConfig::Config[:validation_client_name]).to eq "chef-validator"
+ end
+ end
+ end
+
end
diff --git a/chef-config/spec/unit/workstation_config_loader_spec.rb b/chef-config/spec/unit/workstation_config_loader_spec.rb
index 6cebe1e09c..28fbdf63dd 100644
--- a/chef-config/spec/unit/workstation_config_loader_spec.rb
+++ b/chef-config/spec/unit/workstation_config_loader_spec.rb
@@ -271,6 +271,70 @@ RSpec.describe ChefConfig::WorkstationConfigLoader do
config_loader.load
expect(ChefConfig::Config.config_file).to eq(explicit_config_location)
end
+
+ it "loads a default value for node_name" do
+ allow(Etc).to receive(:getlogin).and_return("notauser")
+ config_loader.load
+ expect(ChefConfig::Config.node_name).to eq("notauser")
+ end
+
+ context "with a user.pem" do
+ before do
+ allow(Etc).to receive(:getlogin).and_return("notauser")
+ allow(FileTest).to receive(:exist?).and_call_original
+ allow(FileTest).to receive(:exist?).with(File.expand_path("../notauser.pem", explicit_config_location)).and_return(false)
+ allow(FileTest).to receive(:exist?).with(File.expand_path("../user.pem", explicit_config_location)).and_return(true)
+ end
+
+ it "loads a default value for client_key" do
+ config_loader.load
+ expect(ChefConfig::Config.client_key).to eq(File.expand_path("../user.pem", explicit_config_location))
+ end
+ end
+
+ context "with a notauser.pem" do
+ before do
+ allow(Etc).to receive(:getlogin).and_return("notauser")
+ allow(FileTest).to receive(:exist?).and_call_original
+ allow(FileTest).to receive(:exist?).with(File.expand_path("../notauser.pem", explicit_config_location)).and_return(true)
+ allow(FileTest).to receive(:exist?).with(File.expand_path("../user.pem", explicit_config_location)).and_return(false)
+ end
+
+ it "loads a default value for client_key" do
+ config_loader.load
+ expect(ChefConfig::Config.client_key).to eq(File.expand_path("../notauser.pem", explicit_config_location))
+ end
+ end
+
+ context "with a valclient.pem" do
+ before do
+ ChefConfig::Config.validation_client_name = "valclient"
+ allow(FileTest).to receive(:exist?).and_call_original
+ allow(FileTest).to receive(:exist?).with(File.expand_path("../valclient.pem", explicit_config_location)).and_return(true)
+ allow(FileTest).to receive(:exist?).with(File.expand_path("../validator.pem", explicit_config_location)).and_return(false)
+ allow(FileTest).to receive(:exist?).with(File.expand_path("../validation.pem", explicit_config_location)).and_return(false)
+ end
+
+ it "loads a default value for validation_key" do
+ config_loader.load
+ expect(ChefConfig::Config.validation_key).to eq(File.expand_path("../valclient.pem", explicit_config_location))
+ end
+ end
+
+ context "with a validator.pem" do
+ before do
+ ChefConfig::Config.validation_client_name = "valclient"
+ allow(FileTest).to receive(:exist?).and_call_original
+ allow(FileTest).to receive(:exist?).with(File.expand_path("../valclient.pem", explicit_config_location)).and_return(false)
+ allow(FileTest).to receive(:exist?).with(File.expand_path("../validator.pem", explicit_config_location)).and_return(true)
+ allow(FileTest).to receive(:exist?).with(File.expand_path("../validation.pem", explicit_config_location)).and_return(false)
+ end
+
+ it "loads a default value for validation_key" do
+ config_loader.load
+ expect(ChefConfig::Config.validation_key).to eq(File.expand_path("../validator.pem", explicit_config_location))
+ end
+ end
end
context "and has a syntax error" do
diff --git a/ext/win32-eventlog/Rakefile b/ext/win32-eventlog/Rakefile
index 3bdf7f91d8..1b974670e5 100644
--- a/ext/win32-eventlog/Rakefile
+++ b/ext/win32-eventlog/Rakefile
@@ -12,13 +12,13 @@ def ensure_present(commands)
end
end
-EVT_MC_FILE = "chef-log.man"
-EVT_RC_FILE = "chef-log.rc"
-EVT_RESOURCE_OBJECT = "resource.o"
-EVT_SHARED_OBJECT = "chef-log.dll"
-MC = "windmc"
-RC = "windres"
-CC = "gcc"
+EVT_MC_FILE = "chef-log.man".freeze
+EVT_RC_FILE = "chef-log.rc".freeze
+EVT_RESOURCE_OBJECT = "resource.o".freeze
+EVT_SHARED_OBJECT = "chef-log.dll".freeze
+MC = "windmc".freeze
+RC = "windres".freeze
+CC = "gcc".freeze
ensure_present [MC, RC, CC]
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
diff --git a/spec/integration/knife/config_get_spec.rb b/spec/integration/knife/config_get_spec.rb
new file mode 100644
index 0000000000..f34d096051
--- /dev/null
+++ b/spec/integration/knife/config_get_spec.rb
@@ -0,0 +1,183 @@
+#
+# Copyright 2018, Noah Kantrowitz
+#
+# 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 "support/shared/integration/integration_helper"
+require "support/shared/context/config"
+
+describe "knife config get", :workstation do
+ include IntegrationSupport
+ include KnifeSupport
+
+ include_context "default config options"
+ include_context "with a chef repo"
+
+ let(:cmd_args) { [] }
+
+ subject do
+ cmd = knife("config", "get", *cmd_args, instance_filter: lambda { |instance|
+ # Clear the stub set up in KnifeSupport.
+ allow(File).to receive(:file?).and_call_original
+ # Lies, damn lies, and config files. We need to allow normal config loading
+ # behavior to be able to test stuff.
+ instance.config.delete(:config_file)
+ $__KNIFE_INTEGRATION_FAILSAFE_CHECK << " ole"
+ })
+ cmd.stdout
+ end
+
+ around do |ex|
+ # Store and reset the value of some env vars.
+ old_chef_home = ENV["CHEF_HOME"]
+ old_knife_home = ENV["KNIFE_HOME"]
+ old_home = ENV["HOME"]
+ old_wd = Dir.pwd
+ ChefConfig::PathHelper.per_tool_home_environment = "KNIFE_HOME"
+ # Clear these out because they are cached permanently.
+ ChefConfig::PathHelper.class_exec { remove_class_variable(:@@home_dir) }
+ Chef::Knife::ConfigGet.reset_config_loader!
+ begin
+ ex.run
+ ensure
+ ENV["CHEF_HOME"] = old_chef_home
+ ENV["KNIFE_HOME"] = old_knife_home
+ ENV["HOME"] = old_home
+ Dir.chdir(old_wd)
+ ENV[ChefConfig.windows? ? "CD" : "PWD"] = Dir.pwd
+ ChefConfig::PathHelper.per_tool_home_environment = nil
+ end
+ end
+
+ before do
+ # Always run from the temp folder. This can't be in the `around` block above
+ # because it has to run after the before set in the "with a chef repo" shared context.
+ directory("repo")
+ Dir.chdir(path_to("repo"))
+ ENV[ChefConfig.windows? ? "CD" : "PWD"] = Dir.pwd
+ ENV["HOME"] = path_to(".")
+ end
+
+ context "with a global knife.rb" do
+ before { file(".chef/knife.rb", "node_name 'one'\n") }
+
+ it { is_expected.to match(%r{^Loading from configuration file .*/#{File.basename(path_to("."))}/.chef/knife.rb$}) }
+ it { is_expected.to match(/^node_name:\s+one$/) }
+ end
+
+ context "with a repo knife.rb" do
+ before { file("repo/.chef/knife.rb", "node_name 'two'\n") }
+
+ it { is_expected.to match(%r{^Loading from configuration file .*/#{File.basename(path_to("."))}/repo/.chef/knife.rb$}) }
+ it { is_expected.to match(/^node_name:\s+two$/) }
+ end
+
+ context "with both knife.rb" do
+ before do
+ file(".chef/knife.rb", "node_name 'one'\n")
+ file("repo/.chef/knife.rb", "node_name 'two'\n")
+ end
+
+ it { is_expected.to match(%r{^Loading from configuration file .*/#{File.basename(path_to("."))}/repo/.chef/knife.rb$}) }
+ it { is_expected.to match(/^node_name:\s+two$/) }
+ end
+
+ context "with a credentials file" do
+ before { file(".chef/credentials", "[default]\nclient_name = \"three\"\n") }
+
+ it { is_expected.to match(%r{^Loading from credentials file .*/#{File.basename(path_to("."))}/.chef/credentials$}) }
+ it { is_expected.to match(/^node_name:\s+three$/) }
+ end
+
+ context "with a credentials file and knife.rb" do
+ before do
+ file(".chef/knife.rb", "node_name 'one'\n")
+ file(".chef/credentials", "[default]\nclient_name = \"three\"\n")
+ end
+
+ it { is_expected.to match(%r{^Loading from configuration file .*/#{File.basename(path_to("."))}/.chef/knife.rb$}) }
+ it { is_expected.to match(%r{^Loading from credentials file .*/#{File.basename(path_to("."))}/.chef/credentials$}) }
+ it { is_expected.to match(/^node_name:\s+one$/) }
+ end
+
+ context "with a credentials file and CHEF_HOME" do
+ before do
+ file(".chef/credentials", "[default]\nclient_name = \"three\"\n")
+ file("foo/.chef/credentials", "[default]\nclient_name = \"four\"\n")
+ ENV["CHEF_HOME"] = path_to("foo")
+ end
+
+ it { is_expected.to match(%r{^Loading from credentials file .*/#{File.basename(path_to("."))}/foo/.chef/credentials$}) }
+ it { is_expected.to match(/^node_name:\s+four$/) }
+ end
+
+ context "with a credentials file and KNIFE_HOME" do
+ before do
+ file(".chef/credentials", "[default]\nclient_name = \"three\"\n")
+ file("bar/.chef/credentials", "[default]\nclient_name = \"four\"\n")
+ ENV["KNIFE_HOME"] = path_to("bar")
+ end
+
+ it { is_expected.to match(%r{^Loading from credentials file .*/#{File.basename(path_to("."))}/bar/.chef/credentials$}) }
+ it { is_expected.to match(/^node_name:\s+four$/) }
+ end
+
+ context "with single argument" do
+ let(:cmd_args) { %w{node_name} }
+ before { file(".chef/credentials", "[default]\nclient_name = \"three\"\n") }
+
+ it { is_expected.to match(/^node_name:\s+three\Z/) }
+ end
+
+ context "with two arguments" do
+ let(:cmd_args) { %w{node_name client_key} }
+ before { file(".chef/credentials", "[default]\nclient_name = \"three\"\nclient_key = \"three.pem\"") }
+
+ it { is_expected.to match(/^client_key:\s+\S*\/.chef\/three.pem\nnode_name:\s+three\Z/) }
+ end
+
+ context "with a dotted argument" do
+ let(:cmd_args) { %w{knife.ssh_user} }
+ before { file(".chef/credentials", "[default]\nclient_name = \"three\"\n[default.knife]\nssh_user = \"foo\"\n") }
+
+ it { is_expected.to match(/^knife.ssh_user:\s+foo\Z/) }
+ end
+
+ context "with regex argument" do
+ let(:cmd_args) { %w{/name/} }
+ before { file(".chef/credentials", "[default]\nclient_name = \"three\"\n") }
+
+ it { is_expected.to match(/^node_name:\s+three\Z/) }
+ end
+
+ context "with --all" do
+ let(:cmd_args) { %w{-a /key_contents/} }
+ before { file(".chef/credentials", "[default]\nclient_name = \"three\"\n") }
+
+ it { is_expected.to match(/^client_key_contents:\s+\nvalidation_key_contents:\s+\Z/) }
+ end
+
+ context "with --raw" do
+ let(:cmd_args) { %w{-r node_name} }
+ before { file(".chef/credentials", "[default]\nclient_name = \"three\"\n") }
+
+ it { is_expected.to eq("three\n") }
+ end
+
+ context "with --format=json" do
+ let(:cmd_args) { %w{--format=json node_name} }
+ before { file(".chef/credentials", "[default]\nclient_name = \"three\"\n") }
+
+ it { expect(JSON.parse(subject)).to eq({ "node_name" => "three" }) }
+ end
+end
diff --git a/spec/scripts/ssl-serve.rb b/spec/scripts/ssl-serve.rb
index 5677e94d0a..66e400b6d0 100644
--- a/spec/scripts/ssl-serve.rb
+++ b/spec/scripts/ssl-serve.rb
@@ -36,7 +36,7 @@ DEFAULT_OPTIONS = {
Logger: LOGGER,
DocumentRoot: File.expand_path("#{Dir.tmpdir}/chef-118-sampledata")
#:AccessLog => [] # Remove this option to enable the access log when debugging.
-}
+}.freeze
webrick_opts = DEFAULT_OPTIONS.merge(server_opts)
pp webrick_opts: webrick_opts
diff --git a/spec/support/shared/functional/securable_resource_with_reporting.rb b/spec/support/shared/functional/securable_resource_with_reporting.rb
index cd2b83fda1..abeb1ba4bb 100644
--- a/spec/support/shared/functional/securable_resource_with_reporting.rb
+++ b/spec/support/shared/functional/securable_resource_with_reporting.rb
@@ -19,7 +19,7 @@ ALL_EXPANDED_PERMISSIONS = ["generic read",
"execute / traverse",
"delete child",
"read attributes",
- "write attributes"]
+ "write attributes"].freeze
shared_examples_for "a securable resource with reporting" do
diff --git a/spec/support/shared/integration/knife_support.rb b/spec/support/shared/integration/knife_support.rb
index 5058b7b278..87ce1bc0b0 100644
--- a/spec/support/shared/integration/knife_support.rb
+++ b/spec/support/shared/integration/knife_support.rb
@@ -24,7 +24,7 @@ require "chef/chef_fs/file_system_cache"
module KnifeSupport
DEBUG = ENV["DEBUG"]
- def knife(*args, input: nil)
+ def knife(*args, input: nil, instance_filter: nil)
# Allow knife('role from file roles/blah.json') rather than requiring the
# arguments to be split like knife('role', 'from', 'file', 'roles/blah.json')
# If any argument will have actual spaces in it, the long form is required.
@@ -88,9 +88,15 @@ module KnifeSupport
allow(File).to receive(:file?).and_call_original
allow(File).to receive(:file?).with(File.expand_path("~/.chef/credentials")).and_return(false)
+ # Set a canary that is modified by the default null_config.rb config file.
$__KNIFE_INTEGRATION_FAILSAFE_CHECK = "ole"
+
+ # Allow tweaking the knife instance before configuration.
+ instance_filter.call(instance) if instance_filter
+
instance.configure_chef
+ # The canary is incorrect, meaning the normal null_config.rb didn't run. Something is wrong.
unless $__KNIFE_INTEGRATION_FAILSAFE_CHECK == "ole ole"
raise Exception, "Potential misconfiguration of integration tests detected. Aborting test."
end
diff --git a/spec/tiny_server.rb b/spec/tiny_server.rb
index c3eab76d8e..4a6bdfb599 100644
--- a/spec/tiny_server.rb
+++ b/spec/tiny_server.rb
@@ -38,7 +38,7 @@ module TinyServer
# SSLEnable: options[:ssl],
# SSLCertName: [ [ 'CN', WEBrick::Utils::getservername ] ],
AccessLog: [], # Remove this option to enable the access log when debugging.
- }
+ }.freeze
def initialize(**options)
@options = DEFAULT_OPTIONS.merge(options)
@@ -101,10 +101,10 @@ module TinyServer
class API
include Singleton
- GET = "GET"
- PUT = "PUT"
- POST = "POST"
- DELETE = "DELETE"
+ GET = "GET".freeze
+ PUT = "PUT".freeze
+ POST = "POST".freeze
+ DELETE = "DELETE".freeze
attr_reader :routes
@@ -170,7 +170,7 @@ module TinyServer
end
class Response
- HEADERS = { "Content-Type" => "application/json" }
+ HEADERS = { "Content-Type" => "application/json" }.freeze
def initialize(response_code = 200, data = nil, headers = nil, &block)
@response_code, @data = response_code, data
diff --git a/spec/unit/application/solo_spec.rb b/spec/unit/application/solo_spec.rb
index 31114261c8..3f7c203c67 100644
--- a/spec/unit/application/solo_spec.rb
+++ b/spec/unit/application/solo_spec.rb
@@ -208,7 +208,7 @@ Enable chef-client interval runs by setting `:client_fork = true` in your config
it "sets the repo path" do
expect(Chef::Config).to receive(:find_chef_repo_path).and_return("/var/chef")
app.reconfigure
- expect(Chef::Config.has_key?(:chef_repo_path)).to be_truthy
+ expect(Chef::Config.key?(:chef_repo_path)).to be_truthy
expect(Chef::Config[:chef_repo_path]).to eq ("/var/chef")
end
diff --git a/spec/unit/audit/audit_reporter_spec.rb b/spec/unit/audit/audit_reporter_spec.rb
index 4c13eca390..db065db923 100644
--- a/spec/unit/audit/audit_reporter_spec.rb
+++ b/spec/unit/audit/audit_reporter_spec.rb
@@ -359,22 +359,18 @@ EOM
end
it "stores the control group" do
- expect(ordered_control_groups).to receive(:has_key?).with(name).and_return(false)
+ expect(ordered_control_groups).to receive(:key?).with(name).and_return(false)
allow(run_context.audits).to receive(:[]).with(name).and_return(control_group)
expect(ordered_control_groups).to receive(:store)
.with(name, control_group)
.and_call_original
reporter.control_group_started(name)
- # stubbed :has_key? above, which is used by the have_key matcher,
- # so instead we check the response to Hash's #key? because luckily
- # #key? does not call #has_key?
- expect(ordered_control_groups.key?(name)).to be true
expect(ordered_control_groups[name]).to eq control_group
end
context "when a control group with the same name has been seen" do
it "raises an exception" do
- expect(ordered_control_groups).to receive(:has_key?).with(name).and_return(true)
+ expect(ordered_control_groups).to receive(:key?).with(name).and_return(true)
expect { reporter.control_group_started(name) }.to raise_error(Chef::Exceptions::AuditControlGroupDuplicate)
end
end
diff --git a/spec/unit/chef_fs/file_system/repository/directory_spec.rb b/spec/unit/chef_fs/file_system/repository/directory_spec.rb
index efd17204e0..5b2a0a47b8 100644
--- a/spec/unit/chef_fs/file_system/repository/directory_spec.rb
+++ b/spec/unit/chef_fs/file_system/repository/directory_spec.rb
@@ -22,7 +22,7 @@ require "chef/chef_fs/file_system/base_fs_object"
require "chef/chef_fs/file_system/exceptions"
require "chef/chef_fs/file_system/nonexistent_fs_object"
-CHILD_FILES = %w{ test1.json test2.json skip test3.json skip2 test4 }
+CHILD_FILES = %w{ test1.json test2.json skip test3.json skip2 test4 }.freeze
class TestDirectory < Chef::ChefFS::FileSystem::Repository::Directory
def make_child_entry(name)
diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb
index 4da1c57964..0f85d82734 100644
--- a/spec/unit/cookbook/metadata_spec.rb
+++ b/spec/unit/cookbook/metadata_spec.rb
@@ -724,8 +724,8 @@ describe Chef::Cookbook::Metadata do
end
it "should automatically provide each recipe" do
- expect(metadata.providing.has_key?("test_cookbook")).to eq(true)
- expect(metadata.providing.has_key?("test_cookbook::enlighten")).to eq(true)
+ expect(metadata.providing.key?("test_cookbook")).to eq(true)
+ expect(metadata.providing.key?("test_cookbook::enlighten")).to eq(true)
end
end
diff --git a/spec/unit/cookbook/synchronizer_spec.rb b/spec/unit/cookbook/synchronizer_spec.rb
index dce2383a16..8421b1ffd1 100644
--- a/spec/unit/cookbook/synchronizer_spec.rb
+++ b/spec/unit/cookbook/synchronizer_spec.rb
@@ -218,10 +218,10 @@ describe Chef::CookbookSynchronizer do
def setup_common_files_missing_expectations
# Files are not in the cache:
- expect(file_cache).to receive(:has_key?)
+ expect(file_cache).to receive(:key?)
.with("cookbooks/cookbook_a/recipes/default.rb")
.and_return(false)
- expect(file_cache).to receive(:has_key?)
+ expect(file_cache).to receive(:key?)
.with("cookbooks/cookbook_a/attributes/default.rb")
.and_return(false)
@@ -247,10 +247,10 @@ describe Chef::CookbookSynchronizer do
end
def setup_no_lazy_files_and_templates_missing_expectations
- expect(file_cache).to receive(:has_key?)
+ expect(file_cache).to receive(:key?)
.with("cookbooks/cookbook_a/files/default/megaman.conf")
.and_return(false)
- expect(file_cache).to receive(:has_key?)
+ expect(file_cache).to receive(:key?)
.with("cookbooks/cookbook_a/templates/default/apache2.conf.erb")
.and_return(false)
@@ -275,10 +275,10 @@ describe Chef::CookbookSynchronizer do
def setup_common_files_chksum_mismatch_expectations
# Files are in the cache:
- expect(file_cache).to receive(:has_key?)
+ expect(file_cache).to receive(:key?)
.with("cookbooks/cookbook_a/recipes/default.rb")
.and_return(true)
- expect(file_cache).to receive(:has_key?)
+ expect(file_cache).to receive(:key?)
.with("cookbooks/cookbook_a/attributes/default.rb")
.and_return(true)
@@ -317,10 +317,10 @@ describe Chef::CookbookSynchronizer do
def setup_no_lazy_files_and_templates_chksum_mismatch_expectations
# Files are in the cache:
- expect(file_cache).to receive(:has_key?)
+ expect(file_cache).to receive(:key?)
.with("cookbooks/cookbook_a/files/default/megaman.conf")
.and_return(true)
- expect(file_cache).to receive(:has_key?)
+ expect(file_cache).to receive(:key?)
.with("cookbooks/cookbook_a/templates/default/apache2.conf.erb")
.and_return(true)
@@ -359,10 +359,10 @@ describe Chef::CookbookSynchronizer do
def setup_common_files_present_expectations
# Files are in the cache:
- expect(file_cache).to receive(:has_key?)
+ expect(file_cache).to receive(:key?)
.with("cookbooks/cookbook_a/recipes/default.rb")
.and_return(true)
- expect(file_cache).to receive(:has_key?)
+ expect(file_cache).to receive(:key?)
.with("cookbooks/cookbook_a/attributes/default.rb")
.and_return(true)
@@ -389,10 +389,10 @@ describe Chef::CookbookSynchronizer do
def setup_no_lazy_files_and_templates_present_expectations
# Files are in the cache:
- expect(file_cache).to receive(:has_key?)
+ expect(file_cache).to receive(:key?)
.with("cookbooks/cookbook_a/files/default/megaman.conf")
.and_return(true)
- expect(file_cache).to receive(:has_key?)
+ expect(file_cache).to receive(:key?)
.with("cookbooks/cookbook_a/templates/default/apache2.conf.erb")
.and_return(true)
diff --git a/spec/unit/data_bag_item_spec.rb b/spec/unit/data_bag_item_spec.rb
index a32ba147f8..3ebbf5c9a0 100644
--- a/spec/unit/data_bag_item_spec.rb
+++ b/spec/unit/data_bag_item_spec.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");
diff --git a/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb b/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb
index a09b192b6d..209d987e78 100644
--- a/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb
+++ b/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb
@@ -18,7 +18,7 @@
require "spec_helper"
-BAD_RECIPE = <<~E
+BAD_RECIPE = <<~E.freeze
#
# Cookbook Name:: syntax-err
# Recipe:: default
diff --git a/spec/unit/mixin/shell_out_spec.rb b/spec/unit/mixin/shell_out_spec.rb
index 6b0cd659ef..7f6021d911 100644
--- a/spec/unit/mixin/shell_out_spec.rb
+++ b/spec/unit/mixin/shell_out_spec.rb
@@ -97,7 +97,7 @@ describe Chef::Mixin::ShellOut do
},
}).and_return(retobj)
shell_out_obj.send(method, cmd, options)
- expect(options[:environment].has_key?("LC_ALL")).to be false
+ expect(options[:environment].key?("LC_ALL")).to be false
end
end
@@ -140,7 +140,7 @@ describe Chef::Mixin::ShellOut do
},
}).and_return(retobj)
shell_out_obj.send(method, cmd, options)
- expect(options[:env].has_key?("LC_ALL")).to be false
+ expect(options[:env].key?("LC_ALL")).to be false
end
end
diff --git a/spec/unit/node/attribute_spec.rb b/spec/unit/node/attribute_spec.rb
index 618a9bbe0e..36827215f0 100644
--- a/spec/unit/node/attribute_spec.rb
+++ b/spec/unit/node/attribute_spec.rb
@@ -522,20 +522,20 @@ describe Chef::Node::Attribute do
describe "has_key?" do
it "should return true if an attribute exists" do
- expect(@attributes.has_key?("music")).to eq(true)
+ expect(@attributes.key?("music")).to eq(true)
end
it "should return false if an attribute does not exist" do
- expect(@attributes.has_key?("ninja")).to eq(false)
+ expect(@attributes.key?("ninja")).to eq(false)
end
it "should return false if an attribute does not exist using dot notation" do
- expect(@attributes.has_key?("does_not_exist_at_all")).to eq(false)
+ expect(@attributes.key?("does_not_exist_at_all")).to eq(false)
end
it "should return true if an attribute exists but is set to false" do
- @attributes.has_key?("music")
- expect(@attributes["music"].has_key?("apophis")).to eq(true)
+ @attributes.key?("music")
+ expect(@attributes["music"].key?("apophis")).to eq(true)
end
it "does not find keys above the current nesting level" do
@@ -886,11 +886,11 @@ describe Chef::Node::Attribute do
end
it "should return true if any key has the value supplied" do
- expect(@attributes.has_value?("cookies")).to eq(true)
+ expect(@attributes.value?("cookies")).to eq(true)
end
it "should return false no key has the value supplied" do
- expect(@attributes.has_value?("lololol")).to eq(false)
+ expect(@attributes.value?("lololol")).to eq(false)
end
it "should alias value?" do
diff --git a/spec/unit/provider/apt_repository_spec.rb b/spec/unit/provider/apt_repository_spec.rb
index 8ea2b9b823..79b871eb6c 100644
--- a/spec/unit/provider/apt_repository_spec.rb
+++ b/spec/unit/provider/apt_repository_spec.rb
@@ -23,7 +23,7 @@ require "spec_helper"
#
# Output of the command:
# => apt-key adv --list-public-keys --with-fingerprint --with-colons
-APT_KEY_FINGER = <<~EOF
+APT_KEY_FINGER = <<~EOF.freeze
tru:t:1:1488924856:0:3:1:5
pub:-:1024:17:40976EAF437D05B5:2004-09-12:::-:Ubuntu Archive Automatic Signing Key <ftpmaster@ubuntu.com>::scESC:
fpr:::::::::630239CC130E1A7FD81A27B140976EAF437D05B5:
@@ -38,7 +38,7 @@ EOF
# Output of the command:
# => gpg --with-fingerprint --with-colons [FILE]
-GPG_FINGER = <<~EOF
+GPG_FINGER = <<~EOF.freeze
pub:-:1024:17:327574EE02A818DD:2009-04-22:::-:Cloudera Apt Repository:
fpr:::::::::F36A89E33CC1BD0F71079007327574EE02A818DD:
sub:-:2048:16:84080586D1CA74A1:2009-04-22::::
diff --git a/spec/unit/provider/group/dscl_spec.rb b/spec/unit/provider/group/dscl_spec.rb
index 4d18a8c2b0..8bd6485740 100644
--- a/spec/unit/provider/group/dscl_spec.rb
+++ b/spec/unit/provider/group/dscl_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Dreamcat4 (<dreamcat4@gmail.com>)
-# Copyright:: Copyright 2009-2016, Chef Software Inc.
+# Copyright:: Copyright 2009-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -116,11 +116,11 @@ describe Chef::Provider::Group::Dscl do
describe "gid_used?" do
before do
- allow(@provider).to receive(:safe_dscl).and_return(<<-eos
+ allow(@provider).to receive(:safe_dscl).and_return(<<-EOS
someprogram somethingElse:gid = (
500
)
- eos
+ EOS
)
end
diff --git a/spec/unit/provider/mount/windows_spec.rb b/spec/unit/provider/mount/windows_spec.rb
index 6d55fb958c..aeff294347 100644
--- a/spec/unit/provider/mount/windows_spec.rb
+++ b/spec/unit/provider/mount/windows_spec.rb
@@ -29,8 +29,8 @@ class Chef
end
end
-GUID = "\\\\?\\Volume{578e72b5-6e70-11df-b5c5-000c29d4a7d9}\\"
-REMOTE = "\\\\server-name\\path"
+GUID = "\\\\?\\Volume{578e72b5-6e70-11df-b5c5-000c29d4a7d9}\\".freeze
+REMOTE = "\\\\server-name\\path".freeze
describe Chef::Provider::Mount::Windows do
before(:each) do
diff --git a/spec/unit/provider/remote_file/cache_control_data_spec.rb b/spec/unit/provider/remote_file/cache_control_data_spec.rb
index a80aa38e77..5e661ba3d7 100644
--- a/spec/unit/provider/remote_file/cache_control_data_spec.rb
+++ b/spec/unit/provider/remote_file/cache_control_data_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Daniel DeLeo (<dan@chef.io>)
-# Copyright:: Copyright 2013-2016, Chef Software Inc.
+# Copyright:: Copyright 2013-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -45,8 +45,8 @@ describe Chef::Provider::RemoteFile::CacheControlData do
context "when loading data for an unknown URI" do
before do
- expect(Chef::FileCache).to receive(:has_key?).with(cache_path).and_return(false)
- expect(Chef::FileCache).to receive(:has_key?).with(old_cache_path).and_return(false)
+ expect(Chef::FileCache).to receive(:key?).with(cache_path).and_return(false)
+ expect(Chef::FileCache).to receive(:key?).with(old_cache_path).and_return(false)
end
context "and there is no current copy of the file" do
@@ -93,7 +93,7 @@ describe Chef::Provider::RemoteFile::CacheControlData do
context "when the cache control data uses sha256 for its name" do
before do
- expect(Chef::FileCache).to receive(:has_key?).with(cache_path).and_return(true)
+ expect(Chef::FileCache).to receive(:key?).with(cache_path).and_return(true)
expect(Chef::FileCache).to receive(:load).with(cache_path).and_return(cache_json_data)
end
@@ -118,7 +118,7 @@ describe Chef::Provider::RemoteFile::CacheControlData do
context "and the cached checksum matches the on-disk copy" do
context "when the filename uses sha256" do
before do
- expect(Chef::FileCache).not_to receive(:has_key?).with(old_cache_path)
+ expect(Chef::FileCache).not_to receive(:key?).with(old_cache_path)
end
it "populates the cache control data" do
expect(cache_control_data.etag).to eq(etag)
@@ -148,8 +148,8 @@ describe Chef::Provider::RemoteFile::CacheControlData do
context "when the filename uses md5" do
before do
- expect(Chef::FileCache).to receive(:has_key?).with(cache_path).and_return(false)
- expect(Chef::FileCache).to receive(:has_key?).with(old_cache_path).and_return(true)
+ expect(Chef::FileCache).to receive(:key?).with(cache_path).and_return(false)
+ expect(Chef::FileCache).to receive(:key?).with(old_cache_path).and_return(true)
expect(Chef::FileCache).to receive(:load).with(old_cache_path).and_return(cache_json_data)
end
diff --git a/spec/unit/provider/zypper_repository_spec.rb b/spec/unit/provider/zypper_repository_spec.rb
index fc8ff14afb..df45c742d4 100644
--- a/spec/unit/provider/zypper_repository_spec.rb
+++ b/spec/unit/provider/zypper_repository_spec.rb
@@ -20,14 +20,14 @@ require "spec_helper"
# Output of the command:
# => rpm -qa gpg-pubkey*
-RPM_KEYS = <<~EOF
+RPM_KEYS = <<~EOF.freeze
gpg-pubkey-307e3d54-4be01a65
gpg-pubkey-3dbdc284-53674dd4
EOF
# Output of the command:
# => gpg --with-fingerprint [FILE]
-GPG_FINGER = <<~EOF
+GPG_FINGER = <<~EOF.freeze
pub 2048R/3DBDC284 2011-08-19 [expires: 2024-06-14]
Key fingerprint = 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62
uid nginx signing key <signing-key@nginx.com>
diff --git a/spec/unit/provider_resolver_spec.rb b/spec/unit/provider_resolver_spec.rb
index cb03141c76..a3f2801adf 100644
--- a/spec/unit/provider_resolver_spec.rb
+++ b/spec/unit/provider_resolver_spec.rb
@@ -887,7 +887,7 @@ describe Chef::ProviderResolver do
},
},
},
- }
+ }.freeze
def self.create_provider_tests(providers, test, expected, filter)
expected = expected.merge(providers.select { |key, value| key.is_a?(Symbol) })
diff --git a/spec/unit/role_spec.rb b/spec/unit/role_spec.rb
index 8e73ad347d..57f1d5c6ba 100644
--- a/spec/unit/role_spec.rb
+++ b/spec/unit/role_spec.rb
@@ -245,7 +245,7 @@ describe Chef::Role do
end
end
- ROLE_DSL = <<~EOR
+ ROLE_DSL = <<~EOR.freeze
name "ceiling_cat"
description "like Aliens, but furry"
EOR
diff --git a/tasks/cbgb.rb b/tasks/cbgb.rb
index 801739a6af..9621f160c3 100644
--- a/tasks/cbgb.rb
+++ b/tasks/cbgb.rb
@@ -68,12 +68,12 @@ begin
end
def person(list, person)
- if list[person].has_key?("GitHub")
+ if list[person].key?("GitHub")
out = "* [#{list[person]["Name"]}](https://github.com/#{list[person]["GitHub"]})"
else
out = "* #{list[person]["Name"]}"
end
- if list[person].has_key?("Person")
+ if list[person].key?("Person")
out << " - #{list[person]["Person"]}"
end
out
diff --git a/tasks/maintainers.rb b/tasks/maintainers.rb
index 1adac47ecc..7465f7ba9e 100644
--- a/tasks/maintainers.rb
+++ b/tasks/maintainers.rb
@@ -25,7 +25,7 @@ REPOSITORIES = ["chef/chef", "chef/chef-dk", "chef/chef-census", "chef/chef-repo
"chef/client-docs", "chef/ffi-yajl", "chef/libyajl2-gem",
"chef/mixlib-authentication", "chef/mixlib-cli",
"chef/mixlib-config", "chef/mixlib-install", "chef/mixlib-log",
- "chef/mixlib-shellout", "chef/ohai", "chef/omnibus-chef"]
+ "chef/mixlib-shellout", "chef/ohai", "chef/omnibus-chef"].freeze
begin
require "tomlrb"
@@ -181,13 +181,13 @@ begin
def format_components(cmp)
out = "## " + cmp.delete("title") + "\n\n"
- out << cmp.delete("text") + "\n" if cmp.has_key?("text")
- out << "To mention the team, use @chef/#{cmp.delete("team")}\n\n" if cmp.has_key?("team")
- if cmp.has_key?("lieutenant")
+ out << cmp.delete("text") + "\n" if cmp.key?("text")
+ out << "To mention the team, use @chef/#{cmp.delete("team")}\n\n" if cmp.key?("team")
+ if cmp.key?("lieutenant")
out << "### Lieutenant\n\n"
out << format_person(cmp.delete("lieutenant")) + "\n\n"
end
- out << format_maintainers(cmp.delete("maintainers")) + "\n" if cmp.has_key?("maintainers")
+ out << format_maintainers(cmp.delete("maintainers")) + "\n" if cmp.key?("maintainers")
cmp.delete("paths")
cmp.each_value { |v| out << format_components(v) }
out