Class: Contrast::Agent::Reporting::PreflightMessage

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

Overview

This is the new PreflightMessage class which will include all the needed information for the new reporting system to report a single message, part of the main Preflight, to TeamServer. This message represents the identifying information of a Finding/Trace, which TeamServer will use to determine if it requires the full information of the Finding/Trace to be reported.

Constant Summary collapse

CODE =

The type of this event, as understood by TeamServer. While TRACE and APPUPDATE are both technically valid, we only use the TRACE type.

:TRACE

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

#initializePreflightMessage

Returns a new instance of PreflightMessage.



28
29
30
31
# File 'lib/contrast/agent/reporting/reporting_events/preflight_message.rb', line 28

def initialize
  @routes = []
  super()
end

Instance Attribute Details

#dataString

Returns the message identifier; rule_id,hash.

Returns:

  • (String)

    the message identifier; rule_id,hash



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

def data
  @data
end

#hash_codeString

Returns CRC checksum of the finding to which this message pertains.

Returns:

  • (String)

    CRC checksum of the finding to which this message pertains



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

def hash_code
  @hash_code
end

#routesArray<Contrast::Agent::Reporting::RouteDiscovery] the route that triggered the finding to which this preflight applies. (readonly)

Returns Array<Contrast::Agent::Reporting::RouteDiscovery] the route that triggered the finding to which this preflight applies.

Returns:

  • (Array<Contrast::Agent::Reporting::RouteDiscovery] the route that triggered the finding to which this preflight applies.)

    Array<Contrast::Agent::Reporting::RouteDiscovery] the route that triggered the finding to which this preflight applies.



22
23
24
# File 'lib/contrast/agent/reporting/reporting_events/preflight_message.rb', line 22

def routes
  @routes
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)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/contrast/agent/reporting/reporting_events/preflight_message.rb', line 38

def to_controlled_hash
  validate
  {
      appLanguage: Contrast::Utils::ObjectShare::RUBY,
      appName: ::Contrast::APP_CONTEXT.name, # rubocop:disable Security/Module/Name
      appPath: ::Contrast::APP_CONTEXT.name, # rubocop:disable Security/Module/Name
      appVersion: ::Contrast::APP_CONTEXT.version,
      code: CODE,
      data: @data || '',
      key: 0,
      session_id: ::Contrast::ASSESS.session_id,
      routes: @routes.map(&:to_controlled_hash)
  }.compact
end

#validateObject

Raises:

  • (ArgumentError)


54
55
56
57
58
59
60
61
62
63
# File 'lib/contrast/agent/reporting/reporting_events/preflight_message.rb', line 54

def validate
  unless Contrast::Utils::StringUtils.present?(data)
    raise(ArgumentError, "#{ cs__class } did not have a proper data. Unable to continue.")
  end
  unless Contrast::APP_CONTEXT.name # rubocop:disable Security/Module/Name
    raise(ArgumentError, "#{ cs__class } did not have a proper Application Name. Unable to continue.")
  end

  nil
end