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.


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

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 (readonly)

Returns the value of attribute pipeline.


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

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


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

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

#add_finding(finding) ⇒ Object


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

def add_finding(finding)
  findings << finding
end

#add_identifier(identifier) ⇒ Object


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

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

#add_scanner(scanner) ⇒ Object


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

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

#add_warning(type, message) ⇒ Object


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

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

#clone_as_blankObject


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

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

#commit_shaObject


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

def commit_sha
  pipeline.sha
end

#errored?Boolean

Returns:

  • (Boolean)

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

def errored?
  errors.present?
end

#has_signatures?Boolean

Returns:

  • (Boolean)

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

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

#merge!(other) ⇒ Object


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

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

#primary_scannerObject


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

def primary_scanner
  scanners.first&.second
end

#primary_scanner_order_to(other) ⇒ Object


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

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


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

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)

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

def warnings?
  warnings.present?
end