summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSteven Danna <steve@opscode.com>2015-01-22 15:58:00 +0000
committerBryan McLellan <btm@opscode.com>2015-02-09 21:19:44 -0500
commitd6a4671ccc3df7ef8fabeb417971cb133de10ad7 (patch)
tree268496eed2130524e927bad1441d619aa28d5511 /lib
parent0d5c1ba1518820e4c4dc9eb732b422e94b4b5c24 (diff)
downloadchef-d6a4671ccc3df7ef8fabeb417971cb133de10ad7.tar.gz
Use ApiClient#from_hash rather than relying on json_class in return data
Previously, knife client create was unable to create a client if the client json provided by the user did not include json_class. Using ApiClient#from_hash removes the restriction. The tests have been updated to test the contract between knife client create and the ApiClient class. Namely, knife client create is expected to call ApiClient.from_hash with a properly formated hash given the the user options and then call #save on the returned object.
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/knife/client_create.rb15
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/chef/knife/client_create.rb b/lib/chef/knife/client_create.rb
index b2bac36081..477a400e8a 100644
--- a/lib/chef/knife/client_create.rb
+++ b/lib/chef/knife/client_create.rb
@@ -54,14 +54,16 @@ class Chef
exit 1
end
- client = Chef::ApiClient.new
- client.name(@client_name)
- client.admin(config[:admin])
- client.validator(config[:validator])
+ client_hash = {
+ "name" => @client_name,
+ "admin" => !!config[:admin],
+ "validator" => !!config[:validator]
+ }
- output = edit_data(client)
+ output = Chef::ApiClient.from_hash(edit_hash(client_hash))
- # Chef::ApiClient.save will try to create a client and if it exists will update it instead silently
+ # Chef::ApiClient.save will try to create a client and if it
+ # exists will update it instead silently.
client = output.save
# We only get a private_key on client creation, not on client update.
@@ -83,4 +85,3 @@ class Chef
end
end
end
-