diff options
106 files changed, 267 insertions, 145 deletions
diff --git a/chef-server-api/app/controllers/application.rb b/chef-server-api/app/controllers/application.rb index 72c1482087..0e2db2901e 100644 --- a/chef-server-api/app/controllers/application.rb +++ b/chef-server-api/app/controllers/application.rb @@ -22,6 +22,7 @@ require "chef/mixin/checksum" require "chef/cookbook_loader" require "mixlib/authentication/signatureverification" +require "chef/json" class Application < Merb::Controller @@ -102,11 +103,11 @@ class Application < Merb::Controller def access_denied raise Unauthorized, "You must authenticate first!" end - + def get_available_recipes all_cookbooks_list = Chef::CookbookVersion.cdb_list(true) available_recipes = all_cookbooks_list.sort{ |a,b| a.name.to_s <=> b.name.to_s }.inject([]) do |result, element| - element.recipes.sort.each do |r| + element.recipes.sort.each do |r| if r =~ /^(.+)::default$/ result << $1 else @@ -118,5 +119,14 @@ class Application < Merb::Controller available_recipes end + # Use Chef's JSON conversion library for sending JSON instead of the + # default Merb, which calls obj.to_json. Fixes CHEF-1292/PL-538. + override! :display + def display(obj) + super(obj, nil, {:max_nesting => Chef::JSON::JSON_MAX_NESTING}) + #super.display(Chef::JSON.to_json(obj)) + #Chef::JSON.to_json(obj) + end + end diff --git a/chef-server-api/config/router.rb b/chef-server-api/config/router.rb index a64f3383e6..da0840840e 100644 --- a/chef-server-api/config/router.rb +++ b/chef-server-api/config/router.rb @@ -112,4 +112,37 @@ Merb::Router.prepare do match('/').to(:controller => 'main', :action =>'index').name(:top) + # Need to monkey patch Merb so that it inflates JSON input with a higher + # recursion depth allowed (the default is 19). See CHEF-1292/PL-538. + module Merb + class Request + # ==== Returns + # Hash:: Parameters from body if this is a JSON request. + # + # ==== Notes + # If the JSON object parses as a Hash, it will be merged with the + # parameters hash. If it parses to anything else (such as an Array, or + # if it inflates to an Object) it will be accessible via the inflated_object + # parameter. + # + # :api: private + def json_params + @json_params ||= begin + if Merb::Const::JSON_MIME_TYPE_REGEXP.match(content_type) + begin + # Call Chef's JSON utility instead of the default in Merb, + # JSON.parse. + jobj = Chef::JSON.from_json(raw_post) + jobj = jobj.to_mash if jobj.is_a?(Hash) + rescue JSON::ParserError + jobj = Mash.new + end + jobj.is_a?(Hash) ? jobj : { :inflated_object => jobj } + end + end + end + + end + end + end diff --git a/chef-server-webui/app/controllers/databag_items.rb b/chef-server-webui/app/controllers/databag_items.rb index 00310008f0..c3da721740 100644 --- a/chef-server-webui/app/controllers/databag_items.rb +++ b/chef-server-webui/app/controllers/databag_items.rb @@ -38,7 +38,7 @@ class DatabagItems < Application begin @databag_item = Chef::DataBagItem.new @databag_item.data_bag params[:databag_id] - @databag_item.raw_data = JSON.parse(params[:json_data]) + @databag_item.raw_data = Chef::JSON.from_json(params[:json_data]) raise ArgumentError, "Updating id is not allowed" unless @databag_item.raw_data['id'] == params[:id] #to be consistent with other objects, changing id is not allowed. @databag_item.save redirect(url(:databag_databag_items, :databag_id => params[:databag_id], :id => @databag_item.name), :message => { :notice => "Updated Databag Item #{@databag_item.name}" }) @@ -61,7 +61,7 @@ class DatabagItems < Application @databag_name = params[:databag_id] @databag_item = Chef::DataBagItem.new @databag_item.data_bag @databag_name - @databag_item.raw_data = JSON.parse(params[:json_data]) + @databag_item.raw_data = Chef::JSON.from_json(params[:json_data]) @databag_item.create redirect(url(:databag_databag_items, :databag_id => @databag_name), :message => { :notice => "Databag item created successfully" }) rescue => e diff --git a/chef-server-webui/app/controllers/nodes.rb b/chef-server-webui/app/controllers/nodes.rb index 3b0bfa1ae8..5888f12b1c 100644 --- a/chef-server-webui/app/controllers/nodes.rb +++ b/chef-server-webui/app/controllers/nodes.rb @@ -91,14 +91,14 @@ class Nodes < Application begin @node = Chef::Node.new @node.name params[:name] - @node.normal_attrs = JSON.parse(params[:attributes]) + @node.normal_attrs = Chef::JSON.from_json(params[:attributes]) @node.run_list.reset!(params[:for_node] ? params[:for_node] : []) raise ArgumentError, "Node name cannot be blank" if (params[:name].nil? || params[:name].length==0) @node.create redirect(url(:nodes), :message => { :notice => "Created Node #{@node.name}" }) rescue => e Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}") - @node.normal_attrs = JSON.parse(params[:attributes]) + @node.normal_attrs = Chef::JSON.from_json(params[:attributes]) @available_recipes = get_available_recipes @available_roles = Chef::Role.list.keys.sort @node.run_list params[:for_node] @@ -112,7 +112,7 @@ class Nodes < Application begin @node = Chef::Node.load(params[:id]) @node.run_list.reset!(params[:for_node] ? params[:for_node] : []) - @node.normal_attrs = JSON.parse(params[:attributes]) + @node.normal_attrs = Chef::JSON.from_json(params[:attributes]) @node.save @_message = { :notice => "Updated Node" } render :show diff --git a/chef-server-webui/app/controllers/roles.rb b/chef-server-webui/app/controllers/roles.rb index 12a663912b..bdf3186124 100644 --- a/chef-server-webui/app/controllers/roles.rb +++ b/chef-server-webui/app/controllers/roles.rb @@ -90,8 +90,8 @@ class Roles < Application @role.name(params[:name]) @role.run_list(params[:for_role] ? params[:for_role] : []) @role.description(params[:description]) if params[:description] != '' - @role.default_attributes(JSON.parse(params[:default_attributes])) if params[:default_attributes] != '' - @role.override_attributes(JSON.parse(params[:override_attributes])) if params[:override_attributes] != '' + @role.default_attributes(Chef::JSON.from_json(params[:default_attributes])) if params[:default_attributes] != '' + @role.override_attributes(Chef::JSON.from_json(params[:override_attributes])) if params[:override_attributes] != '' @role.create redirect(url(:roles), :message => { :notice => "Created Role #{@role.name}" }) rescue => e @@ -99,8 +99,8 @@ class Roles < Application @available_recipes = get_available_recipes @available_roles = Chef::Role.list.keys.sort @role = Chef::Role.new - @role.default_attributes(JSON.parse(params[:default_attributes])) if params[:default_attributes] != '' - @role.override_attributes(JSON.parse(params[:override_attributes])) if params[:override_attributes] != '' + @role.default_attributes(Chef::JSON.from_json(params[:default_attributes])) if params[:default_attributes] != '' + @role.override_attributes(Chef::JSON.from_json(params[:override_attributes])) if params[:override_attributes] != '' @run_list = Chef::RunList.new.reset!(Array(params[:for_role])) @_message = { :error => "Could not create role" } render :new @@ -113,8 +113,8 @@ class Roles < Application @role = Chef::Role.load(params[:id]) @role.run_list(params[:for_role] ? params[:for_role] : []) @role.description(params[:description]) if params[:description] != '' - @role.default_attributes(JSON.parse(params[:default_attributes])) if params[:default_attributes] != '' - @role.override_attributes(JSON.parse(params[:override_attributes])) if params[:override_attributes] != '' + @role.default_attributes(Chef::JSON.from_json(params[:default_attributes])) if params[:default_attributes] != '' + @role.override_attributes(Chef::JSON.from_json(params[:override_attributes])) if params[:override_attributes] != '' @role.save @_message = { :notice => "Updated Role" } render :show @@ -124,8 +124,8 @@ class Roles < Application @available_roles = Chef::Role.list.keys.sort @run_list = Chef::RunList.new.reset!( Array(params[:for_role])) Chef::Log.error(@run_list.inspect) - @role.default_attributes(JSON.parse(params[:default_attributes])) if params[:default_attributes] != '' - @role.override_attributes(JSON.parse(params[:override_attributes])) if params[:override_attributes] != '' + @role.default_attributes(Chef::JSON.from_json(params[:default_attributes])) if params[:default_attributes] != '' + @role.override_attributes(Chef::JSON.from_json(params[:override_attributes])) if params[:override_attributes] != '' @_message = {:error => "Could not update role #{params[:id]}"} render :edit end 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 2c49e3fee5..0d182c85e1 100644 --- a/chef/lib/chef/cookbook/metadata.rb +++ b/chef/lib/chef/cookbook/metadata.rb @@ -437,12 +437,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/amqp_client.rb b/chef/lib/chef/index_queue/amqp_client.rb index 5bbe73e4ec..3109370bc0 100644 --- a/chef/lib/chef/index_queue/amqp_client.rb +++ b/chef/lib/chef/index_queue/amqp_client.rb @@ -76,7 +76,7 @@ class Chef def send_action(action, data) retries = 0 begin - exchange.publish({"action" => action.to_s, "payload" => data}.to_json) + exchange.publish(Chef::JSON.to_json({"action" => action.to_s, "payload" => data})) rescue Bunny::ServerDownError, Bunny::ConnectionError, Errno::ECONNRESET disconnected! if (retries += 1) < 2 diff --git a/chef/lib/chef/index_queue/consumer.rb b/chef/lib/chef/index_queue/consumer.rb index 58b00511f4..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) diff --git a/chef/lib/chef/json.rb b/chef/lib/chef/json.rb new file mode 100644 index 0000000000..1b1618c132 --- /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 PL-538. Increase the max nesting for JSON, which defaults to 19, + # and isn't enough for some deep node (for example) 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) + #::JSON.generate(obj, opts_add_max_nesting(opts)) + 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 dc0d47e5a3..9fb715cdd9 100644 --- a/chef/lib/chef/knife.rb +++ b/chef/lib/chef/knife.rb @@ -291,7 +291,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) @@ -344,7 +344,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-" @@ -362,7 +362,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) @@ -415,7 +415,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) @@ -445,8 +445,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/bluebox_images_list.rb b/chef/lib/chef/knife/bluebox_images_list.rb index 0980727f26..bc83d7a391 100644 --- a/chef/lib/chef/knife/bluebox_images_list.rb +++ b/chef/lib/chef/knife/bluebox_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/bluebox_server_create.rb b/chef/lib/chef/knife/bluebox_server_create.rb index cc34e9e56a..fe878e5db1 100644 --- a/chef/lib/chef/knife/bluebox_server_create.rb +++ b/chef/lib/chef/knife/bluebox_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/bluebox_server_delete.rb b/chef/lib/chef/knife/bluebox_server_delete.rb index ada1edc13f..8e135a2388 100644 --- a/chef/lib/chef/knife/bluebox_server_delete.rb +++ b/chef/lib/chef/knife/bluebox_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/bluebox_server_list.rb b/chef/lib/chef/knife/bluebox_server_list.rb index 2dd7cca027..fc9c42d50f 100644 --- a/chef/lib/chef/knife/bluebox_server_list.rb +++ b/chef/lib/chef/knife/bluebox_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/bootstrap.rb b/chef/lib/chef/knife/bootstrap.rb index b9e45faf69..42c2c9b539 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 fef6461da1..71facf1691 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 237245b330..c2cbee2b47 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/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 f5df41a160..38c3be71f3 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 1cb92453b2..5c5fe14dd4 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 dfaba190d3..de81ac86df 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/environment_create.rb b/chef/lib/chef/knife/environment_create.rb index 7062712d53..72d1cc7b8c 100644 --- a/chef/lib/chef/knife/environment_create.rb +++ b/chef/lib/chef/knife/environment_create.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/environment' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/environment_delete.rb b/chef/lib/chef/knife/environment_delete.rb index a17caee0ab..ad9f05c1bd 100644 --- a/chef/lib/chef/knife/environment_delete.rb +++ b/chef/lib/chef/knife/environment_delete.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/environment' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/environment_edit.rb b/chef/lib/chef/knife/environment_edit.rb index 8135791619..28c80b3e14 100644 --- a/chef/lib/chef/knife/environment_edit.rb +++ b/chef/lib/chef/knife/environment_edit.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/environment' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/environment_list.rb b/chef/lib/chef/knife/environment_list.rb index 061de5b929..540187b889 100644 --- a/chef/lib/chef/knife/environment_list.rb +++ b/chef/lib/chef/knife/environment_list.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/environment' -require 'json' +require 'chef/json' class Chef class Knife diff --git a/chef/lib/chef/knife/environment_show.rb b/chef/lib/chef/knife/environment_show.rb index c41658b07e..a11dc9d8a9 100644 --- a/chef/lib/chef/knife/environment_show.rb +++ b/chef/lib/chef/knife/environment_show.rb @@ -18,7 +18,7 @@ require 'chef/knife' require 'chef/environment' -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 6cfd9292bb..466f0a6abe 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 1e427c6062..e2f2daf224 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 44b8643052..9f50fea2df 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 0d6add3189..48acd9d0b2 100644 --- a/chef/lib/chef/node.rb +++ b/chef/lib/chef/node.rb @@ -34,7 +34,7 @@ require 'chef/run_list' require 'chef/node/attribute' require 'chef/index_queue' require 'extlib' -require 'json' +require 'chef/json' class Chef class Node @@ -646,6 +646,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..18c2c03f8a 100644 --- a/chef/lib/chef/provider/deploy/revision.rb +++ b/chef/lib/chef/provider/deploy/revision.rb @@ -56,7 +56,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 c92083549d..0f2a4e1340 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 @@ -304,7 +304,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 ac72981b71..bcab49fb4b 100644 --- a/chef/lib/chef/shef.rb +++ b/chef/lib/chef/shef.rb @@ -163,7 +163,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 diff --git a/chef/lib/chef/shef/ext.rb b/chef/lib/chef/shef/ext.rb index a601e86786..77c63cfc07 100644 --- a/chef/lib/chef/shef/ext.rb +++ b/chef/lib/chef/shef/ext.rb @@ -327,13 +327,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/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 6825d89809..ef87f29aa4 100644 --- a/chef/spec/unit/cookbook/metadata_spec.rb +++ b/chef/spec/unit/cookbook/metadata_spec.rb @@ -480,11 +480,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/environment_spec.rb b/chef/spec/unit/environment_spec.rb index 3b8b6acfc9..870ab026c0 100644 --- a/chef/spec/unit/environment_spec.rb +++ b/chef/spec/unit/environment_spec.rb @@ -205,7 +205,7 @@ describe Chef::Environment do "json_class" => "Chef::Environment", "chef_type" => "environment" } - @environment = JSON.parse(@data.to_json) + @environment = Chef::JSON.from_json(@data.to_json) end it "should return a Chef::Environment" 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/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/node_spec.rb b/chef/spec/unit/node_spec.rb index 6175dd42b8..4f91798a3b 100644 --- a/chef/spec/unit/node_spec.rb +++ b/chef/spec/unit/node_spec.rb @@ -555,7 +555,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 =~ /chef_environment/ @@ -567,8 +567,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) serialized_node.chef_environment.should eql(@node.chef_environment) 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 8e6230019b..4fcab4874b 100644 --- a/chef/spec/unit/role_spec.rb +++ b/chef/spec/unit/role_spec.rb @@ -141,11 +141,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{ @@ -177,7 +177,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 cc3c819ef0..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,7 +230,7 @@ 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 diff --git a/features/api/nodes/deep_node_show_save.feature b/features/api/nodes/deep_node_show_save.feature new file mode 100644 index 0000000000..309b7c4237 --- /dev/null +++ b/features/api/nodes/deep_node_show_save.feature @@ -0,0 +1,13 @@ +@api @api_nodes @nodes_show @json_recusion @pl_538 +Feature: Save and show a node with deep structure via the API + In order to verify that I can save and show very deep structure in a node object + As a Developer + I want to show the details for a specific node + + Scenario: Show a really deep node + Given I am an administrator + And a 'node' named 'really_deep_node' exists + When I 'GET' the path '/nodes/really_deep_node' + Then I should not get an exception + And the inflated response should respond to 'name' with 'really_deep_node' + And the inflated response should respond to 'deep_array' and match '.*10,\"really_deep_string\".*' as json diff --git a/features/data/Rakefile b/features/data/Rakefile index c7ddd15e1d..58ffa250d7 100644 --- a/features/data/Rakefile +++ b/features/data/Rakefile @@ -22,7 +22,7 @@ $: << File.join(File.dirname(__FILE__), "..", "..", "chef", "lib") require 'rubygems' require 'chef' -require 'json' +require 'chef/json' # Make sure you have loaded constants first require File.join(File.dirname(__FILE__), 'config', 'rake') diff --git a/features/data/node-load-test.rb b/features/data/node-load-test.rb index 0d559e7bb7..bc83a5f320 100755 --- a/features/data/node-load-test.rb +++ b/features/data/node-load-test.rb @@ -17,7 +17,7 @@ end Chef::Config.from_file("/etc/chef/client.rb") json_attrs = Hash.new if ARGV[3] - json_attrs = JSON.parse(IO.read(ARGV[3])) + json_attrs = Chef::JSON.from_json(IO.read(ARGV[3])) end Chef::Log.level = :info processes = Array.new diff --git a/features/steps/deploy_steps.rb b/features/steps/deploy_steps.rb index 2a3906f5ad..ace9b0b173 100644 --- a/features/steps/deploy_steps.rb +++ b/features/steps/deploy_steps.rb @@ -72,7 +72,7 @@ Then /^the callback named <callback> should have run$/ do |callback_files| hook_name = file.first.gsub(/\.rb$/, "") evidence_file = "deploy/current/app/" + hook_name expected_contents = {"hook_name" => hook_name, "env" => "production"} - actual_contents = JSON.parse(IO.read(File.join(tmpdir, evidence_file))) + actual_contents = Chef::JSON.from_json(IO.read(File.join(tmpdir, evidence_file))) expected_contents.should == actual_contents end end diff --git a/features/steps/fixture_steps.rb b/features/steps/fixture_steps.rb index b0e9c9ec44..ba749d4f5f 100644 --- a/features/steps/fixture_steps.rb +++ b/features/steps/fixture_steps.rb @@ -207,6 +207,21 @@ Before do n.chef_environment 'cookbooks_test' n.run_list << "version_test" n + end, + 'really_deep_node' => Proc.new do + array = [] + max_levels = 50 + num_level = 0 + begin + array = [num_level, "really_deep_string", array] + num_level += 1 + end while num_level < max_levels + + n = Chef::Node.new + n.name 'really_deep_node' + n.run_list << "deep_node_recipe" + n.deep_array = array + n end }, 'hash' => { @@ -316,14 +331,14 @@ Given /^an? '(.+)' named '(.+)' exists$/ do |stash_name, stash_key| :method => "POST", "HTTP_ACCEPT" => 'application/json', "CONTENT_TYPE" => 'application/json', - :input => @stash[stash_name].to_json + :input => Chef::JSON.to_json(@stash[stash_name]) }.merge(sign_request("POST", request_path, OpenSSL::PKey::RSA.new(IO.read("#{tmpdir}/client.pem")), "bobo"))) end end end Given /^sending the method '(.+)' to the '(.+)' with '(.+)'/ do |method, stash_name, update_value| - update_value = JSON.parse(update_value) if update_value =~ /^\[|\{/ + update_value = Chef::JSON.from_json(update_value) if update_value =~ /^\[|\{/ @stash[stash_name].send(method.to_sym, update_value) end diff --git a/features/steps/response_steps.rb b/features/steps/response_steps.rb index 3e2813d3dc..db5342db1a 100644 --- a/features/steps/response_steps.rb +++ b/features/steps/response_steps.rb @@ -40,12 +40,12 @@ end Then /^the inflated response should match '(.+)' as json$/ do |regex| puts self.inflated_response.inspect if ENV["DEBUG"] - self.inflated_response.to_json.should =~ /#{regex}/m + Chef::JSON.to_json(self.inflated_response).should =~ /#{regex}/m end Then /^the inflated responses key '(.+)' should match '(.+)' as json$/ do |key, regex| puts self.inflated_response.inspect if ENV["DEBUG"] - self.inflated_response[key].to_json.should =~ /#{regex}/m + Chef::JSON.to_json(self.inflated_response[key]).should =~ /#{regex}/m end Then /^the inflated responses key '(.+)' item '(\d+)' should be '(.+)'$/ do |key, index, to_equal| @@ -135,7 +135,7 @@ Then /^the inflated response should be a kind of '(.+)'$/ do |thing| end Then /^the inflated response should respond to '(.+)' with '(.+)'$/ do |method, to_match| - to_match = JSON.parse(to_match) if to_match =~ /^\[|\{/ + to_match = Chef::JSON.from_json(to_match) if to_match =~ /^\[|\{/ to_match = true if to_match == 'true' to_match = false if to_match == 'false' self.inflated_response.to_hash[method].should == to_match @@ -146,7 +146,7 @@ Then /^the inflated response should respond to '(.+)' and match '(.+)'$/ do |met end Then /^the inflated response should respond to '(.+)' and match '(.+)' as json$/ do |method, regex| - self.inflated_response.to_hash[method].to_json.should =~ /#{regex}/m + Chef::JSON.to_json(self.inflated_response.to_hash[method]).should =~ /#{regex}/m end Then /^the fields in the inflated response should match the '(.+)'$/ do |stash_name| diff --git a/features/support/couchdb_replicate.rb b/features/support/couchdb_replicate.rb index c44970e0bd..6459c3269e 100644 --- a/features/support/couchdb_replicate.rb +++ b/features/support/couchdb_replicate.rb @@ -27,7 +27,7 @@ require 'rubygems' require 'rest-client' require 'chef/log' -require 'json' +require 'chef/json' # Bulk GET all documents in the given db, using the given page size. # Calls the required block for each page size, passing in an array of @@ -48,7 +48,7 @@ def bulk_get_paged(db, page_size) # Pass :create_additions=>false so JSON parser does *not* expand # custom classes (such as Chef::Node, etc), and instead sticks only # to Array, Hash, String, etc. - paged_results = JSON.parse(paged_results_str, :create_additions => false) + paged_results = Chef::JSON.from_json(paged_results_str, :create_additions => false) paged_rows = paged_results['rows'] if paged_rows.length > 0 @@ -115,7 +115,7 @@ def replicate_dbs(replication_specs, delete_source_dbs = false) doc_in_row end - RestClient.post("#{target_db}/_bulk_docs", ({"docs" => paged_rows}).to_json, :content_type => "application/json") + RestClient.post("#{target_db}/_bulk_docs", Chef::JSON.to_json({"docs" => paged_rows}), :content_type => "application/json") end # Delete the source if asked to.. |