Class: Brew::Vulns::Vulnerability
- Inherits:
-
Object
- Object
- Brew::Vulns::Vulnerability
- Defined in:
- lib/brew/vulns/vulnerability.rb
Instance Attribute Summary collapse
-
#affected ⇒ Object
readonly
Returns the value of attribute affected.
-
#aliases ⇒ Object
readonly
Returns the value of attribute aliases.
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#references ⇒ Object
readonly
Returns the value of attribute references.
-
#severity ⇒ Object
readonly
Returns the value of attribute severity.
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
Class Method Summary collapse
Instance Method Summary collapse
- #advisory_url ⇒ Object
- #cve_ids ⇒ Object
- #fix_urls ⇒ Object
- #fixed_versions ⇒ Object
-
#initialize(data) ⇒ Vulnerability
constructor
A new instance of Vulnerability.
- #severity_display ⇒ Object
- #severity_level ⇒ Object
Constructor Details
#initialize(data) ⇒ Vulnerability
Returns a new instance of Vulnerability.
8 9 10 11 12 13 14 15 16 |
# File 'lib/brew/vulns/vulnerability.rb', line 8 def initialize(data) @id = data["id"] @summary = data["summary"] @details = data["details"] @aliases = data["aliases"] || [] @references = data["references"] || [] @affected = data["affected"] || [] @severity = extract_severity(data) end |
Instance Attribute Details
#affected ⇒ Object (readonly)
Returns the value of attribute affected.
6 7 8 |
# File 'lib/brew/vulns/vulnerability.rb', line 6 def affected @affected end |
#aliases ⇒ Object (readonly)
Returns the value of attribute aliases.
6 7 8 |
# File 'lib/brew/vulns/vulnerability.rb', line 6 def aliases @aliases end |
#details ⇒ Object (readonly)
Returns the value of attribute details.
6 7 8 |
# File 'lib/brew/vulns/vulnerability.rb', line 6 def details @details end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/brew/vulns/vulnerability.rb', line 6 def id @id end |
#references ⇒ Object (readonly)
Returns the value of attribute references.
6 7 8 |
# File 'lib/brew/vulns/vulnerability.rb', line 6 def references @references end |
#severity ⇒ Object (readonly)
Returns the value of attribute severity.
6 7 8 |
# File 'lib/brew/vulns/vulnerability.rb', line 6 def severity @severity end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
6 7 8 |
# File 'lib/brew/vulns/vulnerability.rb', line 6 def summary @summary end |
Class Method Details
.from_osv_list(vulns_data) ⇒ Object
57 58 59 |
# File 'lib/brew/vulns/vulnerability.rb', line 57 def self.from_osv_list(vulns_data) vulns_data.map { |data| new(data) } end |
Instance Method Details
#advisory_url ⇒ Object
36 37 38 39 |
# File 'lib/brew/vulns/vulnerability.rb', line 36 def advisory_url ref = references.find { |r| r["type"] == "ADVISORY" } ref&.dig("url") end |
#cve_ids ⇒ Object
32 33 34 |
# File 'lib/brew/vulns/vulnerability.rb', line 32 def cve_ids ([id] + aliases).select { |a| a.start_with?("CVE-") } end |
#fix_urls ⇒ Object
41 42 43 |
# File 'lib/brew/vulns/vulnerability.rb', line 41 def fix_urls references.select { |r| r["type"] == "FIX" }.map { |r| r["url"] } end |
#fixed_versions ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/brew/vulns/vulnerability.rb', line 45 def fixed_versions versions = [] affected.each do |aff| (aff["ranges"] || []).each do |range| (range["events"] || []).each do |event| versions << event["fixed"] if event["fixed"] end end end versions.uniq end |
#severity_display ⇒ Object
18 19 20 |
# File 'lib/brew/vulns/vulnerability.rb', line 18 def severity_display severity&.upcase || "UNKNOWN" end |
#severity_level ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/brew/vulns/vulnerability.rb', line 22 def severity_level case severity&.downcase when "critical" then 4 when "high" then 3 when "medium" then 2 when "low" then 1 else 0 end end |