diff options
-rw-r--r-- | CHANGELOG.md | 7 | ||||
-rw-r--r-- | Gemfile.lock | 14 | ||||
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | chef-bin/lib/chef-bin/version.rb | 2 | ||||
-rw-r--r-- | chef-config/lib/chef-config/version.rb | 2 | ||||
-rw-r--r-- | lib/chef/train_transport.rb | 24 | ||||
-rw-r--r-- | lib/chef/version.rb | 2 | ||||
-rw-r--r-- | spec/unit/train_transport_spec.rb | 23 |
8 files changed, 39 insertions, 37 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 2481c38511..679e829912 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,16 @@ <!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ --> -<!-- latest_release 15.0.303 --> -## [v15.0.303](https://github.com/chef/chef/tree/v15.0.303) (2019-05-21) +<!-- latest_release 15.0.304 --> +## [v15.0.304](https://github.com/chef/chef/tree/v15.0.304) (2019-05-21) #### Merged Pull Requests -- Fix chef-config requires lines [#8545](https://github.com/chef/chef/pull/8545) ([lamont-granquist](https://github.com/lamont-granquist)) +- Better target mode no-creds errors [#8571](https://github.com/chef/chef/pull/8571) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- latest_release --> <!-- release_rollup since=15.0.300 --> ### Changes not yet released to rubygems.org #### Merged Pull Requests +- Better target mode no-creds errors [#8571](https://github.com/chef/chef/pull/8571) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 15.0.304 --> - Fix chef-config requires lines [#8545](https://github.com/chef/chef/pull/8545) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 15.0.303 --> - Only set client_pem in bootstrap_context when validatorless [#8567](https://github.com/chef/chef/pull/8567) ([btm](https://github.com/btm)) <!-- 15.0.302 --> - Chef Infra Client 15 Release Notes Additional edits [#8543](https://github.com/chef/chef/pull/8543) ([mjingle](https://github.com/mjingle)) <!-- 15.0.301 --> diff --git a/Gemfile.lock b/Gemfile.lock index 9fdf729ea7..7f8672229a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -27,11 +27,11 @@ GIT PATH remote: . specs: - chef (15.0.303) + chef (15.0.304) addressable bcrypt_pbkdf (~> 1.0) bundler (>= 1.10) - chef-config (= 15.0.303) + chef-config (= 15.0.304) chef-zero (>= 14.0.11) diff-lcs (~> 1.2, >= 1.2.4) ed25519 (~> 1.2) @@ -57,11 +57,11 @@ PATH train-core (~> 2.0, >= 2.0.12) tty-screen (~> 0.6) uuidtools (~> 2.1.5) - chef (15.0.303-universal-mingw32) + chef (15.0.304-universal-mingw32) addressable bcrypt_pbkdf (~> 1.0) bundler (>= 1.10) - chef-config (= 15.0.303) + chef-config (= 15.0.304) chef-zero (>= 14.0.11) diff-lcs (~> 1.2, >= 1.2.4) ed25519 (~> 1.2) @@ -103,13 +103,13 @@ PATH PATH remote: chef-bin specs: - chef-bin (15.0.303) - chef (= 15.0.303) + chef-bin (15.0.304) + chef (= 15.0.304) PATH remote: chef-config specs: - chef-config (15.0.303) + chef-config (15.0.304) addressable fuzzyurl mixlib-config (>= 2.2.12, < 4.0) @@ -1 +1 @@ -15.0.303
\ No newline at end of file +15.0.304
\ No newline at end of file diff --git a/chef-bin/lib/chef-bin/version.rb b/chef-bin/lib/chef-bin/version.rb index 17e52667e9..bedd8f373b 100644 --- a/chef-bin/lib/chef-bin/version.rb +++ b/chef-bin/lib/chef-bin/version.rb @@ -21,7 +21,7 @@ module ChefBin CHEFBIN_ROOT = File.expand_path("../..", __FILE__) - VERSION = "15.0.303".freeze + VERSION = "15.0.304".freeze end # diff --git a/chef-config/lib/chef-config/version.rb b/chef-config/lib/chef-config/version.rb index e9475811a2..81a83bc5fb 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 = "15.0.303".freeze + VERSION = "15.0.304".freeze end # diff --git a/lib/chef/train_transport.rb b/lib/chef/train_transport.rb index 9db5f8fbf3..95b5018960 100644 --- a/lib/chef/train_transport.rb +++ b/lib/chef/train_transport.rb @@ -20,12 +20,12 @@ require "train" class Chef class TrainTransport + extend ChefConfig::Mixin::Credentials + # # Returns a RFC099 credentials profile as a hash # def self.load_credentials(profile) - extend ChefConfig::Mixin::Credentials - # Tomlrb.load_file returns a hash with keys as strings credentials = parse_credentials_file if contains_split_fqdn?(credentials, profile) @@ -74,22 +74,18 @@ class Chef profile = tm_config.host credentials_file = - if tm_config.credentials_file - if File.exists?(tm_config.credentials_file) - tm_config.credentials_file - else - raise ArgumentError, "Credentials file specified for target mode does not exist: '#{tm_config.credentials_file}'" - end - elsif File.exists?(Chef::Config.platform_specific_path("/etc/chef/#{profile}/credentials")) + if tm_config.credentials_file && File.exist?(tm_config.credentials_file) + tm_config.credentials_file + elsif File.exist?(Chef::Config.platform_specific_path("/etc/chef/#{profile}/credentials")) Chef::Config.platform_specific_path("/etc/chef/#{profile}/credentials") else super end - if credentials_file - Chef::Log.debug("Loading credentials file '#{credentials_file}' for target '#{profile}'") - else - Chef::Log.debug("No credentials file found for target '#{profile}'") - end + + raise ArgumentError, "No credentials file found for target '#{profile}'" unless credentials_file + raise ArgumentError, "Credentials file specified for target mode does not exist: '#{credentials_file}'" unless File.exist?(credentials_file) + + Chef::Log.debug("Loading credentials file '#{credentials_file}' for target '#{profile}'") credentials_file end diff --git a/lib/chef/version.rb b/lib/chef/version.rb index ccfdfea916..9ab27b727b 100644 --- a/lib/chef/version.rb +++ b/lib/chef/version.rb @@ -23,7 +23,7 @@ require_relative "version_string" class Chef CHEF_ROOT = File.expand_path("../..", __FILE__) - VERSION = Chef::VersionString.new("15.0.303") + VERSION = Chef::VersionString.new("15.0.304") end # diff --git a/spec/unit/train_transport_spec.rb b/spec/unit/train_transport_spec.rb index b56c7e1104..1d29c59da0 100644 --- a/spec/unit/train_transport_spec.rb +++ b/spec/unit/train_transport_spec.rb @@ -40,6 +40,7 @@ describe Chef::TrainTransport do # [foo.example.org] => {"foo"=>{"example"=>{"org"=>{}}}} # ['foo.example.org'] => {"foo.example.org"=>{}} it "warns if the host has been split by toml" do + allow(Chef::TrainTransport).to receive(:credentials_file_path).and_return("/Users/scotthourglass/.chef/credentials") allow(Chef::TrainTransport).to receive(:parse_credentials_file).and_return({ "foo" => { "example" => { "org" => {} } } }) expect(Chef::Log).to receive(:warn).with(/as a Hash/) expect(Chef::Log).to receive(:warn).with(/Hostnames must be surrounded by single quotes/) @@ -48,32 +49,36 @@ describe Chef::TrainTransport do end describe "credentials_file_path" do + let(:config_cred_file_path) { "/somewhere/credentials" } + let(:host_cred_file_path) { Chef::Platform.windows? ? "C:\\chef\\foo.example.org\\credentials" : "/etc/chef/foo.example.org/credentials" } context "when a file path is specified by a config" do - let(:cred_file_path) { "/somewhere/credentials" } - before do - tm_config = double("Config Context", host: "foo.example.org", credentials_file: cred_file_path) + tm_config = double("Config Context", host: "foo.example.org", credentials_file: config_cred_file_path) allow(Chef::Config).to receive(:target_mode).and_return(tm_config) end it "returns the path if it exists" do - allow(File).to receive(:exists?).with(cred_file_path).and_return(true) - expect(Chef::TrainTransport.credentials_file_path).to eq(cred_file_path) + allow(File).to receive(:exist?).with(config_cred_file_path).and_return(true) + expect(Chef::TrainTransport.credentials_file_path).to eq(config_cred_file_path) end it "raises an error if it does not exist" do - allow(File).to receive(:exists?).with(cred_file_path).and_return(false) + allow(File).to receive(:exist?).and_return(false) expect { Chef::TrainTransport.credentials_file_path }.to raise_error(ArgumentError, /does not exist/) end end + it "raises an error if the default creds files do not exist" do + allow(File).to receive(:exist?).and_return(false) + expect { Chef::TrainTransport.credentials_file_path }.to raise_error(ArgumentError, /does not exist/) + end + it "returns the path to the default config file if it exists" do - cred_file_path = Chef::Config.platform_specific_path("/etc/chef/foo.example.org/credentials") tm_config = double("Config Context", host: "foo.example.org", credentials_file: nil) allow(Chef::Config).to receive(:target_mode).and_return(tm_config) - allow(File).to receive(:exists?).with(cred_file_path).and_return(true) - expect(Chef::TrainTransport.credentials_file_path).to eq(cred_file_path) + allow(File).to receive(:exist?).with(host_cred_file_path).and_return(true) + expect(Chef::TrainTransport.credentials_file_path).to eq(host_cred_file_path) end end end |