summaryrefslogtreecommitdiff
path: root/lib/chef/api_client.rb
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2012-12-06 11:13:40 -0800
committerdanielsdeleo <dan@opscode.com>2012-12-06 11:13:40 -0800
commit4ef284f09b7c8b699b7e3b28feb3a3efba7843c0 (patch)
treee1938dbe3ddad4d3b9929b8deb0b65b31230e416 /lib/chef/api_client.rb
parent641fbbb056ac2e1da53fa9506f023db24d7285c1 (diff)
downloadchef-4ef284f09b7c8b699b7e3b28feb3a3efba7843c0.tar.gz
[CHEF-3662] ApiClient can reregister itself
Diffstat (limited to 'lib/chef/api_client.rb')
-rw-r--r--lib/chef/api_client.rb18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/chef/api_client.rb b/lib/chef/api_client.rb
index da05939c24..3502f96987 100644
--- a/lib/chef/api_client.rb
+++ b/lib/chef/api_client.rb
@@ -116,6 +116,11 @@ class Chef
client
end
+ def self.reregister(name)
+ api_client = load(name)
+ api_client.reregister
+ end
+
def self.list(inflate=false)
if inflate
response = Hash.new
@@ -131,7 +136,7 @@ class Chef
# Load a client by name via the API
def self.load(name)
- response = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("clients/#{name}")
+ response = Chef::REST.new(Chef::Config[:chef_server_url]).get("clients/#{name}")
if response.kind_of?(Chef::ApiClient)
response
else
@@ -166,6 +171,17 @@ class Chef
end
end
+ def reregister
+ r = Chef::REST.new(Chef::Config[:chef_server_url])
+ reregistered_self = r.put("clients/#{name}", { :name => name, :admin => admin, :private_key => true })
+ if reregistered_self.respond_to?(:[])
+ private_key(reregistered_self["private_key"])
+ else
+ private_key(reregistered_self.private_key)
+ end
+ self
+ end
+
# Create the client via the REST API
def create
Chef::REST.new(Chef::Config[:chef_server_url]).post_rest("clients", self)