CFINSPEC-181: Fix unable to upload inspec compliance profile using to Chef Automate.

Add --with-cookstyle option to inspec check command to disable cookstyle check as default

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>
This commit is contained in:
Vasu1105 2022-04-14 21:47:10 +05:30
parent 7d1ad0acc3
commit 07f6793533
3 changed files with 13 additions and 9 deletions

View file

@ -95,6 +95,8 @@ class Inspec::InspecCLI < Inspec::BaseCLI
desc "check PATH", "verify all tests at the specified PATH"
option :format, type: :string,
desc: "The output format to use doc (default), json. If valid format is not provided then it will use the default."
option :with_cookstyle, type: :boolean,
desc: "Enable or disable cookstyle checks.", default: false
profile_options
def check(path) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
o = config

View file

@ -105,6 +105,7 @@ module Inspec
@check_mode = options[:check_mode] || false
@parent_profile = options[:parent_profile]
@legacy_profile_path = options[:profiles_path] || false
@check_cookstyle = options[:with_cookstyle]
Metadata.finalize(@source_reader.metadata, @profile_id, options)
# if a backend has already been created, clone it so each profile has its own unique backend object
@ -655,12 +656,13 @@ module Inspec
end
# Running cookstyle to check for code offenses
cookstyle_linting_check.each do |lint_output|
data = lint_output.split(":")
msg = "#{data[-2]}:#{data[-1]}"
offense.call(data[0], data[1], data[2], nil, msg)
if @check_cookstyle
cookstyle_linting_check.each do |lint_output|
data = lint_output.split(":")
msg = "#{data[-2]}:#{data[-1]}"
offense.call(data[0], data[1], data[2], nil, msg)
end
end
# profile is valid if we could not find any error & offenses
result[:summary][:valid] = result[:errors].empty? && result[:offenses].empty?

View file

@ -118,16 +118,16 @@ describe "inspec check" do
end
describe "inspec check also check for cookstyle offenses" do
it "finds no offenses in a complete profile" do
it "finds no offenses in a complete profile when --with-cookstyle option is provided" do
skip if windows? # see #5723
out = inspec("check #{profile_path}/complete-profile")
out = inspec("check #{profile_path}/complete-profile --with-cookstyle")
_(out.stdout).must_match(/No errors, warnings, or offenses/)
assert_exit_code 0, out
end
it "fails and returns offenses in a profile" do
it "fails and returns offenses in a profile when --with-cookstyle option is provided" do
skip if windows? # see #5723
out = inspec("check #{profile_path}/inputs/metadata-basic")
out = inspec("check #{profile_path}/inputs/metadata-basic --with-cookstyle")
_(out.stdout).must_match(/1 offenses/)
assert_exit_code 1, out
end