diff options
author | Tim Smith <tsmith@chef.io> | 2021-11-09 17:31:23 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-09 17:31:23 -0800 |
commit | cb35be37091d491c96656000509ab923c38cdcc3 (patch) | |
tree | 6ecc29fa2a1a0ff80275641db14f80866603694d | |
parent | 0615e4234967a476f0e3168f57430e57143a4567 (diff) | |
parent | f32301f8748c9480b7c95e7057566dad47cf0197 (diff) | |
download | chef-cb35be37091d491c96656000509ab923c38cdcc3.tar.gz |
Merge pull request #12241 from chef/lcg/compliance-cli-reporter
Make the compliance CLI reporter always run
-rw-r--r-- | lib/chef/compliance/default_attributes.rb | 2 | ||||
-rw-r--r-- | lib/chef/compliance/runner.rb | 8 | ||||
-rw-r--r-- | spec/unit/compliance/runner_spec.rb | 3 |
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..ade35d4861 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"]).uniq + 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 |