Class: Bootprint::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/bootprint/diagnosis.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, target:, findings:, policy:, duration_ms:) ⇒ Report

Returns a new instance of Report.



51
52
53
54
55
56
57
# File 'lib/bootprint/diagnosis.rb', line 51

def initialize(source:, target:, findings:, policy:, duration_ms:)
  @source = source
  @target = target
  @findings = findings.sort_by { |finding| [-Rules::SEVERITY_ORDER.fetch(finding.severity), finding.rule_id] }
  @policy = policy
  @duration_ms = duration_ms
end

Instance Attribute Details

#duration_msObject (readonly)

Returns the value of attribute duration_ms.



49
50
51
# File 'lib/bootprint/diagnosis.rb', line 49

def duration_ms
  @duration_ms
end

#findingsObject (readonly)

Returns the value of attribute findings.



49
50
51
# File 'lib/bootprint/diagnosis.rb', line 49

def findings
  @findings
end

#policyObject (readonly)

Returns the value of attribute policy.



49
50
51
# File 'lib/bootprint/diagnosis.rb', line 49

def policy
  @policy
end

#sourceObject (readonly)

Returns the value of attribute source.



49
50
51
# File 'lib/bootprint/diagnosis.rb', line 49

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



49
50
51
# File 'lib/bootprint/diagnosis.rb', line 49

def target
  @target
end

Instance Method Details

#blocking?Boolean

Returns:

  • (Boolean)


59
# File 'lib/bootprint/diagnosis.rb', line 59

def blocking? = findings.any? { |finding| finding.blocking?(policy) }

#countsObject



61
62
63
64
65
66
# File 'lib/bootprint/diagnosis.rb', line 61

def counts
  Rules::Rule::SEVERITIES.to_h do |severity|
    count = findings.count { |finding| finding.severity == severity && !finding.suppressed }
    [severity.to_s, count]
  end
end

#to_hObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/bootprint/diagnosis.rb', line 68

def to_h
  {
    "schema_version" => Diagnosis::REPORT_SCHEMA_VERSION,
    "source" => (source),
    "target" => (target),
    "findings" => findings.map(&:to_h),
    "summary" => counts.merge("blocking" => blocking?),
    "execution" => {
      "bootprint_version" => VERSION,
      "duration_ms" => duration_ms,
      "network_requests" => 0,
      "policy" => policy.path
    }
  }
end