Class: Contrast::Agent::Reporting::RouteDiscovery

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

Overview

This is the new Route Discovery class which will include all the needed information for the new reporting system to relay this information in the Application Update messages. These discoveries are used by TeamServer to construct the route coverage information for the assess feature. They represent those methods which map to externally accessible endpoints within the application, as registered to the application framework. They may or may not have been invoked at the time of reporting.

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(signature, observation) ⇒ RouteDiscovery

Returns a new instance of RouteDiscovery.

Parameters:



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

def initialize signature, observation
  @signature = signature
  @observations = []
  observations << observation
  super()
end

Instance Attribute Details

#observationsArray<Contrast::Agent::Reporting::RouteDiscoveryObservation> (readonly)

Returns the routes and verbs seen that match to this Route.

Returns:



20
21
22
# File 'lib/contrast/agent/reporting/reporting_events/route_discovery.rb', line 20

def observations
  @observations
end

#signatureString

Returns the unique identifier for this route; typically the method signature. Required for reporting.

Returns:

  • (String)

    the unique identifier for this route; typically the method signature. Required for reporting.



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

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


39
40
41
42
43
44
45
46
# File 'lib/contrast/agent/reporting/reporting_events/route_discovery.rb', line 39

def to_controlled_hash
  validate
  {
      count: 0, # we have this to make TS happy
      observations: @observations.map(&:to_controlled_hash),
      signature: @signature
  }
end

#validateObject

Ensure the required fields are present.

Raises:

  • (ArgumentError)


51
52
53
54
55
# File 'lib/contrast/agent/reporting/reporting_events/route_discovery.rb', line 51

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

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