Class: Contrast::Agent::Reporting::DiscoveredRoute
- Inherits:
-
ObservedRoute
- Object
- ReportableHash
- ReportingEvent
- ApplicationReportingEvent
- ObservedRoute
- Contrast::Agent::Reporting::DiscoveredRoute
- Defined in:
- lib/contrast/agent/reporting/reporting_events/discovered_route.rb
Overview
This is the new Discovered Route 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
-
#signature ⇒ String
The controller, method, and pattern of this route.
-
#url ⇒ String
The url (or url pattern) used to access this route.
-
#verb ⇒ String?
The HTTP verb used to access this route or nil for any verb.
Attributes inherited from ObservedRoute
Attributes inherited from ReportingEvent
#event_endpoint, #event_method
Class Method Summary collapse
-
.from_action_dispatch_journey(journey_obj, url = nil) ⇒ Contrast::Agent::Reporting::DiscoveredRoute
Convert ActionDispatch::Journey::Route to Contrast::Agent::Reporting::DiscoveredRoute.
-
.from_grape_controller(controller, method, pattern, url = nil) ⇒ Contrast::Agent::Reporting::DiscoveredRoute
Convert Grape route data to discovered route.
-
.from_sinatra_route(controller, method, pattern, url = nil) ⇒ Contrast::Agent::Reporting::DiscoveredRoute
Convert Sinatra route data to discovered route.
- .source_or_string(obj) ⇒ String
Instance Method Summary collapse
-
#initialize ⇒ DiscoveredRoute
constructor
A new instance of DiscoveredRoute.
- #to_controlled_hash ⇒ Object
- #validate ⇒ Object
Methods inherited from ObservedRoute
Methods inherited from ReportingEvent
Methods inherited from ReportableHash
Methods included from Components::Logger::InstanceMethods
Constructor Details
#initialize ⇒ DiscoveredRoute
Returns a new instance of DiscoveredRoute.
98 99 100 101 102 |
# File 'lib/contrast/agent/reporting/reporting_events/discovered_route.rb', line 98 def initialize @event_type = :discovered_route @verb = Contrast::Utils::ObjectShare::EMPTY_STRING super() end |
Instance Attribute Details
#signature ⇒ String
Returns the controller, method, and pattern of this route.
92 93 94 |
# File 'lib/contrast/agent/reporting/reporting_events/discovered_route.rb', line 92 def signature @signature end |
#url ⇒ String
Returns the url (or url pattern) used to access this route.
94 95 96 |
# File 'lib/contrast/agent/reporting/reporting_events/discovered_route.rb', line 94 def url @url end |
#verb ⇒ String?
Returns the HTTP verb used to access this route or nil for any verb.
96 97 98 |
# File 'lib/contrast/agent/reporting/reporting_events/discovered_route.rb', line 96 def verb @verb end |
Class Method Details
.from_action_dispatch_journey(journey_obj, url = nil) ⇒ Contrast::Agent::Reporting::DiscoveredRoute
Convert ActionDispatch::Journey::Route to Contrast::Agent::Reporting::DiscoveredRoute
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/contrast/agent/reporting/reporting_events/discovered_route.rb', line 37 def from_action_dispatch_journey journey_obj, url = nil msg = new msg.signature = "#{ journey_obj.defaults[:controller] }##{ journey_obj.defaults[:action] }" verb = source_or_string(journey_obj.verb) msg.verb = Contrast::Utils::StringUtils.force_utf8(verb) url ||= source_or_string(journey_obj.path.spec) msg.url = Contrast::Utils::StringUtils.force_utf8(url) msg end |
.from_grape_controller(controller, method, pattern, url = nil) ⇒ Contrast::Agent::Reporting::DiscoveredRoute
Convert Grape route data to discovered route.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/contrast/agent/reporting/reporting_events/discovered_route.rb', line 56 def from_grape_controller controller, method, pattern, url = nil if pattern.cs__is_a?(Grape::Router::Route) safe_pattern = pattern.pattern&.path&.to_s safe_url = source_or_string(url || safe_pattern) else safe_pattern = source_or_string(pattern) safe_url = source_or_string(url || pattern) end msg = new msg.signature = "#{ controller }##{ method } #{ safe_pattern }" msg.verb = Contrast::Utils::StringUtils.force_utf8(method) msg.url = Contrast::Utils::StringUtils.force_utf8(safe_url) msg end |
.from_sinatra_route(controller, method, pattern, url = nil) ⇒ Contrast::Agent::Reporting::DiscoveredRoute
Convert Sinatra route data to discovered route.
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/contrast/agent/reporting/reporting_events/discovered_route.rb', line 79 def from_sinatra_route controller, method, pattern, url = nil safe_pattern = source_or_string(pattern) safe_url = source_or_string(url || pattern) msg = new msg.signature = "#{ controller }##{ method } #{ safe_pattern }" # rubocop:disable [Security/Object/Method] msg.verb = Contrast::Utils::StringUtils.force_utf8(method) msg.url = Contrast::Utils::StringUtils.force_utf8(safe_url) msg end |
.source_or_string(obj) ⇒ String
22 23 24 25 26 27 28 29 30 |
# File 'lib/contrast/agent/reporting/reporting_events/discovered_route.rb', line 22 def source_or_string obj if obj.cs__is_a?(Regexp) obj.source elsif obj.cs__respond_to?(:safe_string) obj.safe_string else obj.to_s end end |
Instance Method Details
#to_controlled_hash ⇒ Object
104 105 106 107 |
# File 'lib/contrast/agent/reporting/reporting_events/discovered_route.rb', line 104 def to_controlled_hash validate { session_id: ::Contrast::ASSESS.session_id, signature: @signature, verb: @verb, url: @url }.compact end |
#validate ⇒ Object
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/contrast/agent/reporting/reporting_events/discovered_route.rb', line 109 def validate 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 |