summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2017-12-18 15:56:49 +0000
committerThom May <thom@chef.io>2017-12-18 15:56:49 +0000
commit5451b2a4640e62184a615c167600cb47f7bc363b (patch)
tree02ce913919e4036532131f5e6082ceea26344642
parent57732ab92cc315c6161fbdef4ee17ceaebffc656 (diff)
downloadchef-5451b2a4640e62184a615c167600cb47f7bc363b.tar.gz
respond to review requests
Signed-off-by: Thom May <thom@chef.io>
-rw-r--r--chef-config/lib/chef-config/workstation_config_loader.rb6
-rw-r--r--chef-config/spec/unit/workstation_config_loader_spec.rb16
2 files changed, 21 insertions, 1 deletions
diff --git a/chef-config/lib/chef-config/workstation_config_loader.rb b/chef-config/lib/chef-config/workstation_config_loader.rb
index fdde1e0255..2738d6a1a2 100644
--- a/chef-config/lib/chef-config/workstation_config_loader.rb
+++ b/chef-config/lib/chef-config/workstation_config_loader.rb
@@ -146,7 +146,11 @@ module ChefConfig
a
end
- def apply_credentials(creds, _profile)
+ def apply_credentials(creds, profile)
+ Config.profile ||= profile
+ if creds.key?("node_name") && creds.key?("client_name")
+ raise ChefConfig::ConfigurationError, "Do not specify both node_name and client_name. You should prefer client_name."
+ end
Config.node_name = creds.fetch("node_name") if creds.key?("node_name")
Config.node_name = creds.fetch("client_name") if creds.key?("client_name")
Config.chef_server_url = creds.fetch("chef_server_url") if creds.key?("chef_server_url")
diff --git a/chef-config/spec/unit/workstation_config_loader_spec.rb b/chef-config/spec/unit/workstation_config_loader_spec.rb
index 4bc9e2ba61..38fd727ce9 100644
--- a/chef-config/spec/unit/workstation_config_loader_spec.rb
+++ b/chef-config/spec/unit/workstation_config_loader_spec.rb
@@ -401,6 +401,7 @@ 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.profile.to_s).to eq("default")
end
end
@@ -473,6 +474,21 @@ EOH
end
end
+ context "and contains both node_name and client_name" do
+ let(:content) do
+ content = <<EOH
+[default]
+node_name = 'barney'
+client_name = 'barney'
+EOH
+ content
+ end
+
+ it "raises a ConfigurationError" do
+ expect { config_loader.load_credentials }.to raise_error(ChefConfig::ConfigurationError)
+ end
+ end
+
context "and has a syntax error" do
let(:content) { "<<<<<" }