Class: Homebrew::Vulns::Match::Hit Private

Inherits:
Object
  • Object
show all
Defined in:
vulns/match.rb

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vulnerability:, evidence:) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Raises:

  • (ArgumentError)


107
108
109
110
111
112
113
114
115
116
# File 'vulns/match.rb', line 107

def initialize(vulnerability:, evidence:)
  raise ArgumentError, "Hit requires at least one Evidence" if evidence.empty?

  @vulnerability = vulnerability
  @evidence = T.let(
    evidence.map { |e| e.with_source(vulnerability) }
            .sort_by { |e| -STRATEGY_PRECISION.fetch(e.strategy) }.freeze,
    T::Array[Evidence],
  )
end

Instance Attribute Details

#evidence ⇒ Array<Evidence> (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



104
105
106
# File 'vulns/match.rb', line 104

def evidence
  @evidence
end

#vulnerability ⇒ Vulnerability (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



101
102
103
# File 'vulns/match.rb', line 101

def vulnerability
  @vulnerability
end

Instance Method Details

#canonical_id ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



134
135
136
# File 'vulns/match.rb', line 134

def canonical_id
  vulnerability.cve_ids.min || vulnerability.id
end

#identifiers ⇒ Array<String>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



139
140
141
142
143
# File 'vulns/match.rb', line 139

def identifiers
  evidence.flat_map { |item| item.source_record&.identifiers || [] }
          .prepend(*vulnerability.identifiers)
          .uniq
end

#primary_evidence ⇒ Evidence

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



119
120
121
# File 'vulns/match.rb', line 119

def primary_evidence
  evidence.fetch(0)
end

#resource ⇒ String?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



129
130
131
# File 'vulns/match.rb', line 129

def resource
  primary_evidence.resource
end

#strategy ⇒ Symbol

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



124
125
126
# File 'vulns/match.rb', line 124

def strategy
  primary_evidence.strategy
end