Sha256: dd95049abf0f982724b42852df2b90b0e3f7a61eb94bae0abbc81d49f2520a8c

Contents?: true

Size: 1.49 KB

Versions: 48

Compression:

Stored size: 1.49 KB

Contents

require "json" unless defined?(JSON)

module InspecPlugins::JsonMinReporter
  class Reporter < Inspec.plugin(2, :reporter)
    def self.run_data_schema_constraints
      "~> 0.0"
    end

    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

        profile.controls.each do |control|
          control_id = control.id

          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.non_nil?(:skip_message)
            result_for_report[:resource] = result.resource if result.non_nil?(:resource)
            result_for_report[:message] = result.message if result.non_nil?(:message)
            result_for_report[:exception] = result.exception if result.non_nil?(:exception)
            result_for_report[:backtrace] = result.backtrace if result.non_nil?(:backtrace)

            report[:controls] << result_for_report
          end
        end
      end

      report
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
inspec-core-6.8.11 lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min/reporter.rb
inspec-core-5.22.58 lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min/reporter.rb
inspec-core-5.22.55 lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min/reporter.rb
inspec-core-6.8.1 lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min/reporter.rb
inspec-core-5.22.40 lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min/reporter.rb
inspec-core-6.6.0 lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min/reporter.rb
inspec-core-5.22.36 lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min/reporter.rb
inspec-core-5.22.29 lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min/reporter.rb
inspec-core-4.56.58 lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min/reporter.rb
inspec-core-5.22.3 lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min/reporter.rb
inspec-core-5.21.29 lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min/reporter.rb
inspec-core-5.18.14 lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min/reporter.rb
inspec-core-5.17.4 lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min/reporter.rb
inspec-core-5.14.0 lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min/reporter.rb
inspec-core-4.56.20 lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min/reporter.rb
inspec-core-5.12.2 lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min/reporter.rb
inspec-core-5.10.5 lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min/reporter.rb
inspec-core-4.56.19 lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min/reporter.rb
inspec-core-5.7.9 lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min/reporter.rb
inspec-core-4.56.17 lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min/reporter.rb