diff options
author | Thom May <thom@may.lt> | 2018-05-14 14:48:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-14 14:48:27 +0100 |
commit | 257ee5880c5fa3de1e435d3a165b7b501bb79910 (patch) | |
tree | c7921eb4b5b825cac61730e3af474cf6239ee462 | |
parent | 5ccc5685550b961144b8aec045089c4172722706 (diff) | |
parent | 19399df830795e2ac290f970c455ffc002f874cf (diff) | |
download | chef-257ee5880c5fa3de1e435d3a165b7b501bb79910.tar.gz |
Merge pull request #7237 from smcavallo/support_knife_toml_config
Support for toml knife config settings
-rw-r--r-- | chef-config/lib/chef-config/workstation_config_loader.rb | 6 | ||||
-rw-r--r-- | chef-config/spec/unit/workstation_config_loader_spec.rb | 26 |
2 files changed, 30 insertions, 2 deletions
diff --git a/chef-config/lib/chef-config/workstation_config_loader.rb b/chef-config/lib/chef-config/workstation_config_loader.rb index 2738d6a1a2..99d2ab198f 100644 --- a/chef-config/lib/chef-config/workstation_config_loader.rb +++ b/chef-config/lib/chef-config/workstation_config_loader.rb @@ -72,7 +72,7 @@ module ChefConfig load_credentials(profile) # Ignore it if there's no explicit_config_file and can't find one at a # default path. - if !config_location.nil? + unless config_location.nil? if explicit_config_file && !path_exists?(config_location) raise ChefConfig::ConfigurationError, "Specified config file #{config_location} does not exist" end @@ -156,6 +156,8 @@ module ChefConfig Config.chef_server_url = creds.fetch("chef_server_url") if creds.key?("chef_server_url") Config.validation_client_name = creds.fetch("validation_client_name") if creds.key?("validation_client_name") + Config.knife.merge!(Hash[creds.fetch("knife", {}).map { |k, v| [k.to_sym, v] }]) + extract_key(creds, "validation_key", :validation_key, :validation_key_contents) extract_key(creds, "validator_key", :validation_key, :validation_key_contents) extract_key(creds, "client_key", :client_key, :client_key_contents) @@ -196,7 +198,7 @@ module ChefConfig message << "#{e.class.name}: #{e.message}\n" filtered_trace = e.backtrace.grep(/#{Regexp.escape(config_file_path)}/) filtered_trace.each { |bt_line| message << " " << bt_line << "\n" } - if !filtered_trace.empty? + unless filtered_trace.empty? line_nr = filtered_trace.first[/#{Regexp.escape(config_file_path)}:([\d]+)/, 1] message << highlight_config_error(config_file_path, line_nr.to_i) end diff --git a/chef-config/spec/unit/workstation_config_loader_spec.rb b/chef-config/spec/unit/workstation_config_loader_spec.rb index 509d95fe36..8f1cde17e6 100644 --- a/chef-config/spec/unit/workstation_config_loader_spec.rb +++ b/chef-config/spec/unit/workstation_config_loader_spec.rb @@ -406,6 +406,32 @@ EOH end end + context "and has a default profile with knife settings" do + let(:content) do + content = <<EOH +[default] +node_name = 'barney' +client_key = "barney_rubble.pem" +chef_server_url = "https://api.chef.io/organizations/bedrock" +knife = { + secret_file = "/home/barney/.chef/encrypted_data_bag_secret.pem" +} +[default.knife] +ssh_user = "knife_ssh_user" +EOH + content + end + + it "applies the expected knife config" do + expect { config_loader.load_credentials }.not_to raise_error + expect(ChefConfig::Config.chef_server_url).to eq("https://api.chef.io/organizations/bedrock") + expect(ChefConfig::Config.client_key.to_s).to eq("#{home}/.chef/barney_rubble.pem") + expect(ChefConfig::Config.knife[:ssh_user].to_s).to eq("knife_ssh_user") + expect(ChefConfig::Config.knife[:secret_file].to_s).to eq("/home/barney/.chef/encrypted_data_bag_secret.pem") + expect(ChefConfig::Config.profile.to_s).to eq("default") + end + end + context "and has a profile containing a full key" do let(:content) do content = <<EOH |