Class: Contrast::Agent::Reporting::ObservedRoute

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

Overview

This is the new Route Observation class which will include all the needed information for the new reporting system to relay this information in the Route Observation messages. These observations 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. This also includes the literal URL and HTTP Verb used to invoke them, as they must have been called at this point to be recorded.

Direct Known Subclasses

DiscoveredRoute

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

#initializeObservedRoute

Returns a new instance of ObservedRoute.



30
31
32
33
34
35
# File 'lib/contrast/agent/reporting/reporting_events/observed_route.rb', line 30

def initialize
  @event_endpoint = Contrast::Agent::Reporting::Endpoints.observed_route
  @sources = []
  @verb = Contrast::Utils::ObjectShare::EMPTY_STRING
  super()
end

Instance Attribute Details

#signatureObject

Parameters:

  • the (String)

    method signature used to uniquely identify the coverage report.



21
22
23
# File 'lib/contrast/agent/reporting/reporting_events/observed_route.rb', line 21

def signature
  @signature
end

#sourcesObject (readonly)

Parameters:



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

def sources
  @sources
end

#urlObject

Parameters:

  • the (String)

    normalized URL used to access the method in the route.



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

def url
  @url
end

#verbObject

Parameters:

  • the (String)

    HTTP Verb used to access the method in the route.



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

def verb
  @verb
end

Instance Method Details

#file_nameObject



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

def file_name
  'routes-observed'
end

#hash_idString

Generates a hash id for the observed route, based on the sources, signature, verb, and url.

Returns:



61
62
63
64
65
66
# File 'lib/contrast/agent/reporting/reporting_events/observed_route.rb', line 61

def hash_id
  hashable_data = to_controlled_hash.reject { |key, _value| key == :session_id } # rubocop:disable Style/HashExcept
  hashable_data[:sources] = hashable_data[:sources].sort_by { |s| s[:name] }

  Digest::SHA2.new(256).hexdigest(hashable_data.to_s)
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)


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

def to_controlled_hash
  validate
  {
      session_id: ::Contrast::ASSESS.session_id,
      sources: @sources.map(&:to_controlled_observation_hash),
      signature: @signature,
      verb: @verb,
      url: @url
  }.compact
end

#validateObject

Raises:

  • (ArgumentError)


69
70
71
72
73
74
75
76
77
78
79
# File 'lib/contrast/agent/reporting/reporting_events/observed_route.rb', line 69

def validate
  raise(ArgumentError, "#{ self } did not have a proper sources. Unable to continue.") if @sources.nil?
  if Contrast::Utils::DuckUtils.empty_duck?(signature)
    raise(ArgumentError, "#{ self } did not have a proper signature. Unable to continue.")
  end
  if Contrast::Utils::DuckUtils.empty_duck?(url)
    raise(ArgumentError, "#{ self } did not have a proper url. Unable to continue.")
  end

  nil
end