Class: Gitlab::Ci::Reports::Security::Identifier

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(external_id:, external_type:, name:, url: nil) ⇒ Identifier

Returns a new instance of Identifier.



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

def initialize(external_id:, external_type:, name:, url: nil)
  @external_id = external_id
  @external_type = external_type
  @name = name
  @url = url

  @fingerprint = generate_fingerprint
end

Instance Attribute Details

#external_idObject (readonly)

Returns the value of attribute external_id.



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

def external_id
  @external_id
end

#external_typeObject (readonly)

Returns the value of attribute external_type.



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

def external_type
  @external_type
end

#fingerprintObject (readonly)

Returns the value of attribute fingerprint.



10
11
12
# File 'lib/gitlab/ci/reports/security/identifier.rb', line 10

def fingerprint
  @fingerprint
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/gitlab/ci/reports/security/identifier.rb', line 11

def name
  @name
end

#urlObject (readonly)

Returns the value of attribute url.



12
13
14
# File 'lib/gitlab/ci/reports/security/identifier.rb', line 12

def url
  @url
end

Instance Method Details

#==(other) ⇒ Object



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

def ==(other)
  other.external_type == external_type &&
    other.external_id == external_id
end

#cve?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/gitlab/ci/reports/security/identifier.rb', line 48

def cve?
  external_type.to_s.casecmp?('cve')
end

#cwe?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/gitlab/ci/reports/security/identifier.rb', line 52

def cwe?
  external_type.to_s.casecmp?('cwe')
end

#keyObject



23
24
25
# File 'lib/gitlab/ci/reports/security/identifier.rb', line 23

def key
  fingerprint
end

#to_hashObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gitlab/ci/reports/security/identifier.rb', line 27

def to_hash
  %i[
    external_id
    external_type
    fingerprint
    name
    url
  ].index_with do |key|
    public_send(key) # rubocop:disable GitlabSecurity/PublicSend
  end
end

#type_identifier?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/gitlab/ci/reports/security/identifier.rb', line 44

def type_identifier?
  cwe? || wasc?
end

#wasc?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/gitlab/ci/reports/security/identifier.rb', line 56

def wasc?
  external_type.to_s.casecmp?('wasc')
end