summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authorPete Higgins <pete@peterhiggins.org>2020-12-11 12:22:23 -0800
committerPete Higgins <pete@peterhiggins.org>2020-12-11 12:44:08 -0800
commitce2d4b36cc532732d2631c905f8c7206b496458c (patch)
treead98b9778bd081987bc7943724fd380a6ace82cf /lib/chef
parent2fc41ca52d229f24f3872c68211c13a0a7033c8d (diff)
downloadchef-ce2d4b36cc532732d2631c905f8c7206b496458c.tar.gz
Refactor to separate reporter creation from report sending.
Signed-off-by: Pete Higgins <pete@peterhiggins.org>
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/compliance/reporter/chef_server_automate.rb2
-rw-r--r--lib/chef/compliance/runner.rb26
2 files changed, 19 insertions, 9 deletions
diff --git a/lib/chef/compliance/reporter/chef_server_automate.rb b/lib/chef/compliance/reporter/chef_server_automate.rb
index be59a4cf69..f0eba27816 100644
--- a/lib/chef/compliance/reporter/chef_server_automate.rb
+++ b/lib/chef/compliance/reporter/chef_server_automate.rb
@@ -7,6 +7,8 @@ class Chef
# Used to send inspec reports to Chef Automate server via Chef Server
#
class ChefServerAutomate < Chef::Compliance::Reporter::Automate
+ attr_reader :url
+
def initialize(opts)
@entity_uuid = opts[:entity_uuid]
@run_id = opts[:run_id]
diff --git a/lib/chef/compliance/runner.rb b/lib/chef/compliance/runner.rb
index 828cce9094..789ff74419 100644
--- a/lib/chef/compliance/runner.rb
+++ b/lib/chef/compliance/runner.rb
@@ -201,14 +201,20 @@ class Chef
}
end
- def send_report(reporter, report)
- logger.info "Reporting to #{reporter}"
+ def send_report(reporter_type, report)
+ logger.info "Reporting to #{reporter_type}"
+ reporter = reporter(reporter_type)
+
+ reporter.send_report(report) if reporter
+ end
+
+ def reporter(reporter_type)
insecure = node["audit"]["insecure"]
run_time_limit = node["audit"]["run_time_limit"]
control_results_limit = node["audit"]["control_results_limit"]
- case reporter
+ case reporter_type
when "chef-automate"
opts = {
entity_uuid: node["chef_guid"],
@@ -218,7 +224,7 @@ class Chef
run_time_limit: run_time_limit,
control_results_limit: control_results_limit,
}
- Chef::Compliance::Reporter::Automate.new(opts).send_report(report)
+ Chef::Compliance::Reporter::Automate.new(opts)
when "chef-server-automate"
url = chef_server_automate_url
if url
@@ -231,18 +237,20 @@ class Chef
run_time_limit: run_time_limit,
control_results_limit: control_results_limit,
}
- Chef::Compliance::Reporter::ChefServerAutomate.new(opts).send_report(report)
+ Chef::Compliance::Reporter::ChefServerAutomate.new(opts)
else
- logger.warn "Unable to determine #{ChefUtils::Dist::Server::PRODUCT} url required by #{Inspec::Dist::PRODUCT_NAME} report collector '#{reporter}'. Skipping..."
+ logger.warn "Unable to determine #{ChefUtils::Dist::Server::PRODUCT} url required by #{Inspec::Dist::PRODUCT_NAME} report collector 'chef-server-automate'. Skipping..."
+ nil
end
when "json-file"
path = node["audit"]["json_file"]["location"]
logger.info "Writing compliance report to #{path}"
- Chef::Compliance::Reporter::JsonFile.new(file: path).send_report(report)
+ Chef::Compliance::Reporter::JsonFile.new(file: path)
when "audit-enforcer"
- Chef::Compliance::Reporter::ComplianceEnforcer.new.send_report(report)
+ Chef::Compliance::Reporter::ComplianceEnforcer.new
else
- logger.warn "#{reporter} is not a supported #{Inspec::Dist::PRODUCT_NAME} report collector"
+ logger.warn "'#{reporter_type}' is not a supported #{Inspec::Dist::PRODUCT_NAME} report collector"
+ nil
end
end