diff options
author | tylercloke <tylercloke@gmail.com> | 2015-07-02 13:30:07 -0700 |
---|---|---|
committer | tylercloke <tylercloke@gmail.com> | 2015-07-06 14:36:03 -0700 |
commit | e1960b315b55fba380bfc3837c7655bbd6dd1a4d (patch) | |
tree | d1c95848c947a75350d484309c970a60d3fb9535 /lib/chef | |
parent | 7950b19244fe948619cb0662be5a0044fffe0436 (diff) | |
download | chef-e1960b315b55fba380bfc3837c7655bbd6dd1a4d.tar.gz |
Remove all the stupid json magic from Chef::ApiClientV1.
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/api_client_v1.rb | 37 | ||||
-rw-r--r-- | lib/chef/json_compat.rb | 3 | ||||
-rw-r--r-- | lib/chef/knife/client_create.rb | 4 | ||||
-rw-r--r-- | lib/chef/knife/client_edit.rb | 10 |
4 files changed, 20 insertions, 34 deletions
diff --git a/lib/chef/api_client_v1.rb b/lib/chef/api_client_v1.rb index ac8918184d..80f0d2517c 100644 --- a/lib/chef/api_client_v1.rb +++ b/lib/chef/api_client_v1.rb @@ -57,21 +57,15 @@ class Chef end def chef_rest_v0 - @chef_rest_v0 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url], {:api_version => "0"}) + @chef_rest_v0 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url], {:api_version => "0", :inflate_json_class => false}) end def chef_rest_v1 - @chef_rest_v1 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url], {:api_version => "1"}) + @chef_rest_v1 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url], {:api_version => "1", :inflate_json_class => false}) end - # will default to the current version (Chef::Authenticator::DEFAULT_SERVER_API_VERSION) - def http_api - @http_api ||= Chef::REST.new(Chef::Config[:chef_server_url]) - end - - # will default to the current version (Chef::Authenticator::DEFAULT_SERVER_API_VERSION) def self.http_api - Chef::REST.new(Chef::Config[:chef_server_url]) + Chef::ServerAPI.new(Chef::Config[:chef_server_url], {:api_version => "1", :inflate_json_class => false}) end # Gets or sets the client name. @@ -157,7 +151,6 @@ class Chef "name" => @name, "validator" => @validator, "admin" => @admin, - 'json_class' => self.class.name, "chef_type" => "client" } result["private_key"] = @private_key unless @private_key.nil? @@ -184,16 +177,12 @@ class Chef client end - def self.json_create(data) - from_hash(data) - end - def self.from_json(j) - from_hash(Chef::JSONCompat.parse(j)) + Chef::ApiClientV1.from_hash(Chef::JSONCompat.from_json(j)) end def self.reregister(name) - api_client = load(name) + api_client = Chef::ApiClientV1.load(name) api_client.reregister end @@ -201,7 +190,7 @@ class Chef if inflate response = Hash.new Chef::Search::Query.new.search(:client) do |n| - n = self.json_create(n) if n.instance_of?(Hash) + n = self.from_hash(n) if n.instance_of?(Hash) response[n.name] = n end response @@ -213,20 +202,12 @@ class Chef # Load a client by name via the API def self.load(name) response = http_api.get("clients/#{name}") - if response.kind_of?(Chef::ApiClientV1) - response - # stupid automated object generation. - # just give me the json :( - elsif response.kind_of?(Chef::ApiClient) - json_create(response.to_json) - else - json_create(response) - end + Chef::ApiClientV1.from_hash(response) end # Remove this client via the REST API def destroy - http_api.delete("clients/#{@name}") + chef_rest_v1.delete("clients/#{@name}") end # Save this client via the REST API, returns a hash including the private key @@ -291,7 +272,7 @@ class Chef new_client = chef_rest_v0.put("clients/#{name}", payload) end - new_client + Chef::ApiClientV1.from_hash(new_client) end # Create the client via the REST API diff --git a/lib/chef/json_compat.rb b/lib/chef/json_compat.rb index e8053d12f1..d0b3b4c7f8 100644 --- a/lib/chef/json_compat.rb +++ b/lib/chef/json_compat.rb @@ -29,7 +29,6 @@ class Chef JSON_CLASS = "json_class".freeze CHEF_APICLIENT = "Chef::ApiClient".freeze - CHEF_APICLIENTV1 = "Chef::ApiClientV1".freeze CHEF_CHECKSUM = "Chef::Checksum".freeze CHEF_COOKBOOKVERSION = "Chef::CookbookVersion".freeze CHEF_DATABAG = "Chef::DataBag".freeze @@ -125,8 +124,6 @@ class Chef case json_class when CHEF_APICLIENT Chef::ApiClient - when CHEF_APICLIENTV1 - Chef::ApiClientV1 when CHEF_CHECKSUM Chef::Checksum when CHEF_COOKBOOKVERSION diff --git a/lib/chef/knife/client_create.rb b/lib/chef/knife/client_create.rb index 951457db28..fa9a1a7e32 100644 --- a/lib/chef/knife/client_create.rb +++ b/lib/chef/knife/client_create.rb @@ -62,7 +62,7 @@ class Chef def create_client(client) # should not be using save :( bad behavior - client.save + Chef::ApiClientV1.from_hash(client).save end def run @@ -93,7 +93,7 @@ class Chef output = edit_data(client) final_client = create_client(output) - ui.info("Created #{output}") + ui.info("Created #{final_client}") # output private_key if one if final_client.private_key diff --git a/lib/chef/knife/client_edit.rb b/lib/chef/knife/client_edit.rb index a243129979..5dcd8f212b 100644 --- a/lib/chef/knife/client_edit.rb +++ b/lib/chef/knife/client_edit.rb @@ -38,7 +38,15 @@ class Chef exit 1 end - edit_object(Chef::ApiClientV1, @client_name) + original_data = Chef::ApiClientV1.load(@client_name).to_hash + edited_client = edit_data(original_data) + if original_data != edited_client + client = Chef::ApiClientV1.from_hash(edited_client) + client.save + ui.msg("Saved #{client}.") + else + ui.msg("Client unchanged, not saving.") + end end end end |