Class: SecureKeys::Validation::Finding

Inherits:
Object
  • Object
show all
Defined in:
lib/validation/models/finding.rb

Overview

Represents a single secret detected during a file or git diff scan

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file:, line:, column:, type:, description:, severity:, matched_text:, full_line:, is_addition: false) ⇒ Finding

Initialize a new finding

Parameters:

  • file (String)

    The file path where the secret was found

  • line (Integer)

    The line number where the secret was found

  • column (Integer)

    The column offset of the match within the line

  • type (Symbol)

    The pattern type that matched (e.g. :github_token, :aws_access_key)

  • description (String)

    A human-readable description of the secret type

  • severity (Symbol)

    The severity level (:low, :medium, :high, :critical)

  • matched_text (String)

    The masked matched text, safe for display

  • full_line (String)

    The full trimmed line of code containing the secret

  • is_addition (Boolean) (defaults to: false)

    Whether this line is an addition in a git diff (default: false)



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/validation/models/finding.rb', line 20

def initialize(file:, line:, column:, type:, description:, severity:,
               matched_text:, full_line:, is_addition: false)
  @file = file
  @line = line
  @column = column
  @type = type
  @description = description
  @severity = severity
  @matched_text = matched_text
  @full_line = full_line
  @is_addition = is_addition
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



7
8
9
# File 'lib/validation/models/finding.rb', line 7

def column
  @column
end

#descriptionObject (readonly)

Returns the value of attribute description.



7
8
9
# File 'lib/validation/models/finding.rb', line 7

def description
  @description
end

#fileObject (readonly)

Returns the value of attribute file.



7
8
9
# File 'lib/validation/models/finding.rb', line 7

def file
  @file
end

#full_lineObject (readonly)

Returns the value of attribute full_line.



7
8
9
# File 'lib/validation/models/finding.rb', line 7

def full_line
  @full_line
end

#is_additionObject (readonly)

Returns the value of attribute is_addition.



7
8
9
# File 'lib/validation/models/finding.rb', line 7

def is_addition
  @is_addition
end

#lineObject (readonly)

Returns the value of attribute line.



7
8
9
# File 'lib/validation/models/finding.rb', line 7

def line
  @line
end

#matched_textObject (readonly)

Returns the value of attribute matched_text.



7
8
9
# File 'lib/validation/models/finding.rb', line 7

def matched_text
  @matched_text
end

#severityObject (readonly)

Returns the value of attribute severity.



7
8
9
# File 'lib/validation/models/finding.rb', line 7

def severity
  @severity
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/validation/models/finding.rb', line 7

def type
  @type
end

Instance Method Details

#addition?Boolean

Check if this finding came from a git diff addition

Returns:

  • (Boolean)

    true if the line is a git diff addition



35
36
37
# File 'lib/validation/models/finding.rb', line 35

def addition?
  is_addition
end

#to_hHash

Returns a hash representation of the finding

Returns:

  • (Hash)

    The hash representation



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/validation/models/finding.rb', line 47

def to_h
  {
    file:,
    line:,
    column:,
    type:,
    description:,
    severity:,
    matched_text:,
    full_line:,
    is_addition:,
  }
end

#to_sString

Returns a one-line string representation of the finding

Returns:

  • (String)

    The formatted finding string



41
42
43
# File 'lib/validation/models/finding.rb', line 41

def to_s
  "#{severity_icon} #{file}:#{line}:#{column} [#{type}] #{description}#{matched_text}"
end