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

Use the new method to retrieve access tokens and fix total_failed bug #103

Merged
merged 1 commit into from Oct 6, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions attributes/default.rb
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion libraries/compliance.rb
Expand Up @@ -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}")
Expand Down
16 changes: 7 additions & 9 deletions libraries/report.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion metadata.rb
Expand Up @@ -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'
Expand Down