summaryrefslogtreecommitdiff
path: root/lib/chef/key.rb
diff options
context:
space:
mode:
authortylercloke <tylercloke@gmail.com>2015-04-27 16:15:28 -0700
committertylercloke <tylercloke@gmail.com>2015-04-28 13:20:01 -0700
commitafa4b9e4034628bf5a4f337cf57cfa657df6ec3d (patch)
tree2a0f64e3f356c908aeca0793f90cf39cc7169c43 /lib/chef/key.rb
parente60111f2773b60309db41581a98a66b5ed7cdad6 (diff)
downloadchef-afa4b9e4034628bf5a4f337cf57cfa657df6ec3d.tar.gz
Fixed bug in Chef::Key where create failed to return the full key.
Code assumed POST to keys endpoint returned the key body like other parts of the API. Now, it simply generated the new key returned by create from the original key plus the private_key returned by the API if any. Specs also updated.
Diffstat (limited to 'lib/chef/key.rb')
-rw-r--r--lib/chef/key.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/chef/key.rb b/lib/chef/key.rb
index 1828713386..1ba0ab49c9 100644
--- a/lib/chef/key.rb
+++ b/lib/chef/key.rb
@@ -147,7 +147,11 @@ class Chef
payload['public_key'] = @public_key unless @public_key.nil?
payload['create_key'] = @create_key if @create_key
payload['expiration_date'] = @expiration_date unless @expiration_date.nil?
- new_key = chef_rest.post_rest("#{api_base}/#{@actor}/keys", payload)
+ result = chef_rest.post_rest("#{api_base}/#{@actor}/keys", payload)
+ # append the private key to the current key if the server returned one,
+ # since the POST endpoint just returns uri and private_key if needed.
+ new_key = self.to_hash
+ new_key["private_key"] = result["private_key"] if result["private_key"]
Chef::Key.from_hash(new_key)
end