summaryrefslogtreecommitdiff
path: root/lib/chef/compliance/reporter/compliance_enforcer.rb
blob: 1c63e43b28d605280ae7afc310735c61d92066e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Chef
  module Compliance
    module Reporter
      class AuditEnforcer
        class ControlFailure < StandardError; end

        def send_report(report)
          report.fetch(:profiles, []).each do |profile|
            profile.fetch(:controls, []).each do |control|
              control.fetch(:results, []).each do |result|
                raise ControlFailure, "Audit #{control[:id]} has failed. Aborting #{ChefUtils::Dist::Infra::CLIENT} run." if result[:status] == "failed"
              end
            end
          end
          true
        end
      end
    end
  end
end