Skip to content

Commit

Permalink
raise exception if the minimum InSpec version is not available
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Hartmann <chris@lollyrock.com>
  • Loading branch information
chris-rock committed Jul 3, 2017
1 parent bcd5c4a commit b1789a0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ suites:
attributes:
audit:
collector: json-file
inspec_version: 1.20.0
inspec_version: 1.29.0
fail_if_not_present: true
- name: skip-inspec-gem-install
run_list:
Expand All @@ -130,5 +130,5 @@ suites:
attributes:
audit:
collector: json-file
inspec_version: 1.19.1
inspec_version: 1.25.1
fail_if_not_present: true
8 changes: 4 additions & 4 deletions files/default/handler/audit_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class Chef
class Handler
# Creates a compliance audit report
class AuditReport < ::Chef::Handler
MIN_INSPEC_VERSION = '1.25.1'.freeze

def report
# get reporter(s) from attributes as an array
reporters = get_reporters(node['audit'])
Expand Down Expand Up @@ -125,10 +127,8 @@ def get_opts(format, quiet)
# run profiles and return report
def call(opts, profiles)
Chef::Log.info "Using InSpec #{::Inspec::VERSION}"

if Gem::Version.new(Inspec::VERSION) < Gem::Version.new('1.24.0')
Chef::Log.error "This audit cookbook version requires InSpec 1.24.0 or newer, aborting compliance scan..."
return {}
if Gem::Version.new(::Inspec::VERSION) < Gem::Version.new(MIN_INSPEC_VERSION)
raise "This audit cookbook version requires InSpec #{MIN_INSPEC_VERSION} or newer, aborting compliance scan..."
end

Chef::Log.debug "Options are set to: #{opts}"
Expand Down
2 changes: 1 addition & 1 deletion test/integration/gem-install-version/default.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# verify that a specific inspec version is installed
describe gem('inspec', :chef) do
it { should be_installed }
its('version') { should cmp '1.20.0'}
its('version') { should cmp '1.29.0'}
end
2 changes: 1 addition & 1 deletion test/integration/skip-inspec-gem-install/default.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# verify that a specific inspec version is installed
describe gem('inspec', :chef) do
it { should be_installed }
its('version') { should cmp '1.19.1'}
its('version') { should cmp '1.25.1'}
end

0 comments on commit b1789a0

Please sign in to comment.