Class: Contrast::Agent::Reporting::ObservedRoute
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.
Instance Attribute Summary collapse
#event_endpoint, #event_method
Instance Method Summary
collapse
#attach_headers
#event_json, #valid?
#cef_logger, #logger
Constructor Details
Returns a new instance of ObservedRoute.
Instance Attribute Details
#signature ⇒ Object
21
22
23
|
# File 'lib/contrast/agent/reporting/reporting_events/observed_route.rb', line 21
def signature
@signature
end
|
28
29
30
|
# File 'lib/contrast/agent/reporting/reporting_events/observed_route.rb', line 28
def sources
@sources
end
|
23
24
25
|
# File 'lib/contrast/agent/reporting/reporting_events/observed_route.rb', line 23
def url
@url
end
|
25
26
27
|
# File 'lib/contrast/agent/reporting/reporting_events/observed_route.rb', line 25
def verb
@verb
end
|
Instance Method Details
#file_name ⇒ Object
37
38
39
|
# File 'lib/contrast/agent/reporting/reporting_events/observed_route.rb', line 37
def file_name
'routes-observed'
end
|
Generates a hash id for the observed route, based on the sources, signature, verb, and url.
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 } hashable_data[:sources] = hashable_data[:sources].sort_by { |s| s[:name] }
Digest::SHA2.new(256).hexdigest(hashable_data.to_s)
end
|
#to_controlled_hash ⇒ Hash
Convert the instance variables on the class, and other information, into the identifiers required for TeamServer to process the JSON form of this message.
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
|
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
|