Sha256: c77892ab6a9e6ad69ba562f1e5120ac0f5832f823d61a0add0eeeae78df35f80

Contents?: true

Size: 1.52 KB

Versions: 6

Compression:

Stored size: 1.52 KB

Contents

# encoding: utf-8

require 'json'

module Inspec::Reporters
  class JsonMin < Base
    def render
      output(report.to_json, false)
    end

    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
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
inspec-2.1.81 lib/inspec/reporters/json_min.rb
inspec-2.1.21 lib/inspec/reporters/json_min.rb
inspec-2.1.10 lib/inspec/reporters/json_min.rb
inspec-2.0.32 lib/inspec/reporters/json_min.rb
inspec-2.0.17 lib/inspec/reporters/json_min.rb
inspec-1.51.15 lib/inspec/reporters/json_min.rb