summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2021-11-04 14:23:16 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2021-11-04 14:23:16 -0700
commit75b8fe9a5994834cf1d9114f53cdfc4aa10adb78 (patch)
treee9d6fb4877b28fab6967727385d697b2021b5309
parent3e3aeef2cdd4f7c47416df3f51d06398adb6ea7b (diff)
downloadchef-75b8fe9a5994834cf1d9114f53cdfc4aa10adb78.tar.gz
Make the compliance CLI reporter always run
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/compliance/default_attributes.rb2
-rw-r--r--lib/chef/compliance/runner.rb8
-rw-r--r--spec/unit/compliance/runner_spec.rb3
3 files changed, 9 insertions, 4 deletions
diff --git a/lib/chef/compliance/default_attributes.rb b/lib/chef/compliance/default_attributes.rb
index 24bf72330b..3ecb1cd056 100644
--- a/lib/chef/compliance/default_attributes.rb
+++ b/lib/chef/compliance/default_attributes.rb
@@ -28,7 +28,7 @@ class Chef
# Controls what is done with the resulting report after the Chef InSpec run.
# Accepts a single string value or an array of multiple values.
# Accepted values: 'chef-server-automate', 'chef-automate', 'json-file', 'audit-enforcer', 'cli'
- "reporter" => "cli",
+ "reporter" => nil,
# Controls if Chef InSpec profiles should be fetched from Chef Automate or Chef Infra Server
# in addition to the default fetch locations provided by Chef Inspec.
diff --git a/lib/chef/compliance/runner.rb b/lib/chef/compliance/runner.rb
index b00008fa51..e378f6c8d7 100644
--- a/lib/chef/compliance/runner.rb
+++ b/lib/chef/compliance/runner.rb
@@ -118,7 +118,7 @@ class Chef
return
end
- Array(node["audit"]["reporter"]).each do |reporter_type|
+ requested_reporters.each do |reporter_type|
logger.info "Reporting to #{reporter_type}"
@reporters[reporter_type].send_report(report)
end
@@ -325,7 +325,7 @@ class Chef
@reporters = {}
# Note that the docs don't say you can use an array, but our implementation
# supports it.
- Array(node["audit"]["reporter"]).each do |type|
+ requested_reporters.each do |type|
unless SUPPORTED_REPORTERS.include? type
raise "CMPL003: '#{type}' found in node['audit']['reporter'] is not a supported reporter for Compliance Phase. Supported reporters are: #{SUPPORTED_REPORTERS.join(", ")}. For more information, see the documentation at https://docs.chef.io/chef_compliance_phase#reporters"
end
@@ -358,6 +358,10 @@ class Chef
def safe_input_collection
run_context&.input_collection
end
+
+ def requested_reporters
+ Array(node["audit"]["reporter"]) + ["cli"]
+ end
end
end
end
diff --git a/spec/unit/compliance/runner_spec.rb b/spec/unit/compliance/runner_spec.rb
index c1a0855f78..602d675d4d 100644
--- a/spec/unit/compliance/runner_spec.rb
+++ b/spec/unit/compliance/runner_spec.rb
@@ -216,6 +216,7 @@ describe Chef::Compliance::Runner do
node.normal["audit"]["reporter"] = [ "chef-automate" ]
reporter_double = double("reporter", validate_config!: nil)
expect(runner).to receive(:reporter).with("chef-automate").and_return(reporter_double)
+ expect(runner).to receive(:reporter).with("cli").and_return(reporter_double)
runner.load_and_validate!
end
@@ -278,7 +279,7 @@ describe Chef::Compliance::Runner do
inputs = runner.inspec_opts[:inputs]
expect(inputs["tacos"]).to eq("lunch")
- expect(inputs["chef_node"]["audit"]["reporter"]).to eq("cli")
+ expect(inputs["chef_node"]["audit"]["reporter"]).to eq(nil)
expect(inputs["chef_node"]["chef_environment"]).to eq("_default")
end
end