Class: Contrast::Agent::Reporting::FindingEventSource

Inherits:
ReportableHash show all
Defined in:
lib/contrast/agent/reporting/reporting_events/finding_event_source.rb

Overview

This is the new FindingEventSource class which will include all the needed information for the new reporting system to relay this information in the Finding/Trace messages. These FindingEventSource are used by TeamServer to construct the vulnerability information for the assess feature. They indicate the type of data that the event represents.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ReportableHash

#event_json, #valid?

Methods included from Components::Logger::InstanceMethods

#cef_logger, #logger

Constructor Details

#initialize(type, name) ⇒ FindingEventSource

Returns a new instance of FindingEventSource.

Parameters:



23
24
25
26
27
# File 'lib/contrast/agent/reporting/reporting_events/finding_event_source.rb', line 23

def initialize type, name
  @source_type = type
  @source_name = name
  super()
end

Instance Attribute Details

#source_nameString (readonly)

Returns the name of the source.

Returns:

  • (String)

    the name of the source



17
18
19
# File 'lib/contrast/agent/reporting/reporting_events/finding_event_source.rb', line 17

def source_name
  @source_name
end

#source_typeString (readonly)

Returns the type of the source.

Returns:

  • (String)

    the type of the source



19
20
21
# File 'lib/contrast/agent/reporting/reporting_events/finding_event_source.rb', line 19

def source_type
  @source_type
end

Instance Method Details

#to_controlled_hashHash

Convert the instance variables on the class, and other information, into the identifiers required for TeamServer to process the JSON form of this message.

Returns:

Raises:

  • (ArgumentError)


34
35
36
37
38
39
40
# File 'lib/contrast/agent/reporting/reporting_events/finding_event_source.rb', line 34

def to_controlled_hash
  validate
  {
      sourceName: source_name,
      sourceType: source_type
  }
end

#to_controlled_observation_hashHash

Convert this EventSource into the format expected for route observation

Returns:

Raises:

  • (ArgumentError)


46
47
48
49
50
51
52
# File 'lib/contrast/agent/reporting/reporting_events/finding_event_source.rb', line 46

def to_controlled_observation_hash
  validate
  {
      name: source_name,
      type: source_type
  }
end

#validateObject

Raises:

  • (ArgumentError)


55
56
57
58
59
# File 'lib/contrast/agent/reporting/reporting_events/finding_event_source.rb', line 55

def validate
  return unless Contrast::Utils::DuckUtils.empty_duck?(source_type)

  raise(ArgumentError, "#{ self } did not have a proper type. Unable to continue.")
end