diff options
author | danielsdeleo <dan@opscode.com> | 2012-12-14 18:29:42 -0800 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2012-12-14 18:29:42 -0800 |
commit | 908b9b6734c996bfb8705b9b9523ed4b69704611 (patch) | |
tree | 3cb1b078ce7837107b78cfd08fd6e45c94cd82b4 | |
parent | 3c164ca9ea96c89e1db9128cb5dc87ff006af152 (diff) | |
parent | 5c2665b0b27d2224e1404d8d0f0728aa375abef0 (diff) | |
download | chef-908b9b6734c996bfb8705b9b9523ed4b69704611.tar.gz |
Merge branch 'CHEF-3689-10-stable' into 10-stable
-rw-r--r-- | chef/lib/chef/api_client.rb | 6 | ||||
-rw-r--r-- | chef/lib/chef/rest.rb | 15 |
2 files changed, 13 insertions, 8 deletions
diff --git a/chef/lib/chef/api_client.rb b/chef/lib/chef/api_client.rb index 53f62324a2..02dd34d0d5 100644 --- a/chef/lib/chef/api_client.rb +++ b/chef/lib/chef/api_client.rb @@ -164,7 +164,7 @@ class Chef def self.json_create(o) client = Chef::ApiClient.new client.name(o["name"] || o["clientname"]) - client.private_key(o["private_key"]) + client.private_key(o["private_key"]) if o["private_key"] client.public_key(o["public_key"]) client.admin(o["admin"]) client.couchdb_rev = o["_rev"] @@ -284,8 +284,8 @@ class Chef end def inspect - "Chef::ApiClient name:'#{name}' admin:'#{admin.inspect}'" + - "public_key:'#{public_key}' private_key:#{private_key}" + "Chef::ApiClient name:'#{name}' admin:'#{admin.inspect}' " + + "public_key:'#{public_key}' private_key:'#{private_key}'" end end diff --git a/chef/lib/chef/rest.rb b/chef/lib/chef/rest.rb index cd595c8fdf..80c98c4620 100644 --- a/chef/lib/chef/rest.rb +++ b/chef/lib/chef/rest.rb @@ -99,11 +99,18 @@ class Chef begin response = nc.save(true, true) Chef::Log.debug("Registration response: #{response.inspect}") - raise Chef::Exceptions::CannotWritePrivateKey, "The response from the server did not include a private key!" unless response.has_key?("private_key") + private_key = if response.respond_to?(:[]) + response["private_key"] + else + response.private_key + end + unless private_key + raise Chef::Exceptions::CannotWritePrivateKey, "The response from the server did not include a private key!" + end # Write out the private key ::File.open(destination, "w") {|f| f.chmod(0600) - f.print(response["private_key"]) + f.print(private_key) } throw :done rescue IOError @@ -360,7 +367,7 @@ class Chef begin http_attempts += 1 - res = yield rest_request + yield rest_request rescue SocketError, Errno::ETIMEDOUT => e e.message.replace "Error connecting to #{url} - #{e.message}" @@ -452,7 +459,6 @@ class Chef Chef::Log.debug("Streaming download from #{url.to_s} to tempfile #{tf.path}") # Stolen from http://www.ruby-forum.com/topic/166423 # Kudos to _why! - size, total = 0, response.header['Content-Length'].to_i inflater = if gzip_disabled? NoopInflater.new @@ -471,7 +477,6 @@ class Chef response.read_body do |chunk| tf.write(inflater.inflate(chunk)) - size += chunk.size end tf.close tf |