diff options
Diffstat (limited to 'chef')
89 files changed, 194 insertions, 124 deletions
diff --git a/chef/lib/chef/api_client.rb b/chef/lib/chef/api_client.rb index 0dd7ee8042..d7eed5a16b 100644 --- a/chef/lib/chef/api_client.rb +++ b/chef/lib/chef/api_client.rb @@ -24,7 +24,7 @@ require 'chef/couchdb' require 'chef/certificate' require 'chef/index_queue' require 'extlib' -require 'json' +require 'chef/json' class Chef class ApiClient diff --git a/chef/lib/chef/application/client.rb b/chef/lib/chef/application/client.rb index 4d8addd9af..b8df754ece 100644 --- a/chef/lib/chef/application/client.rb +++ b/chef/lib/chef/application/client.rb @@ -181,7 +181,7 @@ class Chef::Application::Client < Chef::Application end begin - @chef_client_json = JSON.parse(json_io.read) + @chef_client_json = Chef::JSON.from_json(json_io.read) json_io.close unless json_io.closed? rescue JSON::ParserError => error Chef::Application.fatal!("Could not parse the provided JSON file (#{Chef::Config[:json_attribs]})!: " + error.message, 2) diff --git a/chef/lib/chef/application/solo.rb b/chef/lib/chef/application/solo.rb index e1458195b8..35887d0d70 100644 --- a/chef/lib/chef/application/solo.rb +++ b/chef/lib/chef/application/solo.rb @@ -145,7 +145,7 @@ class Chef::Application::Solo < Chef::Application end begin - @chef_solo_json = JSON.parse(json_io.read) + @chef_solo_json = Chef::JSON.from_json(json_io.read) json_io.close unless json_io.closed? rescue JSON::ParserError => error Chef::Application.fatal!("Could not parse the provided JSON file (#{Chef::Config[:json_attribs]})!: " + error.message, 2) diff --git a/chef/lib/chef/cookbook/metadata.rb b/chef/lib/chef/cookbook/metadata.rb index 2f31893ceb..79ef860b89 100644 --- a/chef/lib/chef/cookbook/metadata.rb +++ b/chef/lib/chef/cookbook/metadata.rb @@ -430,12 +430,12 @@ class Chef end def self.from_json(string) - o = JSON.parse(string) + o = Chef::JSON.from_json(string) self.from_hash(o) end def from_json(string) - o = JSON.parse(string) + o = Chef::JSON.from_json(string) from_hash(o) end diff --git a/chef/lib/chef/couchdb.rb b/chef/lib/chef/couchdb.rb index 27f4d2dc45..3dfd8ccbd8 100644 --- a/chef/lib/chef/couchdb.rb +++ b/chef/lib/chef/couchdb.rb @@ -21,7 +21,7 @@ require 'chef/config' require 'chef/rest' require 'chef/log' require 'digest/sha2' -require 'json' +require 'chef/json' # We want to fail on create if uuidtools isn't installed begin diff --git a/chef/lib/chef/data_bag.rb b/chef/lib/chef/data_bag.rb index 512293e717..f14812cf40 100644 --- a/chef/lib/chef/data_bag.rb +++ b/chef/lib/chef/data_bag.rb @@ -25,7 +25,7 @@ require 'chef/couchdb' require 'chef/data_bag_item' require 'chef/index_queue' require 'extlib' -require 'json' +require 'chef/json' class Chef class DataBag diff --git a/chef/lib/chef/data_bag_item.rb b/chef/lib/chef/data_bag_item.rb index d5fba01563..15d046efeb 100644 --- a/chef/lib/chef/data_bag_item.rb +++ b/chef/lib/chef/data_bag_item.rb @@ -25,7 +25,7 @@ require 'chef/couchdb' require 'chef/index_queue' require 'chef/data_bag' require 'extlib' -require 'json' +require 'chef/json' class Chef class DataBagItem diff --git a/chef/lib/chef/file_cache.rb b/chef/lib/chef/file_cache.rb index 9208f53d92..f558e67e9e 100644 --- a/chef/lib/chef/file_cache.rb +++ b/chef/lib/chef/file_cache.rb @@ -18,7 +18,7 @@ require 'chef/mixin/params_validate' require 'chef/mixin/create_path' require 'chef/exceptions' -require 'json' +require 'chef/json' require 'fileutils' class Chef diff --git a/chef/lib/chef/handler/json_file.rb b/chef/lib/chef/handler/json_file.rb index 580ede671b..8bac5232d0 100644 --- a/chef/lib/chef/handler/json_file.rb +++ b/chef/lib/chef/handler/json_file.rb @@ -41,7 +41,7 @@ class Chef build_report_dir savetime = Time.now.strftime("%Y%m%d%H%M%S") File.open(File.join(config[:path], "chef-run-report-#{savetime}.json"), "w") do |file| - file.puts JSON.pretty_generate(data) + file.puts Chef::JSON.to_json_pretty(data) end end diff --git a/chef/lib/chef/index_queue/consumer.rb b/chef/lib/chef/index_queue/consumer.rb index b7be42ed76..18e8d3b8fc 100644 --- a/chef/lib/chef/index_queue/consumer.rb +++ b/chef/lib/chef/index_queue/consumer.rb @@ -56,7 +56,7 @@ class Chef alias :start :run def call_action_for_message(message) - amqp_payload = JSON.parse(message[:payload], :create_additions => false, :max_nesting => false) + amqp_payload = Chef::JSON.from_json(message[:payload], :create_additions => false, :max_nesting => false) action = amqp_payload["action"].to_sym app_payload = amqp_payload["payload"] assert_method_whitelisted(action) @@ -73,4 +73,4 @@ class Chef end end -end
\ No newline at end of file +end diff --git a/chef/lib/chef/index_queue/indexable.rb b/chef/lib/chef/index_queue/indexable.rb index c01bb0f748..03fb0916f1 100644 --- a/chef/lib/chef/index_queue/indexable.rb +++ b/chef/lib/chef/index_queue/indexable.rb @@ -1,6 +1,8 @@ # # Author:: Daniel DeLeo (<dan@kallistec.com>) +# Author:: Seth Falcon (<seth@opscode.com>) # Copyright:: Copyright (c) 2009 Daniel DeLeo +# Copyright:: Copyright (c) 2010 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,6 +17,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +require 'chef/json' class Chef module IndexQueue @@ -67,7 +70,8 @@ class Chef object_with_metadata = with_indexer_metadata(metadata) obj_id = object_with_metadata["id"] AmqpClient.instance.queue_for_object(obj_id) do |queue| - queue.publish({:action => :add, :payload => self.with_indexer_metadata(metadata)}.to_json) + obj = {:action => :add, :payload => self.with_indexer_metadata(metadata)} + queue.publish(Chef::JSON.to_json(obj)) end end @@ -76,7 +80,8 @@ class Chef object_with_metadata = with_indexer_metadata(metadata) obj_id = object_with_metadata["id"] AmqpClient.instance.queue_for_object(obj_id) do |queue| - queue.publish({:action => :delete, :payload => self.with_indexer_metadata(metadata)}.to_json) + obj = {:action => :delete, :payload => self.with_indexer_metadata(metadata)} + queue.publish(Chef::JSON.to_json(obj)) end end diff --git a/chef/lib/chef/json.rb b/chef/lib/chef/json.rb new file mode 100644 index 0000000000..24020356ba --- /dev/null +++ b/chef/lib/chef/json.rb @@ -0,0 +1,52 @@ +# +# Author:: Tim Hinderliter (<tim@opscode.com>) +# Copyright:: Copyright (c) 2010 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Wrapper class for interacting with JSON. + +require 'json' + +class Chef + class JSON + JSON_MAX_NESTING = 1000 + + class <<self + # See CHEF-1292/PL-538. Increase the max nesting for JSON, which defaults + # to 19, and isn't enough for some (for example, a Node within a Node) + # structures. + def opts_add_max_nesting(opts) + if opts.nil? || !opts.has_key?(:max_nesting) + opts = opts.nil? ? Hash.new : opts.clone + opts[:max_nesting] = JSON_MAX_NESTING + end + opts + end + + # Just call the JSON gem's parse method with a modified :max_nesting field + def from_json(source, opts = {}) + ::JSON.parse(source, opts_add_max_nesting(opts)) + end + + def to_json(obj, opts = nil) + obj.to_json(opts_add_max_nesting(opts)) + end + + def to_json_pretty(obj, opts = nil) + ::JSON.pretty_generate(obj, opts_add_max_nesting(opts)) + end + end + end +end diff --git a/chef/lib/chef/knife.rb b/chef/lib/chef/knife.rb index 1351b77326..d284ea622f 100644 --- a/chef/lib/chef/knife.rb +++ b/chef/lib/chef/knife.rb @@ -289,7 +289,7 @@ class Chef def output(data) case config[:format] when "json", nil - stdout.puts JSON.pretty_generate(data) + stdout.puts Chef::JSON.to_json_pretty(data) when "yaml" require 'yaml' stdout.puts YAML::dump(data) @@ -335,7 +335,7 @@ class Chef end def edit_data(data, parse_output=true) - output = JSON.pretty_generate(data) + output = Chef::JSON.to_json_pretty(data) if (!config[:no_editor]) filename = "knife-edit-" @@ -353,7 +353,7 @@ class Chef File.unlink(filename) end - parse_output ? JSON.parse(output) : output + parse_output ? Chef::JSON.from_json(output) : output end def confirm(question, append_instructions=true) @@ -404,7 +404,7 @@ class Chef case from_file when /\.(js|json)$/ - JSON.parse(IO.read(filename)) + Chef::JSON.from_json(IO.read(filename)) when /\.rb$/ r = klass.new r.from_file(filename) @@ -434,8 +434,8 @@ class Chef # We wouldn't have to do these shenanigans if all the editable objects # implemented to_hash, or if to_json against a hash returned a string # with stable key order. - object_parsed_again = JSON.parse(object.to_json, :create_additions => false) - output_parsed_again = JSON.parse(output.to_json, :create_additions => false) + object_parsed_again = Chef::JSON.from_json(Chef::JSON.to_json(object), :create_additions => false) + output_parsed_again = Chef::JSON.from_json(Chef::JSON.to_json(output), :create_additions => false) if object_parsed_again != output_parsed_again output.save self.msg("Saved #{output}") diff --git a/chef/lib/chef/knife/bootstrap.rb b/chef/lib/chef/knife/bootstrap.rb index 968c69076f..37a88f26a8 100644 --- a/chef/lib/chef/knife/bootstrap.rb +++ b/chef/lib/chef/knife/bootstrap.rb @@ -17,7 +17,7 @@ # require 'chef/knife' -require 'json' +require 'chef/json' require 'tempfile' require 'erubis' diff --git a/chef/lib/chef/knife/client_bulk_delete.rb b/chef/lib/chef/knife/client_bulk_delete.rb index 9f7e0c8ace..a856c34dc3 100644 --- a/chef/lib/chef/knife/client_bulk_delete.rb +++ b/chef/lib/chef/knife/client_bulk_delete.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/api_client' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/client_create.rb b/chef/lib/chef/knife/client_create.rb index d25e77f4e2..963fe7bc60 100644 --- a/chef/lib/chef/knife/client_create.rb +++ b/chef/lib/chef/knife/client_create.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/api_client' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/client_delete.rb b/chef/lib/chef/knife/client_delete.rb index 2815369e5c..fa25b4188a 100644 --- a/chef/lib/chef/knife/client_delete.rb +++ b/chef/lib/chef/knife/client_delete.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/api_client' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/client_edit.rb b/chef/lib/chef/knife/client_edit.rb index 293e2ae904..cac55956de 100644 --- a/chef/lib/chef/knife/client_edit.rb +++ b/chef/lib/chef/knife/client_edit.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/api_client' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/client_list.rb b/chef/lib/chef/knife/client_list.rb index 1a0942ae4a..43ee6e4632 100644 --- a/chef/lib/chef/knife/client_list.rb +++ b/chef/lib/chef/knife/client_list.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/api_client' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/client_reregister.rb b/chef/lib/chef/knife/client_reregister.rb index e865b8bf66..257b72da39 100644 --- a/chef/lib/chef/knife/client_reregister.rb +++ b/chef/lib/chef/knife/client_reregister.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/api_client' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/client_show.rb b/chef/lib/chef/knife/client_show.rb index 7c84b6cfab..b8078ccf78 100644 --- a/chef/lib/chef/knife/client_show.rb +++ b/chef/lib/chef/knife/client_show.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/api_client' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/cookbook_create.rb b/chef/lib/chef/knife/cookbook_create.rb index 3098a27d9b..aed540ba6b 100644 --- a/chef/lib/chef/knife/cookbook_create.rb +++ b/chef/lib/chef/knife/cookbook_create.rb @@ -17,7 +17,7 @@ # require 'chef/knife' -require 'json' +require 'chef/json' require 'uri' require 'chef/mixin/shell_out' diff --git a/chef/lib/chef/knife/cookbook_list.rb b/chef/lib/chef/knife/cookbook_list.rb index 9d201742d4..857431cbbc 100644 --- a/chef/lib/chef/knife/cookbook_list.rb +++ b/chef/lib/chef/knife/cookbook_list.rb @@ -17,7 +17,7 @@ # require 'chef/knife' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/cookbook_metadata.rb b/chef/lib/chef/knife/cookbook_metadata.rb index 8182e57502..f15f47b7d3 100644 --- a/chef/lib/chef/knife/cookbook_metadata.rb +++ b/chef/lib/chef/knife/cookbook_metadata.rb @@ -69,7 +69,7 @@ class Chef md.from_file(file) json_file = File.join(File.dirname(file), 'metadata.json') File.open(json_file, "w") do |f| - f.write(JSON.pretty_generate(md)) + f.write(Chef::JSON.to_json_pretty(md)) end generated = true Chef::Log.debug("Generated #{json_file}") diff --git a/chef/lib/chef/knife/cookbook_show.rb b/chef/lib/chef/knife/cookbook_show.rb index 7537c97cca..2b858e1569 100644 --- a/chef/lib/chef/knife/cookbook_show.rb +++ b/chef/lib/chef/knife/cookbook_show.rb @@ -17,7 +17,7 @@ # require 'chef/knife' -require 'json' +require 'chef/json' require 'uri' class Chef diff --git a/chef/lib/chef/knife/cookbook_site_share.rb b/chef/lib/chef/knife/cookbook_site_share.rb index 3a2f7e5ec3..356902eed2 100644 --- a/chef/lib/chef/knife/cookbook_site_share.rb +++ b/chef/lib/chef/knife/cookbook_site_share.rb @@ -85,7 +85,7 @@ class Chef :cookbook => category_string }) - res = JSON.parse(http_resp.body) + res = Chef::JSON.from_json(http_resp.body) if http_resp.code.to_i != 201 if res['error_messages'] if res['error_messages'][0] =~ /Version already exists/ diff --git a/chef/lib/chef/knife/cookbook_site_unshare.rb b/chef/lib/chef/knife/cookbook_site_unshare.rb index e870dbb814..9469cb073a 100644 --- a/chef/lib/chef/knife/cookbook_site_unshare.rb +++ b/chef/lib/chef/knife/cookbook_site_unshare.rb @@ -18,6 +18,7 @@ # require 'chef/knife' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/data_bag_from_file.rb b/chef/lib/chef/knife/data_bag_from_file.rb index 2c8417a4f9..6a513e5dc5 100644 --- a/chef/lib/chef/knife/data_bag_from_file.rb +++ b/chef/lib/chef/knife/data_bag_from_file.rb @@ -19,6 +19,7 @@ require 'chef/knife' require 'chef/data_bag' require 'chef/data_bag_item' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/ec2_instance_data.rb b/chef/lib/chef/knife/ec2_instance_data.rb index b69a2330c1..43265b5cc2 100644 --- a/chef/lib/chef/knife/ec2_instance_data.rb +++ b/chef/lib/chef/knife/ec2_instance_data.rb @@ -17,7 +17,7 @@ # require 'chef/knife' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/ec2_server_create.rb b/chef/lib/chef/knife/ec2_server_create.rb index 3311786817..ae9c108acd 100644 --- a/chef/lib/chef/knife/ec2_server_create.rb +++ b/chef/lib/chef/knife/ec2_server_create.rb @@ -18,7 +18,7 @@ require 'socket' require 'chef/knife' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/ec2_server_delete.rb b/chef/lib/chef/knife/ec2_server_delete.rb index 161c558b37..1f1d45c55c 100644 --- a/chef/lib/chef/knife/ec2_server_delete.rb +++ b/chef/lib/chef/knife/ec2_server_delete.rb @@ -17,7 +17,7 @@ # require 'chef/knife' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/ec2_server_list.rb b/chef/lib/chef/knife/ec2_server_list.rb index 0711cbcf6a..7dabc4688d 100644 --- a/chef/lib/chef/knife/ec2_server_list.rb +++ b/chef/lib/chef/knife/ec2_server_list.rb @@ -17,7 +17,7 @@ # require 'chef/knife' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/node_bulk_delete.rb b/chef/lib/chef/knife/node_bulk_delete.rb index 1958c63836..621b8ae0ec 100644 --- a/chef/lib/chef/knife/node_bulk_delete.rb +++ b/chef/lib/chef/knife/node_bulk_delete.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/node' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/node_create.rb b/chef/lib/chef/knife/node_create.rb index 4f14d21ab8..004fea7df1 100644 --- a/chef/lib/chef/knife/node_create.rb +++ b/chef/lib/chef/knife/node_create.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/node' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/node_delete.rb b/chef/lib/chef/knife/node_delete.rb index 03113b6003..eef13a46c6 100644 --- a/chef/lib/chef/knife/node_delete.rb +++ b/chef/lib/chef/knife/node_delete.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/node' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/node_edit.rb b/chef/lib/chef/knife/node_edit.rb index 5460af5ab0..4ca64c6a59 100644 --- a/chef/lib/chef/knife/node_edit.rb +++ b/chef/lib/chef/knife/node_edit.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/node' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/node_from_file.rb b/chef/lib/chef/knife/node_from_file.rb index e644ca17a5..0020827d4e 100644 --- a/chef/lib/chef/knife/node_from_file.rb +++ b/chef/lib/chef/knife/node_from_file.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/node' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/node_list.rb b/chef/lib/chef/knife/node_list.rb index 6371b655b6..4a916a3096 100644 --- a/chef/lib/chef/knife/node_list.rb +++ b/chef/lib/chef/knife/node_list.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/node' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/node_run_list_add.rb b/chef/lib/chef/knife/node_run_list_add.rb index 9e1602a1e2..41bcf93670 100644 --- a/chef/lib/chef/knife/node_run_list_add.rb +++ b/chef/lib/chef/knife/node_run_list_add.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/node' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/node_run_list_remove.rb b/chef/lib/chef/knife/node_run_list_remove.rb index 7bdfc9a66b..a40488abf9 100644 --- a/chef/lib/chef/knife/node_run_list_remove.rb +++ b/chef/lib/chef/knife/node_run_list_remove.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/node' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/node_show.rb b/chef/lib/chef/knife/node_show.rb index 971354ba66..f9e8393e96 100644 --- a/chef/lib/chef/knife/node_show.rb +++ b/chef/lib/chef/knife/node_show.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/node' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/rackspace_server_create.rb b/chef/lib/chef/knife/rackspace_server_create.rb index 64e16b02f9..5c2347b8f0 100644 --- a/chef/lib/chef/knife/rackspace_server_create.rb +++ b/chef/lib/chef/knife/rackspace_server_create.rb @@ -17,7 +17,7 @@ # require 'chef/knife' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/rackspace_server_delete.rb b/chef/lib/chef/knife/rackspace_server_delete.rb index e6b133f7c6..db9f6b021a 100644 --- a/chef/lib/chef/knife/rackspace_server_delete.rb +++ b/chef/lib/chef/knife/rackspace_server_delete.rb @@ -17,7 +17,7 @@ # require 'chef/knife' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/rackspace_server_list.rb b/chef/lib/chef/knife/rackspace_server_list.rb index bae3548cc6..ea0a38f3ab 100644 --- a/chef/lib/chef/knife/rackspace_server_list.rb +++ b/chef/lib/chef/knife/rackspace_server_list.rb @@ -17,7 +17,7 @@ # require 'chef/knife' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/role_bulk_delete.rb b/chef/lib/chef/knife/role_bulk_delete.rb index 1e4b533c36..95268c799c 100644 --- a/chef/lib/chef/knife/role_bulk_delete.rb +++ b/chef/lib/chef/knife/role_bulk_delete.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/node' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/role_create.rb b/chef/lib/chef/knife/role_create.rb index e81b883fdb..d222c0e2ac 100644 --- a/chef/lib/chef/knife/role_create.rb +++ b/chef/lib/chef/knife/role_create.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/role' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/role_delete.rb b/chef/lib/chef/knife/role_delete.rb index 14e74ba110..989e1eec42 100644 --- a/chef/lib/chef/knife/role_delete.rb +++ b/chef/lib/chef/knife/role_delete.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/role' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/role_edit.rb b/chef/lib/chef/knife/role_edit.rb index 78cad69471..48194bde9b 100644 --- a/chef/lib/chef/knife/role_edit.rb +++ b/chef/lib/chef/knife/role_edit.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/role' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/role_from_file.rb b/chef/lib/chef/knife/role_from_file.rb index a12589c4df..ffa4aac6e5 100644 --- a/chef/lib/chef/knife/role_from_file.rb +++ b/chef/lib/chef/knife/role_from_file.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/role' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/role_list.rb b/chef/lib/chef/knife/role_list.rb index c617d4aa24..a02979fae4 100644 --- a/chef/lib/chef/knife/role_list.rb +++ b/chef/lib/chef/knife/role_list.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/node' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/role_show.rb b/chef/lib/chef/knife/role_show.rb index 952260ae27..14e34c8d0d 100644 --- a/chef/lib/chef/knife/role_show.rb +++ b/chef/lib/chef/knife/role_show.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/node' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/slicehost_images_list.rb b/chef/lib/chef/knife/slicehost_images_list.rb index 1adf6edf6e..af9ad827d2 100644 --- a/chef/lib/chef/knife/slicehost_images_list.rb +++ b/chef/lib/chef/knife/slicehost_images_list.rb @@ -17,7 +17,7 @@ # require 'chef/knife' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/slicehost_server_create.rb b/chef/lib/chef/knife/slicehost_server_create.rb index 086fd387bc..19f802449b 100644 --- a/chef/lib/chef/knife/slicehost_server_create.rb +++ b/chef/lib/chef/knife/slicehost_server_create.rb @@ -17,7 +17,7 @@ # require 'chef/knife' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/slicehost_server_delete.rb b/chef/lib/chef/knife/slicehost_server_delete.rb index 2d065ea4af..e163a3ae61 100644 --- a/chef/lib/chef/knife/slicehost_server_delete.rb +++ b/chef/lib/chef/knife/slicehost_server_delete.rb @@ -17,7 +17,7 @@ # require 'chef/knife' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/slicehost_server_list.rb b/chef/lib/chef/knife/slicehost_server_list.rb index 17920094c3..64a16b11b1 100644 --- a/chef/lib/chef/knife/slicehost_server_list.rb +++ b/chef/lib/chef/knife/slicehost_server_list.rb @@ -17,7 +17,7 @@ # require 'chef/knife' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/terremark_server_create.rb b/chef/lib/chef/knife/terremark_server_create.rb index c32fd9315d..03136ab8c7 100644 --- a/chef/lib/chef/knife/terremark_server_create.rb +++ b/chef/lib/chef/knife/terremark_server_create.rb @@ -17,7 +17,7 @@ # require 'chef/knife' -require 'json' +require 'chef/json' require 'tempfile' class Chef diff --git a/chef/lib/chef/knife/terremark_server_delete.rb b/chef/lib/chef/knife/terremark_server_delete.rb index aeb195c70d..8b3475c6fc 100644 --- a/chef/lib/chef/knife/terremark_server_delete.rb +++ b/chef/lib/chef/knife/terremark_server_delete.rb @@ -17,7 +17,7 @@ # require 'chef/knife' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/terremark_server_list.rb b/chef/lib/chef/knife/terremark_server_list.rb index 20dadbedff..3e90d4cfca 100644 --- a/chef/lib/chef/knife/terremark_server_list.rb +++ b/chef/lib/chef/knife/terremark_server_list.rb @@ -17,7 +17,7 @@ # require 'chef/knife' -require 'json' +require 'chef/json' require 'tempfile' class Chef diff --git a/chef/lib/chef/node.rb b/chef/lib/chef/node.rb index a0aed92258..6bb131a75f 100644 --- a/chef/lib/chef/node.rb +++ b/chef/lib/chef/node.rb @@ -32,7 +32,7 @@ require 'chef/run_list' require 'chef/node/attribute' require 'chef/index_queue' require 'extlib' -require 'json' +require 'chef/json' class Chef class Node @@ -596,6 +596,5 @@ class Chef self.from_file(attribute_filename) self end - end end diff --git a/chef/lib/chef/openid_registration.rb b/chef/lib/chef/openid_registration.rb index 82bee0798e..a97b34d1bc 100644 --- a/chef/lib/chef/openid_registration.rb +++ b/chef/lib/chef/openid_registration.rb @@ -21,7 +21,7 @@ require 'chef/mixin/params_validate' require 'chef/couchdb' require 'chef/index_queue' require 'digest/sha1' -require 'json' +require 'chef/json' class Chef class OpenIDRegistration diff --git a/chef/lib/chef/provider/deploy/revision.rb b/chef/lib/chef/provider/deploy/revision.rb index 00a30515ba..6b5848827a 100644 --- a/chef/lib/chef/provider/deploy/revision.rb +++ b/chef/lib/chef/provider/deploy/revision.rb @@ -1,6 +1,9 @@ # # Author:: Daniel DeLeo (<dan@kallistec.com>) +# Author:: Tim Hinderliter (<tim@opscode.com>) +# Author:: Seth Falcon (<seth@opscode.com>) # Copyright:: Copyright (c) 2009 Daniel DeLeo +# Copyright:: Copyright (c) 2010 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +19,10 @@ # limitations under the License. # +require 'chef/provider' +require 'chef/provider/deploy' +require 'chef/json' + class Chef class Provider class Deploy @@ -56,7 +63,7 @@ class Chef def load_cache begin - JSON.parse(Chef::FileCache.load("revision-deploys/#{new_resource.name}")) + Chef::JSON.from_json(Chef::FileCache.load("revision-deploys/#{new_resource.name}")) rescue Chef::Exceptions::FileNotFound sorted_releases_from_filesystem end diff --git a/chef/lib/chef/rest.rb b/chef/lib/chef/rest.rb index b721a1bd27..052fa2a513 100644 --- a/chef/lib/chef/rest.rb +++ b/chef/lib/chef/rest.rb @@ -22,7 +22,7 @@ require 'net/https' require 'uri' -require 'json' +require 'chef/json' require 'tempfile' require 'chef/api_client' require 'chef/rest/auth_credentials' @@ -162,7 +162,7 @@ class Chef # # Will return the body of the response on success. def run_request(method, url, headers={}, data=false, limit=nil, raw=false) - json_body = data ? data.to_json : nil + json_body = data ? Chef::JSON.to_json(data) : nil headers = build_headers(method, url, headers, json_body, raw) tf = nil @@ -180,7 +180,7 @@ class Chef if res.kind_of?(Net::HTTPSuccess) if res['content-type'] =~ /json/ response_body = res.body.chomp - JSON.parse(response_body) + Chef::JSON.from_json(response_body) else if method == :HEAD true @@ -196,7 +196,7 @@ class Chef false else if res['content-type'] =~ /json/ - exception = JSON.parse(res.body) + exception = Chef::JSON.from_json(res.body) msg = "HTTP Request Returned #{res.code} #{res.message}: " msg << (exception["error"].respond_to?(:join) ? exception["error"].join(", ") : exception["error"].to_s) Chef::Log.warn(msg) @@ -208,7 +208,7 @@ class Chef # Runs an HTTP request to a JSON API. File Download not supported. def api_request(method, url, headers={}, data=false) - json_body = data ? data.to_json : nil + json_body = data ? Chef::JSON.to_json(data) : nil headers = build_headers(method, url, headers, json_body) retriable_rest_request(method, url, json_body, headers) do |rest_request| @@ -216,7 +216,7 @@ class Chef if response.kind_of?(Net::HTTPSuccess) if response['content-type'] =~ /json/ - JSON.parse(response.body.chomp) + Chef::JSON.from_json(response.body.chomp) else Chef::Log.warn("Expected JSON response, but got content-type '#{response['content-type']}'") response.body @@ -225,7 +225,7 @@ class Chef follow_redirect {api_request(:GET, create_url(redirect_location))} else if response['content-type'] =~ /json/ - exception = JSON.parse(response.body) + exception = Chef::JSON.from_json(response.body) msg = "HTTP Request Returned #{response.code} #{response.message}: " msg << (exception["error"].respond_to?(:join) ? exception["error"].join(", ") : exception["error"].to_s) Chef::Log.warn(msg) diff --git a/chef/lib/chef/role.rb b/chef/lib/chef/role.rb index bf0aa32b7a..802ad28752 100644 --- a/chef/lib/chef/role.rb +++ b/chef/lib/chef/role.rb @@ -25,7 +25,7 @@ require 'chef/couchdb' require 'chef/run_list' require 'chef/index_queue' require 'extlib' -require 'json' +require 'chef/json' class Chef class Role @@ -255,7 +255,7 @@ class Chef rb_file = File.join(Chef::Config[:role_path], "#{name}.rb") if File.exists?(js_file) || force == "json" - JSON.parse(IO.read(js_file)) + Chef::JSON.from_json(IO.read(js_file)) elsif File.exists?(rb_file) || force == "ruby" role = Chef::Role.new role.name(name) diff --git a/chef/lib/chef/shef.rb b/chef/lib/chef/shef.rb index e8a224f1e2..2710e7fbb1 100644 --- a/chef/lib/chef/shef.rb +++ b/chef/lib/chef/shef.rb @@ -15,17 +15,18 @@ # limitations under the License. # -require "singleton" -require "pp" -require "etc" -require "mixlib/cli" +require 'singleton' +require 'pp' +require 'etc' +require 'mixlib/cli' require 'chef/version' -require "chef/client" -require "chef/config" +require 'chef/client' +require 'chef/config' -require "chef/shef/shef_session" -require "chef/shef/ext" +require 'chef/shef/shef_session' +require 'chef/shef/ext' +require 'chef/json' # = Shef # Shef is Chef in an IRB session. Shef can interact with a Chef server via the @@ -163,7 +164,7 @@ module Shef end begin - @json_attribs = JSON.parse(json_io.read) + @json_attribs = Chef::JSON.from_json(json_io.read) rescue JSON::ParserError => error fatal!("Could not parse the provided JSON file (#{Chef::Config[:json_attribs]})!: " + error.message, 2) end @@ -322,4 +323,4 @@ FOOTER end -end
\ No newline at end of file +end diff --git a/chef/lib/chef/shef/ext.rb b/chef/lib/chef/shef/ext.rb index a601e86786..6c5116f4a5 100644 --- a/chef/lib/chef/shef/ext.rb +++ b/chef/lib/chef/shef/ext.rb @@ -23,6 +23,7 @@ require 'chef/version' require 'chef/shef/shef_session' require 'chef/shef/model_wrapper' require 'chef/shef/shef_rest' +require 'chef/json' module Shef module Extensions @@ -327,13 +328,13 @@ E edited_data = Tempfile.open([filename, ".js"]) do |tempfile| tempfile.sync = true - tempfile.puts object.to_json + tempfile.puts Chef::JSON.to_json(object) system("#{Shef.editor.to_s} #{tempfile.path}") tempfile.rewind tempfile.read end - JSON.parse(edited_data) + Chef::JSON.from_json(edited_data) end desc "Find and edit API clients" diff --git a/chef/lib/chef/tasks/chef_repo.rake b/chef/lib/chef/tasks/chef_repo.rake index cae90c7e67..271a57ee6a 100644 --- a/chef/lib/chef/tasks/chef_repo.rake +++ b/chef/lib/chef/tasks/chef_repo.rake @@ -17,7 +17,7 @@ # require 'rubygems' -require 'json' +require 'chef/json' require 'chef' require 'chef/role' require 'chef/cookbook/metadata' diff --git a/chef/lib/chef/webui_user.rb b/chef/lib/chef/webui_user.rb index c582722fe8..46932d0f69 100644 --- a/chef/lib/chef/webui_user.rb +++ b/chef/lib/chef/webui_user.rb @@ -22,7 +22,7 @@ require 'chef/mixin/params_validate' require 'chef/couchdb' require 'chef/index_queue' require 'digest/sha1' -require 'json' +require 'chef/json' class Chef diff --git a/chef/spec/functional/tiny_server_spec.rb b/chef/spec/functional/tiny_server_spec.rb index 59a5f16501..370698f0c7 100644 --- a/chef/spec/functional/tiny_server_spec.rb +++ b/chef/spec/functional/tiny_server_spec.rb @@ -54,7 +54,7 @@ describe TinyServer::API do response[0].should == 404 response[1].should == {'Content-Type' => 'application/json'} response[2].should be_a_kind_of(String) - response_obj = JSON.parse(response[2]) + response_obj = Chef::JSON.from_json(response[2]) response_obj["message"].should == "no data matches the request for /no_such_thing" response_obj["available_routes"].should == {"GET"=>[], "PUT"=>[], "POST"=>[], "DELETE"=>[]} response_obj["request"].should == {"REQUEST_METHOD"=>"GET", "REQUEST_URI"=>"/no_such_thing"} diff --git a/chef/spec/lib/chef/resource/zen_master.rb b/chef/spec/lib/chef/resource/zen_master.rb index b3c2c7712a..2ecacd3f6a 100644 --- a/chef/spec/lib/chef/resource/zen_master.rb +++ b/chef/spec/lib/chef/resource/zen_master.rb @@ -1,6 +1,6 @@ # # Author:: Adam Jacob (<adam@opscode.com>) -# Copyright:: Copyright (c) 2008 Opscode, Inc. +# Copyright:: Copyright (c) 2008, 2010 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +16,9 @@ # limitations under the License. # +require 'chef/knife' +require 'chef/json' + class Chef class Resource class ZenMaster < Chef::Resource diff --git a/chef/spec/tiny_server.rb b/chef/spec/tiny_server.rb index 99b2887251..18b593ec8e 100644 --- a/chef/spec/tiny_server.rb +++ b/chef/spec/tiny_server.rb @@ -20,7 +20,7 @@ require 'rubygems' require 'rack' require 'thin' require 'singleton' -require 'json' +require 'chef/json' require 'open-uri' module TinyServer diff --git a/chef/spec/unit/api_client_spec.rb b/chef/spec/unit/api_client_spec.rb index 4b73d80575..eba41310c4 100644 --- a/chef/spec/unit/api_client_spec.rb +++ b/chef/spec/unit/api_client_spec.rb @@ -157,7 +157,7 @@ describe Chef::ApiClient do @client.public_key("crowes") @client.private_key("monkeypants") @client.admin(true) - @deserial = JSON.parse(@client.to_json) + @deserial = Chef::JSON.from_json(@client.to_json) end it "should deserialize to a Chef::ApiClient object" do diff --git a/chef/spec/unit/application/client_spec.rb b/chef/spec/unit/application/client_spec.rb index e92b2458ef..d5daec07d4 100644 --- a/chef/spec/unit/application/client_spec.rb +++ b/chef/spec/unit/application/client_spec.rb @@ -99,7 +99,7 @@ describe Chef::Application::Client, "reconfigure" do end it "should parse the json out of the file" do - JSON.should_receive(:parse).with(@json.read) + Chef::JSON.should_receive(:from_json).with(@json.read) @app.reconfigure end end @@ -109,7 +109,7 @@ describe Chef::Application::Client, "reconfigure" do Chef::Config[:json_attribs] = "/etc/chef/dna.json" @json = mock("Tempfile", :read => {:a=>"b"}.to_json, :null_object => true) @app.stub!(:open).with("/etc/chef/dna.json").and_return(@json) - JSON.stub!(:parse).with(@json.read).and_raise(JSON::ParserError) + Chef::JSON.stub!(:from_json).with(@json.read).and_raise(JSON::ParserError) Chef::Application.stub!(:fatal!).and_return(true) end diff --git a/chef/spec/unit/application/solo_spec.rb b/chef/spec/unit/application/solo_spec.rb index 2a95174147..2ec1d3be4d 100644 --- a/chef/spec/unit/application/solo_spec.rb +++ b/chef/spec/unit/application/solo_spec.rb @@ -87,7 +87,7 @@ describe Chef::Application::Solo do end it "should parse the json out of the file" do - JSON.should_receive(:parse).with(@json.read) + Chef::JSON.should_receive(:from_json).with(@json.read) @app.reconfigure end end @@ -97,7 +97,7 @@ describe Chef::Application::Solo do Chef::Config[:json_attribs] = "/etc/chef/dna.json" @json = mock("Tempfile", :read => {:a=>"b"}.to_json, :null_object => true) @app.stub!(:open).with("/etc/chef/dna.json").and_return(@json) - JSON.stub!(:parse).with(@json.read).and_raise(JSON::ParserError) + Chef::JSON.stub!(:from_json).with(@json.read).and_raise(JSON::ParserError) Chef::Application.stub!(:fatal!).and_return(true) end diff --git a/chef/spec/unit/checksum_spec.rb b/chef/spec/unit/checksum_spec.rb index d2740dae64..c8b405194f 100644 --- a/chef/spec/unit/checksum_spec.rb +++ b/chef/spec/unit/checksum_spec.rb @@ -92,7 +92,7 @@ describe Chef::Checksum do describe "when converted to json" do before do @checksum_as_json = @checksum.to_json - @checksum_as_hash_from_json = JSON.parse(@checksum_as_json, :create_additions => false) + @checksum_as_hash_from_json = Chef::JSON.from_json(@checksum_as_json, :create_additions => false) end it "contains the file's MD5 checksum" do diff --git a/chef/spec/unit/cookbook/metadata_spec.rb b/chef/spec/unit/cookbook/metadata_spec.rb index 9da3b0f84f..4b8420b149 100644 --- a/chef/spec/unit/cookbook/metadata_spec.rb +++ b/chef/spec/unit/cookbook/metadata_spec.rb @@ -515,11 +515,11 @@ describe Chef::Cookbook::Metadata do describe "serialize" do before(:each) do - @serial = JSON.parse(@meta.to_json) + @serial = Chef::JSON.from_json(@meta.to_json) end it "should serialize to a json hash" do - JSON.parse(@meta.to_json).should be_a_kind_of(Hash) + Chef::JSON.from_json(@meta.to_json).should be_a_kind_of(Hash) end %w{ diff --git a/chef/spec/unit/data_bag_item_spec.rb b/chef/spec/unit/data_bag_item_spec.rb index 661e2e7904..c13cca4abf 100644 --- a/chef/spec/unit/data_bag_item_spec.rb +++ b/chef/spec/unit/data_bag_item_spec.rb @@ -145,7 +145,7 @@ describe Chef::DataBagItem do before(:each) do @data_bag_item.data_bag('mars_volta') @data_bag_item.raw_data = { "id" => "octahedron", "snooze" => { "finally" => :world_will }} - @deserial = JSON.parse(@data_bag_item.to_json) + @deserial = Chef::JSON.from_json(@data_bag_item.to_json) end it "should deserialize to a Chef::DataBagItem object" do diff --git a/chef/spec/unit/data_bag_spec.rb b/chef/spec/unit/data_bag_spec.rb index 1f140b5f88..da8c792ea0 100644 --- a/chef/spec/unit/data_bag_spec.rb +++ b/chef/spec/unit/data_bag_spec.rb @@ -52,7 +52,7 @@ describe Chef::DataBag do describe "deserialize" do before(:each) do @data_bag.name('mars_volta') - @deserial = JSON.parse(@data_bag.to_json) + @deserial = Chef::JSON.from_json(@data_bag.to_json) end it "should deserialize to a Chef::DataBag object" do diff --git a/chef/spec/unit/handler/json_file_spec.rb b/chef/spec/unit/handler/json_file_spec.rb index 7a1c112360..6d3de0b970 100644 --- a/chef/spec/unit/handler/json_file_spec.rb +++ b/chef/spec/unit/handler/json_file_spec.rb @@ -52,7 +52,7 @@ describe Chef::Handler::JsonFile do it "saves run status data to a file as JSON" do @handler.should_receive(:build_report_dir) @handler.run_report_unsafe(@run_status) - reported_data = JSON.parse(@file_mock.string) + reported_data = Chef::JSON.from_json(@file_mock.string) reported_data['exception'].should == "Exception: Boy howdy!" reported_data['start_time'].should == @expected_time.iso8601 reported_data['end_time'].should == (@expected_time + 5).iso8601 diff --git a/chef/spec/unit/index_queue_spec.rb b/chef/spec/unit/index_queue_spec.rb index 02cdd514e3..61382fb8ec 100644 --- a/chef/spec/unit/index_queue_spec.rb +++ b/chef/spec/unit/index_queue_spec.rb @@ -113,7 +113,7 @@ describe Chef::IndexQueue::Indexable do @queue = FauxQueue.new @publisher.should_receive(:queue_for_object).with("0000000-1111-2222-3333-444444444444").and_yield(@queue) @indexable_obj.add_to_index(:database => "couchdb@localhost,etc.", :id=>"0000000-1111-2222-3333-444444444444") - published_message = JSON.parse(@queue.published_message) + published_message = Chef::JSON.from_json(@queue.published_message) published_message.should == {"action" => "add", "payload" => {"item" => @item_as_hash, "type" => "indexable_test_harness", "database" => "couchdb@localhost,etc.", @@ -126,7 +126,7 @@ describe Chef::IndexQueue::Indexable do @publisher.should_receive(:queue_for_object).with("0000000-1111-2222-3333-444444444444").and_yield(@queue) @indexable_obj.delete_from_index(:database => "couchdb2@localhost", :id=>"0000000-1111-2222-3333-444444444444") - published_message = JSON.parse(@queue.published_message) + published_message = Chef::JSON.from_json(@queue.published_message) published_message.should == {"action" => "delete", "payload" => { "item" => @item_as_hash, "type" => "indexable_test_harness", "database" => "couchdb2@localhost", diff --git a/chef/spec/unit/knife/cookbook_metadata_from_file_spec.rb b/chef/spec/unit/knife/cookbook_metadata_from_file_spec.rb index b3930689ef..9bee41facc 100644 --- a/chef/spec/unit/knife/cookbook_metadata_from_file_spec.rb +++ b/chef/spec/unit/knife/cookbook_metadata_from_file_spec.rb @@ -27,7 +27,7 @@ describe Chef::Knife::CookbookMetadataFromFile do @tgt = File.expand_path(File.join(CHEF_SPEC_DATA, "metadata", "quick_start", "metadata.json")) @knife = Chef::Knife::CookbookMetadataFromFile.new @knife.name_args = [ @src ] - @knife.stub!(:json_pretty_generate).and_return(true) + @knife.stub!(:to_json_pretty).and_return(true) @md = Chef::Cookbook::Metadata.new Chef::Cookbook::Metadata.stub(:new).and_return(@md) end @@ -56,7 +56,7 @@ describe Chef::Knife::CookbookMetadataFromFile do end it "should generate json from the metadata" do - JSON.should_receive(:pretty_generate).with(@md) + Chef::JSON.should_receive(:to_json_pretty).with(@md) @knife.run end diff --git a/chef/spec/unit/knife/data_bag_show_spec.rb b/chef/spec/unit/knife/data_bag_show_spec.rb index f72cae1987..1c4066991a 100644 --- a/chef/spec/unit/knife/data_bag_show_spec.rb +++ b/chef/spec/unit/knife/data_bag_show_spec.rb @@ -50,7 +50,7 @@ describe Chef::Knife::DataBagShow do Chef::DataBagItem.should_receive(:load).with('bag_o_data', 'an_item').and_return(data_item_content) @knife.run - JSON.parse(@stdout.string).should == data_item_content + Chef::JSON.from_json(@stdout.string).should == data_item_content end end diff --git a/chef/spec/unit/mixin/deprecation_spec.rb b/chef/spec/unit/mixin/deprecation_spec.rb index af0b27ed22..b78080971b 100644 --- a/chef/spec/unit/mixin/deprecation_spec.rb +++ b/chef/spec/unit/mixin/deprecation_spec.rb @@ -31,4 +31,4 @@ describe Chef::Mixin::Deprecation::DeprecatedInstanceVariable do @deprecated_ivar.to_sym.should == :value end -end
\ No newline at end of file +end diff --git a/chef/spec/unit/node_spec.rb b/chef/spec/unit/node_spec.rb index 469720706c..8e896073ac 100644 --- a/chef/spec/unit/node_spec.rb +++ b/chef/spec/unit/node_spec.rb @@ -487,7 +487,7 @@ describe Chef::Node do describe "json" do it "should serialize itself as json" do @node.find_file("test.example.com") - json = @node.to_json() + json = Chef::JSON.to_json(@node) json.should =~ /json_class/ json.should =~ /name/ json.should =~ /normal/ @@ -498,8 +498,8 @@ describe Chef::Node do it "should deserialize itself from json" do @node.find_file("test.example.com") - json = @node.to_json - serialized_node = JSON.parse(json) + json = Chef::JSON.to_json(@node) + serialized_node = Chef::JSON.from_json(json) serialized_node.should be_a_kind_of(Chef::Node) serialized_node.name.should eql(@node.name) @node.each_attribute do |k,v| diff --git a/chef/spec/unit/openid_registration_spec.rb b/chef/spec/unit/openid_registration_spec.rb index 5187ee0d21..5f8421e9f7 100644 --- a/chef/spec/unit/openid_registration_spec.rb +++ b/chef/spec/unit/openid_registration_spec.rb @@ -56,7 +56,7 @@ describe Chef::OpenIDRegistration, "from_json" do oreg.name = "foobar" oreg.set_password("monkey") oreg_json = oreg.to_json - nreg = JSON.parse(oreg_json) + nreg = Chef::JSON.from_json(oreg_json) nreg.should be_a_kind_of(Chef::OpenIDRegistration) %w{name salt password validated}.each do |verify| nreg.send(verify.to_sym).should eql(oreg.send(verify.to_sym)) diff --git a/chef/spec/unit/resource_collection_spec.rb b/chef/spec/unit/resource_collection_spec.rb index e9ee2f86a8..578e5e8908 100644 --- a/chef/spec/unit/resource_collection_spec.rb +++ b/chef/spec/unit/resource_collection_spec.rb @@ -222,7 +222,7 @@ describe Chef::ResourceCollection do it "should deserialize itself from json" do @rc << @resource json = @rc.to_json - s_rc = JSON.parse(json) + s_rc = Chef::JSON.from_json(json) s_rc.should be_a_kind_of(Chef::ResourceCollection) s_rc[0].name.should eql(@resource.name) end diff --git a/chef/spec/unit/resource_spec.rb b/chef/spec/unit/resource_spec.rb index 72be22fa04..fdb3816788 100644 --- a/chef/spec/unit/resource_spec.rb +++ b/chef/spec/unit/resource_spec.rb @@ -204,7 +204,7 @@ describe Chef::Resource do describe "self.json_create" do it "should deserialize itself from json" do json = @resource.to_json - serialized_node = JSON.parse(json) + serialized_node = Chef::JSON.from_json(json) serialized_node.should be_a_kind_of(Chef::Resource) serialized_node.name.should eql(@resource.name) end diff --git a/chef/spec/unit/rest_spec.rb b/chef/spec/unit/rest_spec.rb index a2a697181b..1a79ea8075 100644 --- a/chef/spec/unit/rest_spec.rb +++ b/chef/spec/unit/rest_spec.rb @@ -204,7 +204,7 @@ describe Chef::REST do it "should inflate the body as to an object if JSON is returned" do @http_response.add_field("content-type", "application/json") - JSON.should_receive(:parse).with("ninja").and_return("ohai2u_success") + Chef::JSON.should_receive(:from_json).with("ninja").and_return("ohai2u_success") @rest.run_request(:GET, @url, {}).should == "ohai2u_success" end diff --git a/chef/spec/unit/role_spec.rb b/chef/spec/unit/role_spec.rb index 548faaac7c..fbb0b3c40a 100644 --- a/chef/spec/unit/role_spec.rb +++ b/chef/spec/unit/role_spec.rb @@ -115,11 +115,11 @@ describe Chef::Role do @role.run_list('one', 'two', 'role[a]') @role.default_attributes({ :el_groupo => 'nuevo' }) @role.override_attributes({ :deloused => 'in the comatorium' }) - @serial = @role.to_json + @serial = Chef::JSON.to_json(@role) end it "should serialize to a json hash" do - @role.to_json.should match(/^\{.+\}$/) + Chef::JSON.to_json(@role).should match(/^\{.+\}$/) end %w{ @@ -151,7 +151,7 @@ describe Chef::Role do @role.run_list('one', 'two', 'role[a]') @role.default_attributes({ 'el_groupo' => 'nuevo' }) @role.override_attributes({ 'deloused' => 'in the comatorium' }) - @deserial = JSON.parse(@role.to_json) + @deserial = Chef::JSON.from_json(Chef::JSON.to_json(@role)) end it "should deserialize to a Chef::Role object" do diff --git a/chef/spec/unit/webui_user_spec.rb b/chef/spec/unit/webui_user_spec.rb index 0e1c053013..4db9294b4e 100644 --- a/chef/spec/unit/webui_user_spec.rb +++ b/chef/spec/unit/webui_user_spec.rb @@ -217,8 +217,8 @@ describe Chef::WebUIUser do end it "sets its couchdb id when loading from the database" do - # reqs via REST eventually get to JSON.parse - webui_user = JSON.parse('{"salt":null,"name":"test_user","json_class":"Chef::WebUIUser","admin":false,"openid":null,"password":null,"chef_type":"webui_user","_id":"IdontNeedNoID"}') + # reqs via REST eventually get to Chef::JSON.from_json + webui_user = Chef::JSON.from_json('{"salt":null,"name":"test_user","json_class":"Chef::WebUIUser","admin":false,"openid":null,"password":null,"chef_type":"webui_user","_id":"IdontNeedNoID"}') webui_user.couchdb_id.should == "IdontNeedNoID" end @@ -230,9 +230,9 @@ describe Chef::WebUIUser do end it "sets the couchdb_rev when loading from the database" do - webui_user = JSON.parse('{"salt":null,"name":"test_user","json_class":"Chef::WebUIUser","admin":false,"openid":null,"password":null,"chef_type":"webui_user","_id":"IdontNeedNoID","_rev":"moto"}') + webui_user = Chef::JSON.from_json('{"salt":null,"name":"test_user","json_class":"Chef::WebUIUser","admin":false,"openid":null,"password":null,"chef_type":"webui_user","_id":"IdontNeedNoID","_rev":"moto"}') webui_user.couchdb_rev.should == "moto" end end -end
\ No newline at end of file +end |