Class: Inspec::Reporters::JsonMin

Inherits:
Base
  • Object
show all
Defined in:
lib/inspec/reporters/json_min.rb

Instance Attribute Summary

Attributes inherited from Base

#run_data

Instance Method Summary collapse

Methods inherited from Base

#initialize, #output, #rendered_output

Constructor Details

This class inherits a constructor from Inspec::Reporters::Base

Instance Method Details

#renderObject



5
6
7
# File 'lib/inspec/reporters/json_min.rb', line 5

def render
  output(report.to_json, false)
end

#reportObject

rubocop:disable Metrics/AbcSize



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/inspec/reporters/json_min.rb', line 9

def report # rubocop:disable Metrics/AbcSize
  report = {
    controls: [],
    statistics: { duration: run_data[:statistics][:duration] },
    version: run_data[:version],
  }

  # collect all test results and add them to the report
  run_data[:profiles].each do |profile|
    profile_id = profile[:name]
    next unless profile[:controls]

    profile[:controls].each do |control|
      control_id = control[:id]
      next unless control[:results]

      control[:results].each do |result|
        result_for_report = {
          id: control_id,
          profile_id: profile_id,
          profile_sha256: profile[:sha256],
          status: result[:status],
          code_desc: result[:code_desc],
        }

        result_for_report[:skip_message] = result[:skip_message] if result.key?(:skip_message)
        result_for_report[:resource] = result[:resource] if result.key?(:resource)
        result_for_report[:message] = result[:message] if result.key?(:message)
        result_for_report[:exception] = result[:exception] if result.key?(:exception)
        result_for_report[:backtrace] = result[:backtrace] if result.key?(:backtrace)

        report[:controls] << result_for_report
      end
    end
  end

  report
end