summaryrefslogtreecommitdiff
path: root/lib/chef/client.rb
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-01-26 13:46:16 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2016-01-26 13:46:16 -0800
commit11756f5f428ba0b1fc72648c7605c2ffdb364677 (patch)
treeece69e6199e9b9fc4f9d19549c486d510dc3e510 /lib/chef/client.rb
parent8d32dc4a67b03362b04e0a5eda717cb85dff9f27 (diff)
downloadchef-11756f5f428ba0b1fc72648c7605c2ffdb364677.tar.gz
suppress reporter failures by using validate_utf8=falselcg/suppress-reporter-failures
- doesn't turn off the utf8 validation in the rest of the rest API - has to use a different rest object because we have to pass options in the constructor - the handling of Chef::Config in Chef::Client is just awful
Diffstat (limited to 'lib/chef/client.rb')
-rw-r--r--lib/chef/client.rb24
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/chef/client.rb b/lib/chef/client.rb
index a524a9cd54..42b7084787 100644
--- a/lib/chef/client.rb
+++ b/lib/chef/client.rb
@@ -97,6 +97,14 @@ class Chef
attr_reader :rest
#
+ # A rest object with validate_utf8 set to false. This will not throw exceptions
+ # on non-UTF8 strings in JSON but will sanitize them so that e.g. POSTs will
+ # never fail. Cannot be configured on a request-by-request basis, so we carry
+ # around another rest object for it.
+ #
+ attr_reader :rest_clean
+
+ #
# The runner used to converge.
#
# @return [Chef::Runner]
@@ -385,13 +393,23 @@ class Chef
end
end
+ # Rest client for use by API reporters. This rest client will not fail with an exception if
+ # it is fed non-UTF8 data.
+ #
+ # @api private
+ def rest_clean(client_name=node_name, config=Chef::Config)
+ @rest_clean ||=
+ Chef::ServerAPI.new(config[:chef_server_url], client_name: client_name,
+ signing_key_filename: config[:client_key], validate_utf8: false)
+ end
+
# Resource reporters send event information back to the chef server for
# processing. Can only be called after we have a @rest object
# @api private
def register_reporters
[
- Chef::ResourceReporter.new(rest),
- Chef::Audit::AuditReporter.new(rest),
+ Chef::ResourceReporter.new(rest_clean),
+ Chef::Audit::AuditReporter.new(rest_clean),
].each do |r|
events.register(r)
end
@@ -603,6 +621,8 @@ class Chef
# We now have the client key, and should use it from now on.
@rest = Chef::ServerAPI.new(config[:chef_server_url], client_name: client_name,
signing_key_filename: config[:client_key])
+ # force initialization of ther rest_clean API object
+ rest_clean(client_name, config)
register_reporters
rescue Exception => e
# TODO this should probably only ever fire if we *started* registration.