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 Jun 29, 2017
1 parent 872c1a1 commit b5347fd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions files/default/handler/audit_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ class Chef
class Handler
# Creates a compliance audit report
class AuditReport < ::Chef::Handler

MIN_INSPEC_VERSION = '1.25.1'

def report
# get reporter(s) from attributes as an array
reporters = get_reporters(node['audit'])
Expand Down Expand Up @@ -125,10 +128,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

0 comments on commit b5347fd

Please sign in to comment.