diff --git a/attributes/default.rb b/attributes/default.rb index bf3fc24e..f9dae21e 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -46,8 +46,8 @@ # fail converge after posting report if any audits have failed default['audit']['fail_if_any_audits_failed'] = false -# inspec gem version to install(e.g. '0.22.1') or 'latest' -default['audit']['inspec_version'] = '1.0.0' +# inspec gem version to install(e.g. '1.1.0') +default['audit']['inspec_version'] = '1.1.0' # by default run audit every time default['audit']['interval']['enabled'] = false diff --git a/libraries/compliance.rb b/libraries/compliance.rb index c0cc0aa9..b2f4e37e 100644 --- a/libraries/compliance.rb +++ b/libraries/compliance.rb @@ -6,7 +6,8 @@ def retrieve_access_token(server_url, refresh_token, insecure) require 'bundles/inspec-compliance/api' require 'bundles/inspec-compliance/http' require 'bundles/inspec-compliance/configuration' - success, msg, access_token = Compliance::API.post_refresh_token(server_url, refresh_token, insecure) + # get_token_via_refresh_token is provided by the inspec-compliance plugin bundled in InSpec + success, msg, access_token = Compliance::API.get_token_via_refresh_token(server_url, refresh_token, insecure) # TODO: we return always the access token, without proper error handling unless success Chef::Log.error("Unable to get a Chef Compliance API access_token: #{msg}") diff --git a/libraries/report.rb b/libraries/report.rb index beed405f..e86a8e1d 100644 --- a/libraries/report.rb +++ b/libraries/report.rb @@ -27,19 +27,17 @@ class ComplianceReport < Chef::Resource blob = node_info blob[:reports] = reports blob[:profiles] = ownermap - total_failed = reports.map do |_name, report| - report['profiles'].map do |profile| + + total_failed = reports.map do |_name, profile| + if !profile['controls'].empty? profile['controls'].map do |control| - if control['results'] - control['results'].map do |result| - result['status'] != 'passed' ? 1 : 0 - end - else - 0 - end + control['status'] != 'passed' ? 1 : 0 end + else + 0 end end.flatten.reduce(:+) + Chef::Log.info "Total number of failed controls: #{total_failed}" # resolve owner o = return_or_guess_owner diff --git a/metadata.rb b/metadata.rb index 4ca54064..062799cb 100644 --- a/metadata.rb +++ b/metadata.rb @@ -5,7 +5,7 @@ license 'Apache 2.0' description 'Allows for fetching and executing compliance profiles, and reporting its results' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '1.0.0' +version '1.0.1' source_url 'https://github.com/chef-cookbooks/audit' issues_url 'https://github.com/chef-cookbooks/audit/issues'