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::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
63 64 65 |
# File 'lib/contrast/agent/reporting/reporting_utilities/response_handler.rb', line 63 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 46 |
# File 'lib/contrast/agent/reporting/reporting_utilities/response_handler.rb', line 26 def process response, event logger.debug('[Reporter] Received a response') return if event&.cs__is_a?(Contrast::Agent::Reporting::Finding) 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
68 69 70 |
# File 'lib/contrast/agent/reporting/reporting_utilities/response_handler.rb', line 68 def put_to_sleep @_sleep = true end |
#sleep? ⇒ Boolean
If sleep is true puts reporting service to sleep.
49 50 51 52 |
# File 'lib/contrast/agent/reporting/reporting_utilities/response_handler.rb', line 49 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:
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/contrast/agent/reporting/reporting_utilities/response_handler.rb', line 86 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.
59 60 61 |
# File 'lib/contrast/agent/reporting/reporting_utilities/response_handler.rb', line 59 def timeout @_timeout ||= TIMEOUT end |
#wake_up ⇒ Object
Wakes the reporting service
73 74 75 |
# File 'lib/contrast/agent/reporting/reporting_utilities/response_handler.rb', line 73 def wake_up @_sleep = false end |