Class: Gitlab::SecretDetection::Core::Finding

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/secret_detection/core/finding.rb

Overview

Finding is a data object representing a secret finding identified within a payload

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload_id, status, line_number = nil, type = nil, description = nil, raw_value: nil) ⇒ Finding

Returns a new instance of Finding.



12
13
14
15
16
17
18
19
# File 'lib/gitlab/secret_detection/core/finding.rb', line 12

def initialize(payload_id, status, line_number = nil, type = nil, description = nil, raw_value: nil)
  @payload_id = payload_id
  @status = status
  @line_number = line_number
  @type = type
  @description = description
  @raw_value = raw_value
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



10
11
12
# File 'lib/gitlab/secret_detection/core/finding.rb', line 10

def description
  @description
end

#line_numberObject (readonly)

Returns the value of attribute line_number.



10
11
12
# File 'lib/gitlab/secret_detection/core/finding.rb', line 10

def line_number
  @line_number
end

#payload_idObject (readonly)

Returns the value of attribute payload_id.



10
11
12
# File 'lib/gitlab/secret_detection/core/finding.rb', line 10

def payload_id
  @payload_id
end

#raw_valueObject (readonly)

Returns the value of attribute raw_value.



10
11
12
# File 'lib/gitlab/secret_detection/core/finding.rb', line 10

def raw_value
  @raw_value
end

#statusObject (readonly)

Returns the value of attribute status.



10
11
12
# File 'lib/gitlab/secret_detection/core/finding.rb', line 10

def status
  @status
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/gitlab/secret_detection/core/finding.rb', line 10

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



21
22
23
# File 'lib/gitlab/secret_detection/core/finding.rb', line 21

def ==(other)
  self.class == other.class && other.state == state
end

#as_json(_options = nil) ⇒ Object



36
37
38
# File 'lib/gitlab/secret_detection/core/finding.rb', line 36

def as_json(_options = nil)
  to_h
end

#inspectObject

The default inspect would dump raw_value in plain text, reaching p, error contexts, and anything holding a Finding (+Response+ included).



46
47
48
49
50
# File 'lib/gitlab/secret_detection/core/finding.rb', line 46

def inspect
  "#<#{self.class.name} payload_id=#{payload_id.inspect} status=#{status.inspect} " \
    "line_number=#{line_number.inspect} type=#{type.inspect} " \
    "description=#{description.inspect} raw_value=#{raw_value.nil? ? 'nil' : '[FILTERED]'}>"
end

#to_hObject

raw_value is omitted here, and from state and inspect, so a secret cannot leak.



26
27
28
29
30
31
32
33
34
# File 'lib/gitlab/secret_detection/core/finding.rb', line 26

def to_h
  {
    payload_id:,
    status:,
    line_number:,
    type:,
    description:
  }
end

#to_json(*args) ⇒ Object



40
41
42
# File 'lib/gitlab/secret_detection/core/finding.rb', line 40

def to_json(*args)
  to_h.to_json(*args)
end