Class: ForemanCveScanner::CveReportScanner

Inherits:
Object
  • Object
show all
Defined in:
app/services/foreman_cve_scanner/cve_report_scanner.rb

Overview

Scans ConfigReports after import for indicators of an CveScanner report and sets the origin of the report to ‘CveScanner’

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ CveReportScanner

Returns a new instance of CveReportScanner.



24
25
26
27
# File 'app/services/foreman_cve_scanner/cve_report_scanner.rb', line 24

def initialize(raw)
  @raw_data = raw
  @cve_report_data = generate_unified_vuls
end

Class Method Details

.add_reporter_data(_report, raw) ⇒ Object



7
8
9
10
11
12
13
14
# File 'app/services/foreman_cve_scanner/cve_report_scanner.rb', line 7

def self.add_reporter_data(_report, raw)
  scanner = ForemanCveScanner::CveReportScanner.new(raw)
  scanner.generate
  raw['logs'] = scanner.logs
  raw['status'] = scanner.status
  raw['metrics'] = scanner.metrics
  raw['report_status_calculator_options'] = { :metrics => %w[critical high medium low total] }
end

.cve_scanner_report?(raw) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'app/services/foreman_cve_scanner/cve_report_scanner.rb', line 20

def self.cve_scanner_report?(raw)
  raw['reporter'] == 'cve_scan'
end

.identify_origin(raw) ⇒ Object



16
17
18
# File 'app/services/foreman_cve_scanner/cve_report_scanner.rb', line 16

def self.identify_origin(raw)
  'CveScanner' if cve_scanner_report?(raw)
end

Instance Method Details

#generateObject



29
30
31
32
33
34
35
36
# File 'app/services/foreman_cve_scanner/cve_report_scanner.rb', line 29

def generate
  @status = {}
  @logs = []
  @cve_report_data.each do |id, cve|
    @logs << generate_log_from_unified(id, cve)
  end
  @logs
end

#logsObject



38
39
40
# File 'app/services/foreman_cve_scanner/cve_report_scanner.rb', line 38

def logs
  @logs
end

#metricsObject



46
47
48
49
50
# File 'app/services/foreman_cve_scanner/cve_report_scanner.rb', line 46

def metrics
  res = @status
  res['total'] = @status.values.sum
  return res
end

#statusObject



42
43
44
# File 'app/services/foreman_cve_scanner/cve_report_scanner.rb', line 42

def status
  @status
end