Class: Gitlab::Ci::Reports::Security::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/reports/security/report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, pipeline, created_at) ⇒ Report

Returns a new instance of Report.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gitlab/ci/reports/security/report.rb', line 15

def initialize(type, pipeline, created_at)
  @type = type
  @pipeline = pipeline
  @created_at = created_at
  @findings = []
  @scanners = {}
  @identifiers = {}
  @scanned_resources = []
  @errors = []
  @warnings = []
end

Instance Attribute Details

#analyzerObject

Returns the value of attribute analyzer.



9
10
11
# File 'lib/gitlab/ci/reports/security/report.rb', line 9

def analyzer
  @analyzer
end

#created_atObject (readonly)

Returns the value of attribute created_at.



8
9
10
# File 'lib/gitlab/ci/reports/security/report.rb', line 8

def created_at
  @created_at
end

#errorsObject

Returns the value of attribute errors.



9
10
11
# File 'lib/gitlab/ci/reports/security/report.rb', line 9

def errors
  @errors
end

#findingsObject (readonly)

Returns the value of attribute findings.



8
9
10
# File 'lib/gitlab/ci/reports/security/report.rb', line 8

def findings
  @findings
end

#identifiersObject (readonly)

Returns the value of attribute identifiers.



8
9
10
# File 'lib/gitlab/ci/reports/security/report.rb', line 8

def identifiers
  @identifiers
end

#pipelineObject

Returns the value of attribute pipeline.



9
10
11
# File 'lib/gitlab/ci/reports/security/report.rb', line 9

def pipeline
  @pipeline
end

#scanObject

Returns the value of attribute scan.



9
10
11
# File 'lib/gitlab/ci/reports/security/report.rb', line 9

def scan
  @scan
end

#scanned_resourcesObject

Returns the value of attribute scanned_resources.



9
10
11
# File 'lib/gitlab/ci/reports/security/report.rb', line 9

def scanned_resources
  @scanned_resources
end

#scannersObject (readonly)

Returns the value of attribute scanners.



8
9
10
# File 'lib/gitlab/ci/reports/security/report.rb', line 8

def scanners
  @scanners
end

#schema_validation_statusObject

Returns the value of attribute schema_validation_status.



9
10
11
# File 'lib/gitlab/ci/reports/security/report.rb', line 9

def schema_validation_status
  @schema_validation_status
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/gitlab/ci/reports/security/report.rb', line 8

def type
  @type
end

#versionObject

Returns the value of attribute version.



9
10
11
# File 'lib/gitlab/ci/reports/security/report.rb', line 9

def version
  @version
end

#warningsObject

Returns the value of attribute warnings.



9
10
11
# File 'lib/gitlab/ci/reports/security/report.rb', line 9

def warnings
  @warnings
end

Instance Method Details

#add_error(type, message = 'An unexpected error happened!') ⇒ Object



31
32
33
# File 'lib/gitlab/ci/reports/security/report.rb', line 31

def add_error(type, message = 'An unexpected error happened!')
  errors << { type: type, message: message }
end

#add_finding(finding) ⇒ Object



55
56
57
# File 'lib/gitlab/ci/reports/security/report.rb', line 55

def add_finding(finding)
  findings << finding
end

#add_identifier(identifier) ⇒ Object



51
52
53
# File 'lib/gitlab/ci/reports/security/report.rb', line 51

def add_identifier(identifier)
  identifiers[identifier.key] ||= identifier
end

#add_scanner(scanner) ⇒ Object



47
48
49
# File 'lib/gitlab/ci/reports/security/report.rb', line 47

def add_scanner(scanner)
  scanners[scanner.key] ||= scanner
end

#add_warning(type, message) ⇒ Object



35
36
37
# File 'lib/gitlab/ci/reports/security/report.rb', line 35

def add_warning(type, message)
  warnings << { type: type, message: message }
end

#clone_as_blankObject



59
60
61
# File 'lib/gitlab/ci/reports/security/report.rb', line 59

def clone_as_blank
  Report.new(type, pipeline, created_at)
end

#commit_shaObject



27
28
29
# File 'lib/gitlab/ci/reports/security/report.rb', line 27

def commit_sha
  pipeline.sha
end

#errored?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/gitlab/ci/reports/security/report.rb', line 39

def errored?
  errors.present?
end

#has_signatures?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/gitlab/ci/reports/security/report.rb', line 88

def has_signatures?
  findings.any?(&:has_signatures?)
end

#merge!(other) ⇒ Object



69
70
71
# File 'lib/gitlab/ci/reports/security/report.rb', line 69

def merge!(other)
  replace_with!(::Security::MergeReportsService.new(self, other).execute)
end

#primary_identifiersObject



73
74
75
# File 'lib/gitlab/ci/reports/security/report.rb', line 73

def primary_identifiers
  scanners.values.flat_map(&:primary_identifiers).compact
end

#primary_scannerObject



77
78
79
# File 'lib/gitlab/ci/reports/security/report.rb', line 77

def primary_scanner
  scanners.first&.second
end

#primary_scanner_order_to(other) ⇒ Object



81
82
83
84
85
86
# File 'lib/gitlab/ci/reports/security/report.rb', line 81

def primary_scanner_order_to(other)
  return 1 unless primary_scanner
  return -1 unless other.primary_scanner

  primary_scanner <=> other.primary_scanner
end

#replace_with!(other) ⇒ Object



63
64
65
66
67
# File 'lib/gitlab/ci/reports/security/report.rb', line 63

def replace_with!(other)
  instance_variables.each do |ivar|
    instance_variable_set(ivar, other.public_send(ivar.to_s[1..])) # rubocop:disable GitlabSecurity/PublicSend
  end
end

#warnings?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/gitlab/ci/reports/security/report.rb', line 43

def warnings?
  warnings.present?
end