Class: Contrast::Agent::Reporting::Audit

Inherits:
Object
  • Object
show all
Includes:
Components::Logger::InstanceMethods
Defined in:
lib/contrast/agent/reporting/reporting_utilities/audit.rb

Overview

This class will facilitate the Audit functionality and it will be controlled from the configuration classes

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Components::Logger::InstanceMethods

#cef_logger, #logger

Constructor Details

#initializeAudit

Returns a new instance of Audit.



18
19
20
# File 'lib/contrast/agent/reporting/reporting_utilities/audit.rb', line 18

def initialize
  generate_paths if enabled?
end

Instance Attribute Details

#path_for_requestsObject (readonly)

Returns the value of attribute path_for_requests.



16
17
18
# File 'lib/contrast/agent/reporting/reporting_utilities/audit.rb', line 16

def path_for_requests
  @path_for_requests
end

#path_for_responsesObject (readonly)

Returns the value of attribute path_for_responses.



16
17
18
# File 'lib/contrast/agent/reporting/reporting_utilities/audit.rb', line 16

def path_for_responses
  @path_for_responses
end

Instance Method Details

#audit_event(event, response_data = nil) ⇒ Object

This method will be handling the auditing of the requests and responses we send to TeamServer. If the audit feature is enabled, we’ll log to file the request and/or response JSON objects.

Parameters:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/contrast/agent/reporting/reporting_utilities/audit.rb', line 28

def audit_event event, response_data = nil
  return unless ::Contrast::API.request_audit_requests || ::Contrast::API.request_audit_responses

  file_name = event.cs__respond_to?(:file_name) ? event.file_name : event.cs__class.cs__name.to_s.downcase
  data = event.event_json
  log_data(:request, file_name, data) if data
  return unless ::Contrast::API.request_audit_responses

  data = response_data&.body ||
      { response_code: response_data.code, response_body: 'There is no available response body' }.to_json
  log_data(:response, file_name, data)
rescue StandardError => e
  logger.error('Audit failed with error: ', event: event, error: e)
end