Class: SeccompTools::Audit::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/seccomp-tools/audit/report.rb

Overview

The findings for one filter, rendered either as a human report or a JSON-ready hash.

Constant Summary collapse

SEVERITY_THEME =

Severity => Util.colorize theme for the [SEVERITY] tag.

{ high: :error, medium: :warn, low: :info }.freeze
WIDTH =

Widest a rendered line may get, so a finding reads without wrapping on a standard terminal.

120

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, arches:, findings:, truncated:) ⇒ Report

Returns a new instance of Report.

Parameters:

  • source (String?)

    Label for the audited filter.

  • arches (Array<String>)

    The architectures covered.

  • findings (Array<Finding>)
  • truncated (Boolean)

    Whether the symbolic walk was cut short.



20
21
22
23
24
25
# File 'lib/seccomp-tools/audit/report.rb', line 20

def initialize(source:, arches:, findings:, truncated:)
  @source = source
  @arches = arches
  @findings = findings.sort_by(&:rank)
  @truncated = truncated
end

Instance Attribute Details

#archesArray<String> (readonly)

Returns The architectures covered.

Returns:

  • (Array<String>)

    The architectures covered.



30
31
32
# File 'lib/seccomp-tools/audit/report.rb', line 30

def arches
  @arches
end

#findingsArray<Finding> (readonly)

Returns:



28
29
30
# File 'lib/seccomp-tools/audit/report.rb', line 28

def findings
  @findings
end

Instance Method Details

#to_hHash

Returns JSON-ready shape for one filter.

Returns:

  • (Hash)

    JSON-ready shape for one filter.



48
49
50
# File 'lib/seccomp-tools/audit/report.rb', line 48

def to_h
  { source: @source, arches: @arches, truncated: @truncated, findings: @findings.map(&:to_h) }
end

#to_sString

The human report.

Returns:

  • (String)


34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/seccomp-tools/audit/report.rb', line 34

def to_s
  out = +''
  out << "Seccomp audit of #{@source}\n" if @source
  out << "Architectures: #{@arches.join(', ')}\n" unless @arches.empty?
  # A truncated walk can only hide weaknesses, so it qualifies the whole report rather than
  # being a finding of its own.
  out << "WARNING: analysis truncated (filter too large); results may be incomplete.\n" if @truncated
  return out << "\nNo weaknesses found.\n" if @findings.empty?

  @findings.each { |f| out << render(f) }
  out
end