Class: Contrast::Agent::Reporting::ResponseHandler
- Defined in:
- lib/contrast/agent/reporting/reporting_utilities/response_handler.rb
Overview
This class will facilitate the Response capture and analysis functionality.
Constant Summary collapse
- TIMEOUT =
15 min
900.cs__freeze
Constants included from ResponseHandlerUtils
Contrast::Agent::Reporting::ResponseHandlerUtils::ANALYZE_WHEN, Contrast::Agent::Reporting::ResponseHandlerUtils::APP_NON_EXISTENT_MSG, Contrast::Agent::Reporting::ResponseHandlerUtils::ERROR_CODES, Contrast::Agent::Reporting::ResponseHandlerUtils::FORBIDDEN_MSG, Contrast::Agent::Reporting::ResponseHandlerUtils::FORBIDDEN_NO_ACTION_MSG, Contrast::Agent::Reporting::ResponseHandlerUtils::RETRY_AFTER_MSG, Contrast::Agent::Reporting::ResponseHandlerUtils::SUSPEND_MSG, Contrast::Agent::Reporting::ResponseHandlerUtils::UNPROCESSABLE_ENTITY_MSG, Contrast::Agent::Reporting::ResponseHandlerUtils::UNSUCCESSFULLY_RECEIVED_MSG
Instance Method Summary collapse
- #mode ⇒ Object
-
#process(response, event) ⇒ Object
Process the response from TS.
-
#put_to_sleep ⇒ Object
Puts the reporting service to sleep.
-
#sleep? ⇒ Boolean
If sleep is true puts reporting service to sleep.
-
#suspend_reporting(message, timeout, error_message, event: nil, log_error: true, startup: false) ⇒ Object
Suspend the reporter and try again in time.
-
#timeout ⇒ Object
For how long the agent should wait until retry to send message.
-
#wake_up ⇒ Object
Wakes the reporting service.
Methods included from ResponseHandlerUtils
#last_application_modified, #last_response_code, #last_server_modified, #stop_reporting
Methods included from Components::Logger::InstanceMethods
Instance Method Details
#mode ⇒ Object
62 63 64 |
# File 'lib/contrast/agent/reporting/reporting_utilities/response_handler.rb', line 62 def mode @_mode ||= Contrast::Agent::Reporting::ResponseHandlerMode.new end |
#process(response, event) ⇒ Object
Process the response from TS
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/contrast/agent/reporting/reporting_utilities/response_handler.rb', line 26 def process response, event logger.debug('[Reporter] Received a response') return unless analyze_response?(response) # Handle the response body and obtain server_features or app_settings report_response = convert_response(response, event) return unless report_response # Update Server Features and Application Settings to provide current agent settings update_agent_settings(report_response) # Process any reactions, including message logging and shutting down update_reaction(report_response) update_ruleset(report_response) logger.trace('Agent settings updated in response to TeamServer', protect_on: ::Contrast::PROTECT.enabled?, assess_on: ::Contrast::ASSESS.enabled?) response rescue StandardError => e logger.error('[Reporter] Unable to process response from TeamServer', e) nil end |
#put_to_sleep ⇒ Object
Puts the reporting service to sleep
67 68 69 |
# File 'lib/contrast/agent/reporting/reporting_utilities/response_handler.rb', line 67 def put_to_sleep @_sleep = true end |
#sleep? ⇒ Boolean
If sleep is true puts reporting service to sleep.
48 49 50 51 |
# File 'lib/contrast/agent/reporting/reporting_utilities/response_handler.rb', line 48 def sleep? @_sleep = wake_up if @_sleep.nil? @_sleep end |
#suspend_reporting(message, timeout, error_message, event: nil, log_error: true, startup: false) ⇒ Object
Suspend the reporter and try again in time. If not set the timeout is set to 15 min As default:
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/contrast/agent/reporting/reporting_utilities/response_handler.rb', line 85 def suspend_reporting , timeout, , event: nil, log_error: true, startup: false @_timeout = timeout || Contrast::Agent::Reporting::ResponseHandler::TIMEOUT if log_error log_error_msg(, timeout: @_timeout, error_message: || 'none', event_id: event.nil? ? 'none' : event&.__id__, event_type: event.nil? ? 'none' : event&.cs__class&.cs__name) end if startup logger.info(, connection_error: , client: Contrast::Agent::Reporting::ReporterClient::SERVICE_NAME, event_id: event&.__id__, timeout: timeout, event_type: event&.cs__class&.cs__name) end put_to_sleep end |
#timeout ⇒ Object
For how long the agent should wait until retry to send message
to be suspended.
58 59 60 |
# File 'lib/contrast/agent/reporting/reporting_utilities/response_handler.rb', line 58 def timeout @_timeout ||= TIMEOUT end |
#wake_up ⇒ Object
Wakes the reporting service
72 73 74 |
# File 'lib/contrast/agent/reporting/reporting_utilities/response_handler.rb', line 72 def wake_up @_sleep = false end |