summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2012-12-18 17:07:56 -0800
committerdanielsdeleo <dan@opscode.com>2012-12-18 17:10:05 -0800
commitd737f867d71d193081f6a7cffe1ae5665d6bb983 (patch)
treefb226fa78f4289a072cb6c775a312f6addcb9de7
parent10b457a41b27a71168c5f86b1bb47c72c44833bc (diff)
downloadchef-d737f867d71d193081f6a7cffe1ae5665d6bb983.tar.gz
[CHEF-3689] remove extra flags to Client#save
-rw-r--r--lib/chef/api_client.rb14
-rw-r--r--spec/unit/api_client_spec.rb5
2 files changed, 8 insertions, 11 deletions
diff --git a/lib/chef/api_client.rb b/lib/chef/api_client.rb
index 6c7132d28f..32e1eee017 100644
--- a/lib/chef/api_client.rb
+++ b/lib/chef/api_client.rb
@@ -158,19 +158,13 @@ class Chef
end
# Save this client via the REST API, returns a hash including the private key
- def save(new_key=false, validation=false)
- if validation
- r = http_api_as_validator
- else
- r = http_api
- end
- # First, try and create a new registration
+ def save
begin
- r.post("clients", {:name => self.name, :admin => self.admin })
+ http_api.put("clients/#{name}", { :name => self.name, :admin => self.admin})
rescue Net::HTTPServerException => e
# If that fails, go ahead and try and update it
- if e.response.code == "409"
- r.put("clients/#{name}", { :name => self.name, :admin => self.admin, :private_key => new_key })
+ if e.response.code == "404"
+ http_api.post("clients", {:name => self.name, :admin => self.admin })
else
raise e
end
diff --git a/spec/unit/api_client_spec.rb b/spec/unit/api_client_spec.rb
index 6368082815..d1097d81bf 100644
--- a/spec/unit/api_client_spec.rb
+++ b/spec/unit/api_client_spec.rb
@@ -153,12 +153,15 @@ describe Chef::ApiClient do
Chef::Config[:client_key] = nil
end
+ let :private_key_data do
+ File.open(Chef::Config[:client_key], "rb") {|f| f.read.chomp }
+ end
+
it "has an HTTP client configured with default credentials" do
@client.http_api.should be_a_kind_of(Chef::REST)
@client.http_api.client_name.should == "silent-bob"
@client.http_api.signing_key.to_s.should == private_key_data
end
-
end