summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlamont-granquist <lamont@scriptkiddie.org>2014-06-24 10:08:19 -0700
committerlamont-granquist <lamont@scriptkiddie.org>2014-06-24 10:08:19 -0700
commit9f42beea1883f345bdc4697d074ec93611a1b796 (patch)
treece8c34fdec0d27edd191865ee7aa28111330667f
parentd111e820f1f3dba3e759f6f06bbeac30f8aa1389 (diff)
parentf382c51e3f6fc091153f447520817e7ede3520fc (diff)
downloadchef-9f42beea1883f345bdc4697d074ec93611a1b796.tar.gz
Merge pull request #1540 from opscode/lcg/ffi-yajl-gem
replace ruby-yajl with ffi-yajl gem
-rw-r--r--chef.gemspec3
-rw-r--r--lib/chef/config_fetcher.rb2
-rw-r--r--lib/chef/encrypted_data_bag_item/decryptor.rb6
-rw-r--r--lib/chef/encrypted_data_bag_item/encryptor.rb4
-rw-r--r--lib/chef/json_compat.rb21
-rw-r--r--lib/chef/knife/core/object_loader.rb4
-rw-r--r--lib/chef/provider/remote_file/cache_control_data.rb2
-rw-r--r--spec/unit/knife/bootstrap_spec.rb4
-rw-r--r--spec/unit/provider/remote_file/cache_control_data_spec.rb2
9 files changed, 19 insertions, 29 deletions
diff --git a/chef.gemspec b/chef.gemspec
index 898ac32c76..5d657abf6e 100644
--- a/chef.gemspec
+++ b/chef.gemspec
@@ -27,8 +27,7 @@ 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 "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..2dbb607d9b 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,9 @@ 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
-
# 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 +88,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/knife/core/object_loader.rb b/lib/chef/knife/core/object_loader.rb
index 1d207c10d1..de683b23fd 100644
--- a/lib/chef/knife/core/object_loader.rb
+++ b/lib/chef/knife/core/object_loader.rb
@@ -16,6 +16,8 @@
# limitations under the License.
#
+require 'ffi_yajl'
+
class Chef
class Knife
module Core
@@ -83,7 +85,7 @@ class Chef
def object_from_file(filename)
case filename
when /\.(js|json)$/
- r = Yajl::Parser.parse(IO.read(filename))
+ r = FFI_Yajl::Parser.parse(IO.read(filename))
# Chef::DataBagItem doesn't work well with the json_create method
if @klass == Chef::DataBagItem
diff --git a/lib/chef/provider/remote_file/cache_control_data.rb b/lib/chef/provider/remote_file/cache_control_data.rb
index afd3b78aa5..0add74f50a 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, JSON::ParserError
false
end
diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb
index e2c8a3da23..999a845c83 100644
--- a/spec/unit/knife/bootstrap_spec.rb
+++ b/spec/unit/knife/bootstrap_spec.rb
@@ -94,8 +94,8 @@ describe Chef::Knife::Bootstrap do
@knife.instance_variable_set("@template_file", @knife.config[:template_file])
template_string = @knife.read_template
@knife.parse_options(["-j", '{"foo":{"bar":"baz"}}'])
- expected_hash = Yajl::Parser.new.parse('{"foo":{"bar":"baz"},"run_list":[]}')
- actual_hash = Yajl::Parser.new.parse(@knife.render_template(template_string))
+ expected_hash = FFI_Yajl::Parser.new.parse('{"foo":{"bar":"baz"},"run_list":[]}')
+ actual_hash = FFI_Yajl::Parser.new.parse(@knife.render_template(template_string))
actual_hash.should == expected_hash
end
diff --git a/spec/unit/provider/remote_file/cache_control_data_spec.rb b/spec/unit/provider/remote_file/cache_control_data_spec.rb
index 05fedcfa8b..8e396b1b40 100644
--- a/spec/unit/provider/remote_file/cache_control_data_spec.rb
+++ b/spec/unit/provider/remote_file/cache_control_data_spec.rb
@@ -199,7 +199,7 @@ describe Chef::Provider::RemoteFile::CacheControlData do
it "truncates the file cache path to 102 characters" do
normalized_cache_path = cache_control_data.send('sanitized_cache_file_basename')
- Chef::FileCache.should_receive(:store).with("remote_file/" + normalized_cache_path, cache_control_data.json_data)
+ Chef::FileCache.should_receive(:store).with("remote_file/" + normalized_cache_path, cache_control_data.json_data)
cache_control_data.save