Class: Contrast::Agent::Reporting::Preflight

Inherits:
ApplicationReportingEvent show all
Defined in:
lib/contrast/agent/reporting/reporting_events/preflight.rb

Overview

This is the new Preflight class which will include all the needed information for the new reporting system to report a Preflight message to TeamServer. This message represents the identifying information of a collection of Findings/Traces, which TeamServer will use to determine if it requires the full information of any of the Findings/Traces to be reported.

Instance Attribute Summary collapse

Attributes inherited from ReportingEvent

#event_endpoint, #event_method

Instance Method Summary collapse

Methods inherited from ReportingEvent

#attach_headers

Methods inherited from ReportableHash

#event_json, #valid?

Methods included from Components::Logger::InstanceMethods

#cef_logger, #logger

Constructor Details

#initializePreflight

Returns a new instance of Preflight.



20
21
22
23
24
25
# File 'lib/contrast/agent/reporting/reporting_events/preflight.rb', line 20

def initialize
  @event_method = :PUT
  @event_endpoint = "#{ Contrast::API.api_url }/api/ng/preflight/"
  @messages = []
  super()
end

Instance Attribute Details

#messagesObject (readonly)

For our purposes, we’ll only ever send one message per request; however, we must use an array to conform to the specification.



18
19
20
# File 'lib/contrast/agent/reporting/reporting_events/preflight.rb', line 18

def messages
  @messages
end

Instance Method Details

#file_nameObject



27
28
29
# File 'lib/contrast/agent/reporting/reporting_events/preflight.rb', line 27

def file_name
  'preflight'
end

#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)


36
37
38
39
# File 'lib/contrast/agent/reporting/reporting_events/preflight.rb', line 36

def to_controlled_hash
  validate
  { messages: @messages.map(&:to_controlled_hash) }
end

#validateObject

Raises:

  • (ArgumentError)


42
43
44
45
46
47
48
# File 'lib/contrast/agent/reporting/reporting_events/preflight.rb', line 42

def validate
  if Contrast::Utils::DuckUtils.empty_duck?(messages)
    raise(ArgumentError, "#{ cs__class } did not have any messages. Unable to continue.")
  end

  nil
end