Class: SecureKeys::Validation::ScanResult

Inherits:
Object
  • Object
show all
Defined in:
lib/validation/models/scan_result.rb

Overview

Aggregates all findings from a single scan run

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(findings:, files_count:) ⇒ ScanResult

Initialize a new scan result

Parameters:

  • findings (Array<Finding>)

    The list of detected secrets

  • files_count (Integer)

    The total number of files (or diff lines) scanned



12
13
14
15
# File 'lib/validation/models/scan_result.rb', line 12

def initialize(findings:, files_count:)
  @findings = findings
  @files_count = files_count
end

Instance Attribute Details

#files_countObject (readonly)

Returns the value of attribute files_count.



7
8
9
# File 'lib/validation/models/scan_result.rb', line 7

def files_count
  @files_count
end

#findingsObject (readonly)

Returns the value of attribute findings.



7
8
9
# File 'lib/validation/models/scan_result.rb', line 7

def findings
  @findings
end

Instance Method Details

#by_severity(severity:) ⇒ Array<Finding>

Returns findings filtered by a specific severity level

Parameters:

  • severity (Symbol)

    The severity to filter by (:low, :medium, :high, :critical)

Returns:

  • (Array<Finding>)

    Findings matching the given severity



26
27
28
# File 'lib/validation/models/scan_result.rb', line 26

def by_severity(severity:)
  findings.select { |finding| finding.severity == severity }
end

#clean?Boolean

Check if the scan produced no findings

Returns:

  • (Boolean)

    true if no secrets were detected



19
20
21
# File 'lib/validation/models/scan_result.rb', line 19

def clean?
  findings.empty?
end

#to_hHash

Returns a hash representation of the scan result

Returns:

  • (Hash)

    The hash representation, suitable for JSON export



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/validation/models/scan_result.rb', line 32

def to_h
  {
    files_scanned: files_count,
    total_findings: findings.length,
    by_severity: {
      critical: by_severity(severity: :critical).length,
      high: by_severity(severity: :high).length,
      medium: by_severity(severity: :medium).length,
      low: by_severity(severity: :low).length,
    },
    findings: findings.map(&:to_h),
  }
end