Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure min version of inspec is used #237

Merged
merged 2 commits into from
Jul 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 7 additions & 1 deletion 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 @@ -124,7 +126,11 @@ def get_opts(format, quiet)

# run profiles and return report
def call(opts, profiles)
Chef::Log.info "Initialize InSpec #{::Inspec::VERSION}"
Chef::Log.info "Using InSpec #{::Inspec::VERSION}"
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}"
runner = ::Inspec::Runner.new(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