diff options
author | Thom May <thom@chef.io> | 2015-12-02 12:19:33 +0000 |
---|---|---|
committer | Thom May <thom@chef.io> | 2016-01-11 15:40:42 +0000 |
commit | d99e306a41b1402209d320cb7119b12a3bbb962f (patch) | |
tree | f65940702826deb991e6198967d3e9e96cb2857a /lib/chef/role.rb | |
parent | 1b71aeb423b009f6d1a44215c89e9976957b47e9 (diff) | |
download | chef-d99e306a41b1402209d320cb7119b12a3bbb962f.tar.gz |
Convert all uses of Chef::REST to Chef::ServerAPItm/no_more_rest
In the process, stop auto-expanding JSON in the HTTP client, and let
individual classes control that themselves.
Fixes #2737, Fixes #3518
Diffstat (limited to 'lib/chef/role.rb')
-rw-r--r-- | lib/chef/role.rb | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/lib/chef/role.rb b/lib/chef/role.rb index c085d1d714..6984a8a245 100644 --- a/lib/chef/role.rb +++ b/lib/chef/role.rb @@ -24,6 +24,7 @@ require 'chef/mixin/from_file' require 'chef/run_list' require 'chef/mash' require 'chef/json_compat' +require 'chef/server_api' require 'chef/search/query' class Chef @@ -45,11 +46,11 @@ class Chef end def chef_server_rest - @chef_server_rest ||= Chef::REST.new(Chef::Config[:chef_server_url]) + @chef_server_rest ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url]) end def self.chef_server_rest - Chef::REST.new(Chef::Config[:chef_server_url]) + Chef::ServerAPI.new(Chef::Config[:chef_server_url]) end def name(arg=nil) @@ -170,6 +171,10 @@ class Chef # Create a Chef::Role from JSON def self.json_create(o) + from_hash(o) + end + + def self.from_hash(o) role = new role.name(o["name"]) role.description(o["description"]) @@ -199,42 +204,42 @@ class Chef end response else - chef_server_rest.get_rest("roles") + chef_server_rest.get("roles") end end # Load a role by name from the API def self.load(name) - chef_server_rest.get_rest("roles/#{name}") + from_hash(chef_server_rest.get("roles/#{name}")) end def environment(env_name) - chef_server_rest.get_rest("roles/#{@name}/environments/#{env_name}") + chef_server_rest.get("roles/#{@name}/environments/#{env_name}") end def environments - chef_server_rest.get_rest("roles/#{@name}/environments") + chef_server_rest.get("roles/#{@name}/environments") end # Remove this role via the REST API def destroy - chef_server_rest.delete_rest("roles/#{@name}") + chef_server_rest.delete("roles/#{@name}") end # Save this role via the REST API def save begin - chef_server_rest.put_rest("roles/#{@name}", self) + chef_server_rest.put("roles/#{@name}", self) rescue Net::HTTPServerException => e raise e unless e.response.code == "404" - chef_server_rest.post_rest("roles", self) + chef_server_rest.post("roles", self) end self end # Create the role via the REST API def create - chef_server_rest.post_rest("roles", self) + chef_server_rest.post("roles", self) self end @@ -258,7 +263,8 @@ class Chef if js_path && File.exists?(js_path) # from_json returns object.class => json_class in the JSON. - return Chef::JSONCompat.from_json(IO.read(js_path)) + hsh = Chef::JSONCompat.parse(IO.read(js_path)) + return from_hash(hsh) elsif rb_path && File.exists?(rb_path) role = Chef::Role.new role.name(name) |