summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2015-04-24 15:07:23 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2015-05-04 10:57:09 -0700
commita874fce5a4f7e79f7319e5959b6802ad48c45344 (patch)
treed919ff6fa67e22dca22fa55dd868280398065530
parente2b7e4e76cd8dae088299137d991a0455d87a109 (diff)
downloadchef-a874fce5a4f7e79f7319e5959b6802ad48c45344.tar.gz
use validate_utf8=false option to json encoder for node
with validation off any bad utf8 data will not cause the ffi-yajl encoder to raise. with ffi-yajl >= 2.2.0 the bad data will be scrubbed to produce valid JSON to POST/PUT to the server.
-rw-r--r--chef.gemspec2
-rw-r--r--lib/chef/http/json_input.rb7
-rw-r--r--lib/chef/node.rb2
3 files changed, 8 insertions, 3 deletions
diff --git a/chef.gemspec b/chef.gemspec
index 8bec26ea7c..ec600f1f89 100644
--- a/chef.gemspec
+++ b/chef.gemspec
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
s.add_dependency "mixlib-shellout", ">= 2.0.0.rc.0", "< 3.0"
s.add_dependency "ohai", "~> 8.0"
- s.add_dependency "ffi-yajl", ">= 1.2", "< 3.0"
+ s.add_dependency "ffi-yajl", "~> 2.2"
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/http/json_input.rb b/lib/chef/http/json_input.rb
index 23ccc3a8a7..3296d8821f 100644
--- a/lib/chef/http/json_input.rb
+++ b/lib/chef/http/json_input.rb
@@ -25,14 +25,19 @@ class Chef
# Middleware that takes json input and turns it into raw text
class JSONInput
+ attr_accessor :opts
+
def initialize(opts={})
+ @opts = opts
end
def handle_request(method, url, headers={}, data=false)
if data && should_encode_as_json?(headers)
headers.delete_if { |key, _value| key.downcase == 'content-type' }
headers["Content-Type"] = 'application/json'
- data = Chef::JSONCompat.to_json(data)
+ json_opts = {}
+ json_opts[:validate_utf8] = opts[:validate_utf8] if opts.has_key?(:validate_utf8)
+ data = Chef::JSONCompat.to_json(data, json_opts)
# Force encoding to binary to fix SSL related EOFErrors
# cf. http://tickets.opscode.com/browse/CHEF-2363
# http://redmine.ruby-lang.org/issues/5233
diff --git a/lib/chef/node.rb b/lib/chef/node.rb
index 9823185ede..cc79a187a9 100644
--- a/lib/chef/node.rb
+++ b/lib/chef/node.rb
@@ -83,7 +83,7 @@ class Chef
end
def chef_server_rest
- @chef_server_rest ||= Chef::REST.new(Chef::Config[:chef_server_url])
+ @chef_server_rest ||= Chef::REST.new(Chef::Config[:chef_server_url], Chef::Config[:node_name], Chef::Config[:client_key], validate_utf8: false)
end
# Set the name of this Node, or return the current name.