diff options
author | tylercloke <tylercloke@gmail.com> | 2015-04-29 15:29:02 -0700 |
---|---|---|
committer | tylercloke <tylercloke@gmail.com> | 2015-04-30 09:56:58 -0700 |
commit | 75cb417e2edbf21427d778b4675c806bdb312b3f (patch) | |
tree | 459ce71ec0b3184409430a2cc01005adabe8966e /lib/chef | |
parent | 2d7f8a477b68767373068f363f785b84b9b832ae (diff) | |
download | chef-75cb417e2edbf21427d778b4675c806bdb312b3f.tar.gz |
Changes Chef::Key update to allow updating the name of a key.
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/key.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/chef/key.rb b/lib/chef/key.rb index 1ba0ab49c9..3c8229f859 100644 --- a/lib/chef/key.rb +++ b/lib/chef/key.rb @@ -159,12 +159,18 @@ class Chef self.class.generate_fingerprint(@public_key) end - def update - if @name.nil? - raise Chef::Exceptions::MissingKeyAttribute, "the name field must be populated when update is called" + # set @name and pass put_name if you wish to update the name of an existing key put_name to @name + def update(put_name=nil) + if @name.nil? && put_name.nil? + raise Chef::Exceptions::MissingKeyAttribute, "the name field must be populated or you must pass a name to update when update is called" end - new_key = chef_rest.put_rest("#{api_base}/#{@actor}/keys/#{@name}", to_hash) + # If no name was passed, fall back to using @name in the PUT URL, otherwise + # use the put_name passed. This will update the a key by the name put_name + # to @name. + put_name = @name if put_name.nil? + + new_key = chef_rest.put_rest("#{api_base}/#{@actor}/keys/#{put_name}", to_hash) Chef::Key.from_hash(self.to_hash.merge(new_key)) end |