summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2016-01-21 11:14:49 +0000
committerThom May <thom@may.lt>2016-01-21 11:14:49 +0000
commitb2287acca8df58079205979ab2ba956d0e281fe5 (patch)
tree471e241d05effbe9d2b470588c1ff0f647952741
parent38e4b8ad4a1d701878595c7822636f3cbb7f7af9 (diff)
parent3458740dc59959e0eaa88543883756d041435d56 (diff)
downloadchef-b2287acca8df58079205979ab2ba956d0e281fe5.tar.gz
Merge pull request #4423 from chef/tm/rest_deprecation
Add deprecation warnings to Chef::REST and all json_creates
-rw-r--r--lib/chef/api_client.rb3
-rw-r--r--lib/chef/chef_fs/data_handler/data_handler_base.rb2
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb2
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb2
-rw-r--r--lib/chef/cookbook_version.rb1
-rw-r--r--lib/chef/data_bag.rb1
-rw-r--r--lib/chef/data_bag_item.rb1
-rw-r--r--lib/chef/environment.rb4
-rw-r--r--lib/chef/key.rb5
-rw-r--r--lib/chef/knife/core/object_loader.rb2
-rw-r--r--lib/chef/node.rb1
-rw-r--r--lib/chef/org.rb5
-rw-r--r--lib/chef/rest.rb2
-rw-r--r--lib/chef/role.rb1
-rw-r--r--lib/chef/user.rb5
-rw-r--r--lib/chef/user_v1.rb5
-rw-r--r--spec/functional/rest_spec.rb1
-rw-r--r--spec/unit/api_client_spec.rb2
-rw-r--r--spec/unit/data_bag_item_spec.rb2
-rw-r--r--spec/unit/data_bag_spec.rb2
-rw-r--r--spec/unit/environment_spec.rb2
-rw-r--r--spec/unit/handler/json_file_spec.rb2
-rw-r--r--spec/unit/json_compat_spec.rb7
-rw-r--r--spec/unit/node_spec.rb4
-rw-r--r--spec/unit/rest_spec.rb7
25 files changed, 50 insertions, 21 deletions
diff --git a/lib/chef/api_client.rb b/lib/chef/api_client.rb
index 9def6199b7..cea9dd8176 100644
--- a/lib/chef/api_client.rb
+++ b/lib/chef/api_client.rb
@@ -141,6 +141,7 @@ class Chef
end
def self.json_create(data)
+ Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please use Chef::ApiClient#from_hash")
from_hash(data)
end
@@ -176,7 +177,7 @@ class Chef
if response.kind_of?(Chef::ApiClient)
response
else
- json_create(response)
+ from_hash(response)
end
end
diff --git a/lib/chef/chef_fs/data_handler/data_handler_base.rb b/lib/chef/chef_fs/data_handler/data_handler_base.rb
index 53936979e3..41c5dd13e2 100644
--- a/lib/chef/chef_fs/data_handler/data_handler_base.rb
+++ b/lib/chef/chef_fs/data_handler/data_handler_base.rb
@@ -117,7 +117,7 @@ class Chef
# Turn a JSON hash into a bona fide Chef object (like Chef::Node).
#
def chef_object(object)
- chef_class.json_create(object)
+ chef_class.from_hash(object)
end
#
diff --git a/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb b/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb
index 18bf748d87..fb3c185145 100644
--- a/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb
@@ -188,7 +188,7 @@ class Chef
old_retry_count = Chef::Config[:http_retry_count]
begin
Chef::Config[:http_retry_count] = 0
- @chef_object ||= Chef::CookbookVersion.json_create(root.get_json(api_path))
+ @chef_object ||= Chef::CookbookVersion.from_hash(root.get_json(api_path))
ensure
Chef::Config[:http_retry_count] = old_retry_count
end
diff --git a/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb b/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb
index 692b6cfc73..cfc9e43955 100644
--- a/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb
@@ -102,7 +102,7 @@ class Chef
def chef_object
# REST will inflate the Chef object using json_class
- data_handler.json_class.json_create(read)
+ data_handler.json_class.from_hash(read)
end
def minimize_value(value)
diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb
index 28f817c8ba..19150464ba 100644
--- a/lib/chef/cookbook_version.rb
+++ b/lib/chef/cookbook_version.rb
@@ -476,6 +476,7 @@ class Chef
end
def self.json_create(o)
+ Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please use Chef::CookbookVersion#from_hash")
from_hash(o)
end
diff --git a/lib/chef/data_bag.rb b/lib/chef/data_bag.rb
index 66771d325f..38b3d4fdf5 100644
--- a/lib/chef/data_bag.rb
+++ b/lib/chef/data_bag.rb
@@ -80,6 +80,7 @@ class Chef
# Create a Chef::Role from JSON
def self.json_create(o)
+ Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please use Chef::DataBag#from_hash")
from_hash(o)
end
diff --git a/lib/chef/data_bag_item.rb b/lib/chef/data_bag_item.rb
index 8688693568..facf6c89f4 100644
--- a/lib/chef/data_bag_item.rb
+++ b/lib/chef/data_bag_item.rb
@@ -142,6 +142,7 @@ class Chef
# Create a Chef::DataBagItem from JSON
def self.json_create(o)
+ Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please use Chef::DataBagItem#from_hash")
from_hash(o)
end
diff --git a/lib/chef/environment.rb b/lib/chef/environment.rb
index e41f2b66ac..042cde5bd5 100644
--- a/lib/chef/environment.rb
+++ b/lib/chef/environment.rb
@@ -217,6 +217,7 @@ class Chef
end
def self.json_create(o)
+ Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please use Chef::Environment#from_hash")
from_hash(o)
end
@@ -260,7 +261,8 @@ class Chef
if File.exists?(js_file)
# from_json returns object.class => json_class in the JSON.
- Chef::JSONCompat.from_json(IO.read(js_file))
+ hash = Chef::JSONCompat.parse(IO.read(js_file))
+ from_hash(hash)
elsif File.exists?(rb_file)
environment = Chef::Environment.new
environment.name(name)
diff --git a/lib/chef/key.rb b/lib/chef/key.rb
index ba5613e35e..141a444d57 100644
--- a/lib/chef/key.rb
+++ b/lib/chef/key.rb
@@ -222,8 +222,9 @@ class Chef
Chef::Key.from_hash(Chef::JSONCompat.from_json(json))
end
- class << self
- alias_method :json_create, :from_json
+ def self.json_create(json)
+ Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please use Chef::Key#from_json or one of the load_by methods.")
+ Chef::Key.from_json(json)
end
def self.list_by_user(actor, inflate=false)
diff --git a/lib/chef/knife/core/object_loader.rb b/lib/chef/knife/core/object_loader.rb
index 69c2428bd4..063c192728 100644
--- a/lib/chef/knife/core/object_loader.rb
+++ b/lib/chef/knife/core/object_loader.rb
@@ -93,7 +93,7 @@ class Chef
if @klass == Chef::DataBagItem
r
else
- @klass.json_create(r)
+ @klass.from_hash(r)
end
when /\.rb$/
r = klass.new
diff --git a/lib/chef/node.rb b/lib/chef/node.rb
index d7b0bf5948..b9ef200e91 100644
--- a/lib/chef/node.rb
+++ b/lib/chef/node.rb
@@ -532,6 +532,7 @@ class Chef
# Create a Chef::Node from JSON
def self.json_create(o)
+ Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please use Chef::Node#from_hash")
from_hash(o)
end
diff --git a/lib/chef/org.rb b/lib/chef/org.rb
index 33a986dc3b..434113e315 100644
--- a/lib/chef/org.rb
+++ b/lib/chef/org.rb
@@ -124,8 +124,9 @@ class Chef
Chef::Org.from_hash(Chef::JSONCompat.from_json(json))
end
- class <<self
- alias_method :json_create, :from_json
+ def self.json_create(json)
+ Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please use Chef::Org#from_json or Chef::Org#load.")
+ Chef::Org.from_json(json)
end
def self.load(org_name)
diff --git a/lib/chef/rest.rb b/lib/chef/rest.rb
index 96a563e034..73cd0d68a9 100644
--- a/lib/chef/rest.rb
+++ b/lib/chef/rest.rb
@@ -59,6 +59,8 @@ class Chef
# HTTP GET request to http://localhost:4000/nodes
def initialize(url, client_name=Chef::Config[:node_name], signing_key_filename=Chef::Config[:client_key], options={})
+ Chef.log_deprecation("Chef::REST is deprecated. Please use Chef::ServerAPI, or investigate Ridley or ChefAPI.")
+
signing_key_filename = nil if chef_zero_uri?(url)
options = options.dup
diff --git a/lib/chef/role.rb b/lib/chef/role.rb
index fa76129af2..d607a1be98 100644
--- a/lib/chef/role.rb
+++ b/lib/chef/role.rb
@@ -171,6 +171,7 @@ class Chef
# Create a Chef::Role from JSON
def self.json_create(o)
+ Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please use Chef::Role#from_hash")
from_hash(o)
end
diff --git a/lib/chef/user.rb b/lib/chef/user.rb
index 37a104a537..bcbce76bf2 100644
--- a/lib/chef/user.rb
+++ b/lib/chef/user.rb
@@ -154,8 +154,9 @@ class Chef
Chef::User.from_hash(Chef::JSONCompat.from_json(json))
end
- class << self
- alias_method :json_create, :from_json
+ def self.json_create(json)
+ Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please use Chef::User#from_json or Chef::User#load.")
+ Chef::User.from_json(json)
end
def self.list(inflate=false)
diff --git a/lib/chef/user_v1.rb b/lib/chef/user_v1.rb
index 133087a089..bb594e3564 100644
--- a/lib/chef/user_v1.rb
+++ b/lib/chef/user_v1.rb
@@ -276,8 +276,9 @@ class Chef
Chef::UserV1.from_hash(Chef::JSONCompat.from_json(json))
end
- class << self
- alias_method :json_create, :from_json
+ def self.json_create(json)
+ Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please use Chef::UserV1#from_json or Chef::UserV1#load.")
+ Chef::UserV1.from_json(json)
end
def self.list(inflate=false)
diff --git a/spec/functional/rest_spec.rb b/spec/functional/rest_spec.rb
index e2d472c1d5..752e71d7e3 100644
--- a/spec/functional/rest_spec.rb
+++ b/spec/functional/rest_spec.rb
@@ -80,6 +80,7 @@ describe Chef::REST do
before do
Chef::Config[:node_name] = "webmonkey.example.com"
Chef::Config[:client_key] = CHEF_SPEC_DATA + "/ssl/private_key.pem"
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
end
before(:all) do
diff --git a/spec/unit/api_client_spec.rb b/spec/unit/api_client_spec.rb
index 1f313d7447..0451541f14 100644
--- a/spec/unit/api_client_spec.rb
+++ b/spec/unit/api_client_spec.rb
@@ -181,7 +181,7 @@ describe Chef::ApiClient do
end
let(:client) do
- Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(client_hash))
+ Chef::ApiClient.from_hash(Chef::JSONCompat.parse(Chef::JSONCompat.to_json(client_hash)))
end
it "should deserialize to a Chef::ApiClient object" do
diff --git a/spec/unit/data_bag_item_spec.rb b/spec/unit/data_bag_item_spec.rb
index 0329264718..5605763806 100644
--- a/spec/unit/data_bag_item_spec.rb
+++ b/spec/unit/data_bag_item_spec.rb
@@ -174,7 +174,7 @@ describe Chef::DataBagItem do
data_bag_item
}
- let(:deserial) { Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(data_bag_item)) }
+ let(:deserial) { Chef::DataBagItem.from_hash(Chef::JSONCompat.parse(Chef::JSONCompat.to_json(data_bag_item))) }
it "should deserialize to a Chef::DataBagItem object" do
diff --git a/spec/unit/data_bag_spec.rb b/spec/unit/data_bag_spec.rb
index 4e06a31911..8dc716460b 100644
--- a/spec/unit/data_bag_spec.rb
+++ b/spec/unit/data_bag_spec.rb
@@ -59,7 +59,7 @@ describe Chef::DataBag do
describe "deserialize" do
before(:each) do
@data_bag.name("mars_volta")
- @deserial = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(@data_bag))
+ @deserial = Chef::DataBag.from_hash(Chef::JSONCompat.parse(Chef::JSONCompat.to_json(@data_bag)))
end
it "should deserialize to a Chef::DataBag object" do
diff --git a/spec/unit/environment_spec.rb b/spec/unit/environment_spec.rb
index 04f54688de..ddbcf1d2b3 100644
--- a/spec/unit/environment_spec.rb
+++ b/spec/unit/environment_spec.rb
@@ -226,7 +226,7 @@ describe Chef::Environment do
"json_class" => "Chef::Environment",
"chef_type" => "environment",
}
- @environment = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(@data))
+ @environment = Chef::Environment.from_hash(Chef::JSONCompat.parse(Chef::JSONCompat.to_json(@data)))
end
it "should return a Chef::Environment" do
diff --git a/spec/unit/handler/json_file_spec.rb b/spec/unit/handler/json_file_spec.rb
index 76098e2522..d66c3ef120 100644
--- a/spec/unit/handler/json_file_spec.rb
+++ b/spec/unit/handler/json_file_spec.rb
@@ -53,7 +53,7 @@ describe Chef::Handler::JsonFile do
it "saves run status data to a file as JSON" do
expect(@handler).to receive(:build_report_dir)
@handler.run_report_unsafe(@run_status)
- reported_data = Chef::JSONCompat.from_json(@file_mock.string)
+ reported_data = Chef::JSONCompat.parse(@file_mock.string)
expect(reported_data["exception"]).to eq("Exception: Boy howdy!")
expect(reported_data["start_time"]).to eq(@expected_time.to_s)
expect(reported_data["end_time"]).to eq((@expected_time + 5).to_s)
diff --git a/spec/unit/json_compat_spec.rb b/spec/unit/json_compat_spec.rb
index 524b71f09a..042ac09069 100644
--- a/spec/unit/json_compat_spec.rb
+++ b/spec/unit/json_compat_spec.rb
@@ -20,10 +20,17 @@ require File.expand_path("../../spec_helper", __FILE__)
require "chef/json_compat"
describe Chef::JSONCompat do
+ before { Chef::Config[:treat_deprecation_warnings_as_errors] = false }
describe "#from_json with JSON containing an existing class" do
let(:json) { '{"json_class": "Chef::Role"}' }
+ it "emits a deprecation warning" do
+ Chef::Config[:treat_deprecation_warnings_as_errors] = true
+ expect { Chef::JSONCompat.from_json(json) }.to raise_error Chef::Exceptions::DeprecatedFeatureError,
+ /Auto inflation of JSON data is deprecated. Please use Chef::Role#from_hash/
+ end
+
it "returns an instance of the class instead of a Hash" do
expect(Chef::JSONCompat.from_json(json).class).to eq Chef::Role
end
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb
index dcee5f8eb5..59bd1a1081 100644
--- a/spec/unit/node_spec.rb
+++ b/spec/unit/node_spec.rb
@@ -1207,7 +1207,7 @@ describe Chef::Node do
it "should deserialize itself from json", :json => true do
node.from_file(File.expand_path("nodes/test.example.com.rb", CHEF_SPEC_DATA))
json = Chef::JSONCompat.to_json(node)
- serialized_node = Chef::JSONCompat.from_json(json)
+ serialized_node = Chef::Node.from_hash(Chef::JSONCompat.parse(json))
expect(serialized_node).to be_a_kind_of(Chef::Node)
expect(serialized_node.name).to eql(node.name)
expect(serialized_node.chef_environment).to eql(node.chef_environment)
@@ -1246,7 +1246,7 @@ describe Chef::Node do
end
it "parses policyfile attributes from JSON" do
- round_tripped_node = Chef::Node.json_create(node.for_json)
+ round_tripped_node = Chef::Node.from_hash(node.for_json)
expect(round_tripped_node.policy_name).to eq("my-application")
expect(round_tripped_node.policy_group).to eq("staging")
diff --git a/spec/unit/rest_spec.rb b/spec/unit/rest_spec.rb
index 8e6a3be79c..86572c7034 100644
--- a/spec/unit/rest_spec.rb
+++ b/spec/unit/rest_spec.rb
@@ -74,6 +74,7 @@ describe Chef::REST do
before(:each) do
Chef::Log.init(log_stringio)
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
end
it "should have content length validation middleware after compressor middleware" do
@@ -92,6 +93,12 @@ describe Chef::REST do
Chef::REST.new(base_url, nil, nil, options)
end
+ it "emits a deprecation warning" do
+ Chef::Config[:treat_deprecation_warnings_as_errors] = true
+ expect { Chef::REST.new(base_url) }.to raise_error Chef::Exceptions::DeprecatedFeatureError,
+ /Chef::REST is deprecated. Please use Chef::ServerAPI, or investigate Ridley or ChefAPI./
+ end
+
context "when created with a chef zero URL" do
let(:url) { "chefzero://localhost:1" }