summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Higgins <pete@peterhiggins.org>2020-11-18 21:03:17 -0800
committerPete Higgins <pete@peterhiggins.org>2020-12-01 16:12:04 -0800
commit41f74394a99bacbc46c49456e8cd1e56d1bc714f (patch)
tree36cc808e256fc5920337bad9cb1792594c6cd34c
parent717caa4dc036a44279d5c5902d5b8aeb80c1fd72 (diff)
downloadchef-41f74394a99bacbc46c49456e8cd1e56d1bc714f.tar.gz
Use the json shim.
Signed-off-by: Pete Higgins <pete@peterhiggins.org>
-rw-r--r--lib/chef/audit/reporter/automate.rb9
-rw-r--r--lib/chef/audit/reporter/chef_server_automate.rb2
2 files changed, 5 insertions, 6 deletions
diff --git a/lib/chef/audit/reporter/automate.rb b/lib/chef/audit/reporter/automate.rb
index 6118955def..23eccd4e58 100644
--- a/lib/chef/audit/reporter/automate.rb
+++ b/lib/chef/audit/reporter/automate.rb
@@ -54,13 +54,12 @@ class Chef
# If the Automate backend has the profile metadata for at least one profile, proceed with metadata stripping
full_report = strip_profiles_meta(full_report, missing_report_shas, 1) if missing_report_shas.length < all_report_shas.length
- json_report = full_report.to_json
+ json_report = Chef::JSONCompat.to_json(full_report, validate_utf8: false)
- report_size = json_report.bytesize
# Automate GRPC currently has a message limit of ~4MB
# https://github.com/chef/automate/issues/1417#issuecomment-541908157
- if report_size > 4 * 1024 * 1024
- Chef::Log.warn "Compliance report size is #{(report_size / (1024 * 1024.0)).round(2)} MB."
+ if json_report.bytesize > 4 * 1024 * 1024
+ Chef::Log.warn "Compliance report size is #{(json_report.bytesize / (1024 * 1024.0)).round(2)} MB."
Chef::Log.warn "Automate has an internal 4MB limit that is not currently configurable."
end
@@ -156,7 +155,7 @@ class Chef
meta_url = URI(@url)
meta_url.path = "/compliance/profiles/metasearch"
response_str = http_client(meta_url.to_s).post(nil, "{\"sha256\": #{report_shas}}", headers)
- missing_shas = JSON.parse(response_str)["missing_sha256"]
+ missing_shas = Chef::JSONCompat.parse(response_str)["missing_sha256"]
unless missing_shas.empty?
Chef::Log.info "Automate is missing metadata for the following profile ids: #{missing_shas}"
end
diff --git a/lib/chef/audit/reporter/chef_server_automate.rb b/lib/chef/audit/reporter/chef_server_automate.rb
index 84b9fb9d62..51f45d6ee9 100644
--- a/lib/chef/audit/reporter/chef_server_automate.rb
+++ b/lib/chef/audit/reporter/chef_server_automate.rb
@@ -35,7 +35,7 @@ class Chef
automate_report = truncate_controls_results(enriched_report(report), @control_results_limit)
- report_size = automate_report.to_json.bytesize
+ report_size = Chef::JSONCompat.to_json(automate_report, validate_utf8: false).bytesize
# this is set to slightly less than the oc_erchef limit
if report_size > 900 * 1024
Chef::Log.warn "Compliance report size is #{(report_size / (1024 * 1024.0)).round(2)} MB."