Class: ForemanCveScanner::CveReportScanner
- Inherits:
-
Object
- Object
- ForemanCveScanner::CveReportScanner
- Defined in:
- app/services/foreman_cve_scanner/cve_report_scanner.rb
Overview
Parses raw CVE scanner reports and produces unified logs/metrics. rubocop:disable Metrics/ClassLength
Constant Summary collapse
- SEVERITY_ORDER =
%w[CRITICAL HIGH MEDIUM LOW UNKNOWN].freeze
Instance Attribute Summary collapse
-
#logs ⇒ Object
readonly
Returns the value of attribute logs.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
- .cve_scanner_report?(raw) ⇒ Boolean
- .detect_scanner(scan_json) ⇒ Object
- .identify_origin(raw) ⇒ Object
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(raw) ⇒ CveReportScanner
constructor
A new instance of CveReportScanner.
- #metrics ⇒ Object
- #unified_vulnerabilities ⇒ Object
Constructor Details
#initialize(raw) ⇒ CveReportScanner
Returns a new instance of CveReportScanner.
17 18 19 20 |
# File 'app/services/foreman_cve_scanner/cve_report_scanner.rb', line 17 def initialize(raw) @raw_data = raw @cve_report_data = generate_unified_vuls end |
Instance Attribute Details
#logs ⇒ Object (readonly)
Returns the value of attribute logs.
31 32 33 |
# File 'app/services/foreman_cve_scanner/cve_report_scanner.rb', line 31 def logs @logs end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
31 32 33 |
# File 'app/services/foreman_cve_scanner/cve_report_scanner.rb', line 31 def status @status end |
Class Method Details
.cve_scanner_report?(raw) ⇒ Boolean
13 14 15 |
# File 'app/services/foreman_cve_scanner/cve_report_scanner.rb', line 13 def self.cve_scanner_report?(raw) raw['reporter'] == 'cve_scan' end |
.detect_scanner(scan_json) ⇒ Object
37 38 39 40 41 42 |
# File 'app/services/foreman_cve_scanner/cve_report_scanner.rb', line 37 def self.detect_scanner(scan_json) return 'grype' if scan_json.is_a?(Hash) && scan_json.key?('matches') return 'trivy' if scan_json.is_a?(Hash) && scan_json.key?('Results') 'unknown' end |
.identify_origin(raw) ⇒ Object
9 10 11 |
# File 'app/services/foreman_cve_scanner/cve_report_scanner.rb', line 9 def self.identify_origin(raw) 'CveScanner' if cve_scanner_report?(raw) end |
Instance Method Details
#generate ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'app/services/foreman_cve_scanner/cve_report_scanner.rb', line 22 def generate @status = {} @logs = [] @cve_report_data.each do |id, cve| @logs << generate_log_from_unified(id, cve) end @logs end |
#metrics ⇒ Object
44 45 46 47 48 49 |
# File 'app/services/foreman_cve_scanner/cve_report_scanner.rb', line 44 def metrics known = %w[critical high medium low] res = @status.slice(*known) res['total'] = res.values.sum res end |
#unified_vulnerabilities ⇒ Object
33 34 35 |
# File 'app/services/foreman_cve_scanner/cve_report_scanner.rb', line 33 def unified_vulnerabilities @cve_report_data end |