summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorS.Cavallo <smcavallo@hotmail.com>2018-05-09 13:18:00 -0400
committerS.Cavallo <smcavallo@hotmail.com>2018-05-09 13:18:00 -0400
commit3d8ed4ea8ca808e42c689225ef1780ef01d028a4 (patch)
tree4f16acbfcb885553f3cc5b02b0d5ad95dbf98857
parentdbee7f652952beb8e1056f6e6731223672788838 (diff)
downloadchef-3d8ed4ea8ca808e42c689225ef1780ef01d028a4.tar.gz
Signed-off-by: S.Cavallo <smcavallo@hotmail.com>
Support for toml knife config settings
-rw-r--r--chef-config/lib/chef-config/workstation_config_loader.rb11
-rw-r--r--chef-config/spec/unit/workstation_config_loader_spec.rb4
2 files changed, 13 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..76b829b42e 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,13 @@ 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")
+ creds.each do |cred|
+ knife_setting = /knife\[:(\w+)\]/.match(cred[0])
+ if knife_setting
+ Config.knife[knife_setting[1].to_sym] = cred[1]
+ end
+ end
+
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 +203,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..677d411e3b 100644
--- a/chef-config/spec/unit/workstation_config_loader_spec.rb
+++ b/chef-config/spec/unit/workstation_config_loader_spec.rb
@@ -394,6 +394,8 @@ RSpec.describe ChefConfig::WorkstationConfigLoader do
node_name = 'barney'
client_key = "barney_rubble.pem"
chef_server_url = "https://api.chef.io/organizations/bedrock"
+"knife[:ssh_user]" = 'knife_ssh_user'
+"knife[:secret_file]" = "/home/barney/.chef/encrypted_data_bag_secret.pem"
EOH
content
end
@@ -402,6 +404,8 @@ EOH
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