diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2014-01-13 00:59:34 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2014-06-23 16:41:05 -0700 |
commit | 6a9ed8cc9a4df568ee0df35964f87007bfc730df (patch) | |
tree | 798f48e43d2ddbf9975eb4e60ce972b8e39dc71d | |
parent | d111e820f1f3dba3e759f6f06bbeac30f8aa1389 (diff) | |
download | chef-6a9ed8cc9a4df568ee0df35964f87007bfc730df.tar.gz |
replace yajl and json gem with ffi-yajl
-rw-r--r-- | chef.gemspec | 5 | ||||
-rw-r--r-- | lib/chef/config_fetcher.rb | 2 | ||||
-rw-r--r-- | lib/chef/encrypted_data_bag_item/decryptor.rb | 6 | ||||
-rw-r--r-- | lib/chef/encrypted_data_bag_item/encryptor.rb | 4 | ||||
-rw-r--r-- | lib/chef/json_compat.rb | 21 | ||||
-rw-r--r-- | lib/chef/provider/remote_file/cache_control_data.rb | 2 |
6 files changed, 16 insertions, 24 deletions
diff --git a/chef.gemspec b/chef.gemspec index 898ac32c76..50cbd4e279 100644 --- a/chef.gemspec +++ b/chef.gemspec @@ -27,8 +27,9 @@ Gem::Specification.new do |s| s.add_dependency "mime-types", "~> 1.16" # The JSON gem reliably releases breaking changes as a patch release - s.add_dependency "json", ">= 1.4.4", "<= 1.8.1" - s.add_dependency "yajl-ruby", "~> 1.1" + s.add_dependency "ffi-yajl" +# s.add_dependency "json", ">= 1.4.4", "<= 1.8.1" +# s.add_dependency "yajl-ruby", "~> 1.1" s.add_dependency "net-ssh", "~> 2.6" s.add_dependency "net-ssh-multi", "~> 1.1" # CHEF-3027: The knife-cloud plugins require newer features from highline, core chef should not. diff --git a/lib/chef/config_fetcher.rb b/lib/chef/config_fetcher.rb index 26440c9c01..c1fd262656 100644 --- a/lib/chef/config_fetcher.rb +++ b/lib/chef/config_fetcher.rb @@ -18,7 +18,7 @@ class Chef config_data = read_config begin Chef::JSONCompat.from_json(config_data) - rescue JSON::ParserError => error + rescue FFI_Yajl::ParseError => error Chef::Application.fatal!("Could not parse the provided JSON file (#{config_location}): " + error.message, 2) end end diff --git a/lib/chef/encrypted_data_bag_item/decryptor.rb b/lib/chef/encrypted_data_bag_item/decryptor.rb index 9ee38a12c4..69b8d62e3b 100644 --- a/lib/chef/encrypted_data_bag_item/decryptor.rb +++ b/lib/chef/encrypted_data_bag_item/decryptor.rb @@ -17,7 +17,7 @@ # require 'yaml' -require 'yajl' +require 'ffi_yajl' require 'openssl' require 'base64' require 'digest/sha2' @@ -121,8 +121,8 @@ class Chef::EncryptedDataBagItem end def for_decrypted_item - Yajl::Parser.parse(decrypted_data)["json_wrapper"] - rescue Yajl::ParseError + FFI_Yajl::Parser.parse(decrypted_data)["json_wrapper"] + rescue FFI_Yajl::ParseError # convert to a DecryptionFailure error because the most likely scenario # here is that the decryption step was unsuccessful but returned bad # data rather than raising an error. diff --git a/lib/chef/encrypted_data_bag_item/encryptor.rb b/lib/chef/encrypted_data_bag_item/encryptor.rb index f99c913c62..9686e84b34 100644 --- a/lib/chef/encrypted_data_bag_item/encryptor.rb +++ b/lib/chef/encrypted_data_bag_item/encryptor.rb @@ -19,7 +19,7 @@ require 'base64' require 'digest/sha2' require 'openssl' -require 'yajl' +require 'ffi_yajl' require 'chef/encrypted_data_bag_item' require 'chef/encrypted_data_bag_item/unsupported_encrypted_data_bag_item_format' @@ -111,7 +111,7 @@ class Chef::EncryptedDataBagItem # Strings) that do not produce valid JSON when serialized without the # wrapper. def serialized_data - Yajl::Encoder.encode(:json_wrapper => plaintext_data) + FFI_Yajl::Encoder.encode(:json_wrapper => plaintext_data) end end diff --git a/lib/chef/json_compat.rb b/lib/chef/json_compat.rb index e4795cfd7e..795cf046fd 100644 --- a/lib/chef/json_compat.rb +++ b/lib/chef/json_compat.rb @@ -17,8 +17,8 @@ # Wrapper class for interacting with JSON. -require 'json' -require 'yajl' +require 'ffi_yajl' +require 'ffi_yajl/json_gem' # XXX: parts of chef require JSON gem's Hash#to_json monkeypatch class Chef class JSONCompat @@ -40,20 +40,11 @@ class Chef 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 + # opts_add_max_nesting() removed -- libyajl does not have a configurable max nesting depth # Just call the JSON gem's parse method with a modified :max_nesting field def from_json(source, opts = {}) - obj = ::Yajl::Parser.parse(source) + obj = ::FFI_Yajl::Parser.parse(source) # JSON gem requires top level object to be a Hash or Array (otherwise # you get the "must contain two octets" error). Yajl doesn't impose the @@ -99,11 +90,11 @@ class Chef end def to_json(obj, opts = nil) - obj.to_json(opts_add_max_nesting(opts)) + obj.to_json(opts) end def to_json_pretty(obj, opts = nil) - ::JSON.pretty_generate(obj, opts_add_max_nesting(opts)) + ::JSON.pretty_generate(obj, opts) end diff --git a/lib/chef/provider/remote_file/cache_control_data.rb b/lib/chef/provider/remote_file/cache_control_data.rb index afd3b78aa5..545f2b571e 100644 --- a/lib/chef/provider/remote_file/cache_control_data.rb +++ b/lib/chef/provider/remote_file/cache_control_data.rb @@ -140,7 +140,7 @@ class Chef def load_data Chef::JSONCompat.from_json(load_json_data) - rescue Chef::Exceptions::FileNotFound, Yajl::ParseError, JSON::ParserError + rescue Chef::Exceptions::FileNotFound, FFI_Yajl::ParseError false end |