Class: Contrast::Agent::Reporting::RouteDiscoveryObservation

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

Overview

This is the new Route Discovery Observation class which will include all the needed information for the new reporting system to relay this information in the Application Update messages. These route observations are used by TeamServer to construct the route coverage information for the assess feature. They represent the literal URL and HTTP verb used to invoke a method in the application, as routed by the application framework.

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(url, verb) ⇒ RouteDiscoveryObservation

Returns a new instance of RouteDiscoveryObservation.



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

def initialize url, verb
  @url = url
  @verb = verb if Contrast::Utils::StringUtils.present?(verb)
  super()
end

Instance Attribute Details

#urlString

Returns the URL requested to hit this endpoint. Required for reporting; required attributes.

Returns:

  • (String)

    the URL requested to hit this endpoint. Required for reporting; required attributes



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

def url
  @url
end

#verbString

Returns the HTTP Method requested to his this endpoint. Empty means all, so is allowed for reporting; optional attributes.

Returns:

  • (String)

    the HTTP Method requested to his this endpoint. Empty means all, so is allowed for reporting; optional attributes



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

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


33
34
35
36
# File 'lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb', line 33

def to_controlled_hash
  validate
  { url: url, verb: verb }.compact
end

#validateObject

Ensure the required fields are present.

Raises:

  • (ArgumentError)


41
42
43
44
45
# File 'lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb', line 41

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

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