summaryrefslogtreecommitdiff
path: root/lib/chef/data_bag_item.rb
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2015-12-02 12:19:33 +0000
committerThom May <thom@chef.io>2016-01-11 15:40:42 +0000
commitd99e306a41b1402209d320cb7119b12a3bbb962f (patch)
treef65940702826deb991e6198967d3e9e96cb2857a /lib/chef/data_bag_item.rb
parent1b71aeb423b009f6d1a44215c89e9976957b47e9 (diff)
downloadchef-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/data_bag_item.rb')
-rw-r--r--lib/chef/data_bag_item.rb36
1 files changed, 19 insertions, 17 deletions
diff --git a/lib/chef/data_bag_item.rb b/lib/chef/data_bag_item.rb
index 31c9b69330..7ef9fffe07 100644
--- a/lib/chef/data_bag_item.rb
+++ b/lib/chef/data_bag_item.rb
@@ -25,6 +25,7 @@ require 'chef/mixin/params_validate'
require 'chef/mixin/from_file'
require 'chef/data_bag'
require 'chef/mash'
+require 'chef/server_api'
require 'chef/json_compat'
class Chef
@@ -58,11 +59,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 raw_data
@@ -125,22 +126,23 @@ class Chef
end
def self.from_hash(h)
+ h.delete("chef_type")
+ h.delete("json_class")
+ h.delete("name")
+
item = new
- item.raw_data = h
+ item.data_bag(h.delete("data_bag")) if h.key?("data_bag")
+ if h.key?("raw_data")
+ item.raw_data = Mash.new(h["raw_data"])
+ else
+ item.raw_data = h
+ end
item
end
# Create a Chef::DataBagItem from JSON
def self.json_create(o)
- bag_item = new
- bag_item.data_bag(o["data_bag"])
- o.delete("data_bag")
- o.delete("chef_type")
- o.delete("json_class")
- o.delete("name")
-
- bag_item.raw_data = Mash.new(o["raw_data"])
- bag_item
+ from_hash(o)
end
# Load a Data Bag Item by name via either the RESTful API or local data_bag_path if run in solo mode
@@ -149,7 +151,7 @@ class Chef
bag = Chef::DataBag.load(data_bag)
item = bag[name]
else
- item = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("data/#{data_bag}/#{name}")
+ item = Chef::ServerAPI.new(Chef::Config[:chef_server_url]).get("data/#{data_bag}/#{name}")
end
if item.kind_of?(DataBagItem)
@@ -162,7 +164,7 @@ class Chef
end
def destroy(data_bag=data_bag(), databag_item=name)
- chef_server_rest.delete_rest("data/#{data_bag}/#{databag_item}")
+ chef_server_rest.delete("data/#{data_bag}/#{databag_item}")
end
# Save this Data Bag Item via RESTful API
@@ -172,18 +174,18 @@ class Chef
if Chef::Config[:why_run]
Chef::Log.warn("In why-run mode, so NOT performing data bag item save.")
else
- r.put_rest("data/#{data_bag}/#{item_id}", self)
+ r.put("data/#{data_bag}/#{item_id}", self)
end
rescue Net::HTTPServerException => e
raise e unless e.response.code == "404"
- r.post_rest("data/#{data_bag}", self)
+ r.post("data/#{data_bag}", self)
end
self
end
# Create this Data Bag Item via RESTful API
def create
- chef_server_rest.post_rest("data/#{data_bag}", self)
+ chef_server_rest.post("data/#{data_bag}", self)
self
end