Class: Zwischen::Finding::Finding

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

Constant Summary collapse

SEVERITY_LEVELS =
%w[critical high medium low info].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, scanner:, severity:, file:, line: nil, message:, rule_id: nil, code_snippet: nil, raw_data: {}) ⇒ Finding

Returns a new instance of Finding.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/zwischen/finding/finding.rb', line 10

def initialize(
  type:,
  scanner:,
  severity:,
  file:,
  line: nil,
  message:,
  rule_id: nil,
  code_snippet: nil,
  raw_data: {}
)
  @type = type.to_s
  @scanner = scanner.to_s
  @severity = normalize_severity(severity)
  @file = file.to_s
  @line = line
  @message = message.to_s
  @rule_id = rule_id.to_s if rule_id
  @code_snippet = code_snippet
  @raw_data = raw_data
end

Instance Attribute Details

#code_snippetObject (readonly)

Returns the value of attribute code_snippet.



6
7
8
# File 'lib/zwischen/finding/finding.rb', line 6

def code_snippet
  @code_snippet
end

#fileObject (readonly)

Returns the value of attribute file.



6
7
8
# File 'lib/zwischen/finding/finding.rb', line 6

def file
  @file
end

#lineObject (readonly)

Returns the value of attribute line.



6
7
8
# File 'lib/zwischen/finding/finding.rb', line 6

def line
  @line
end

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/zwischen/finding/finding.rb', line 6

def message
  @message
end

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



6
7
8
# File 'lib/zwischen/finding/finding.rb', line 6

def raw_data
  @raw_data
end

#rule_idObject (readonly)

Returns the value of attribute rule_id.



6
7
8
# File 'lib/zwischen/finding/finding.rb', line 6

def rule_id
  @rule_id
end

#scannerObject (readonly)

Returns the value of attribute scanner.



6
7
8
# File 'lib/zwischen/finding/finding.rb', line 6

def scanner
  @scanner
end

#severityObject (readonly)

Returns the value of attribute severity.



6
7
8
# File 'lib/zwischen/finding/finding.rb', line 6

def severity
  @severity
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/zwischen/finding/finding.rb', line 6

def type
  @type
end

Instance Method Details

#critical?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/zwischen/finding/finding.rb', line 51

def critical?
  @severity == "critical"
end

#high?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/zwischen/finding/finding.rb', line 55

def high?
  @severity == "high"
end

#should_fail?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/zwischen/finding/finding.rb', line 59

def should_fail?
  critical? || high?
end

#to_hObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/zwischen/finding/finding.rb', line 32

def to_h
  {
    type: @type,
    scanner: @scanner,
    severity: @severity,
    file: @file,
    line: @line,
    message: @message,
    rule_id: @rule_id,
    code_snippet: @code_snippet,
    raw_data: @raw_data
  }
end

#to_json(*args) ⇒ Object



46
47
48
49
# File 'lib/zwischen/finding/finding.rb', line 46

def to_json(*args)
  require "json" unless defined?(JSON)
  to_h.to_json(*args)
end