Class: Bootprint::Formatters::Sarif
- Inherits:
-
Object
- Object
- Bootprint::Formatters::Sarif
- Defined in:
- lib/bootprint/formatters/sarif.rb
Constant Summary collapse
- LEVELS =
{ critical: "error", error: "error", warning: "warning", info: "note" }.freeze
Instance Method Summary collapse
-
#initialize(report) ⇒ Sarif
constructor
A new instance of Sarif.
- #render ⇒ Object
Constructor Details
#initialize(report) ⇒ Sarif
Returns a new instance of Sarif.
10 |
# File 'lib/bootprint/formatters/sarif.rb', line 10 def initialize(report) = @report = report |
Instance Method Details
#render ⇒ Object
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 |
# File 'lib/bootprint/formatters/sarif.rb', line 12 def render rules = @report.findings.map(&:rule_id).uniq.map do |id| finding = @report.findings.find { |candidate| candidate.rule_id == id } { "id" => id, "name" => id.tr("-", "_"), "shortDescription" => { "text" => finding.title }, "help" => { "text" => finding.remediation&.fetch("summary", "Review this environment difference.") } } end results = @report.findings.map do |finding| result = { "ruleId" => finding.rule_id, "level" => finding.suppressed ? "none" : LEVELS.fetch(finding.severity), "message" => { "text" => [finding.summary, finding.impact, finding.remediation&.fetch("summary", nil)].compact.join(" ") }, "properties" => { "category" => finding.category.to_s, "evidence" => finding.evidence, "suppressed" => finding.suppressed } } location = physical_location(finding.source_location) result["locations"] = [{ "physicalLocation" => location }] if location result["suppressions"] = [{ "kind" => "external", "justification" => finding.suppression_reason }] if finding.suppressed result end driver = { "name" => "Bootprint", "version" => VERSION, "rules" => rules } run = { "tool" => { "driver" => driver }, "results" => results } output = ::JSON.pretty_generate( "version" => "2.1.0", "$schema" => "https://json.schemastore.org/sarif-2.1.0.json", "runs" => [run] ) "#{output}\n" end |