debian-mirror-gitlab/lib/gitlab/ci/reports/security/report.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

96 lines
2.4 KiB
Ruby
Raw Normal View History

2021-10-27 15:23:28 +05:30
# frozen_string_literal: true
module Gitlab
module Ci
module Reports
module Security
class Report
2023-05-27 22:25:52 +05:30
attr_reader :created_at, :type, :findings, :scanners, :identifiers
attr_accessor :scan, :pipeline, :scanned_resources, :errors,
:analyzer, :version, :schema_validation_status, :warnings
2021-10-27 15:23:28 +05:30
delegate :project_id, to: :pipeline
2022-06-21 17:19:12 +05:30
delegate :project, to: :pipeline
2021-10-27 15:23:28 +05:30
def initialize(type, pipeline, created_at)
@type = type
@pipeline = pipeline
@created_at = created_at
@findings = []
@scanners = {}
@identifiers = {}
@scanned_resources = []
@errors = []
2022-05-07 20:08:51 +05:30
@warnings = []
2021-10-27 15:23:28 +05:30
end
def commit_sha
pipeline.sha
end
def add_error(type, message = 'An unexpected error happened!')
errors << { type: type, message: message }
end
2022-05-07 20:08:51 +05:30
def add_warning(type, message)
warnings << { type: type, message: message }
end
2021-10-27 15:23:28 +05:30
def errored?
errors.present?
end
2022-06-21 17:19:12 +05:30
def warnings?
warnings.present?
end
2021-10-27 15:23:28 +05:30
def add_scanner(scanner)
scanners[scanner.key] ||= scanner
end
def add_identifier(identifier)
identifiers[identifier.key] ||= identifier
end
def add_finding(finding)
findings << finding
end
def clone_as_blank
Report.new(type, pipeline, created_at)
end
def replace_with!(other)
instance_variables.each do |ivar|
2022-01-26 12:08:38 +05:30
instance_variable_set(ivar, other.public_send(ivar.to_s[1..])) # rubocop:disable GitlabSecurity/PublicSend
2021-10-27 15:23:28 +05:30
end
end
def merge!(other)
replace_with!(::Security::MergeReportsService.new(self, other).execute)
end
2022-11-25 23:54:43 +05:30
def primary_identifiers
scanners.values.flat_map(&:primary_identifiers).compact
end
2021-10-27 15:23:28 +05:30
def primary_scanner
scanners.first&.second
end
def primary_scanner_order_to(other)
return 1 unless primary_scanner
return -1 unless other.primary_scanner
primary_scanner <=> other.primary_scanner
end
2021-12-11 22:18:48 +05:30
def has_signatures?
findings.any?(&:has_signatures?)
end
2021-10-27 15:23:28 +05:30
end
end
end
end
end