Class: Contrast::Agent::Reporting::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/contrast/agent/reporting/reporting_utilities/response.rb

Overview

this class will hold the response from TS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#application_settingsContrast::Agent::Reporting::Settings::ApplicationSettings?

All of the settings from TeamServer that apply at the application level. At least one, but not necessarily all, setting will differ from the agent’s current set. Agents are able to replace all application settings with those in this message.



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

def application_settings
  @application_settings
end

#messagesArray<String>

Message with reasons for success or fail.

Returns:

  • (Array<String>)

    Messages received from TS.



33
34
35
# File 'lib/contrast/agent/reporting/reporting_utilities/response.rb', line 33

def messages
  @messages
end

#server_featuresContrast::Agent::Reporting::Settings::ServerFeatures?

All of the feature server_features



23
24
25
# File 'lib/contrast/agent/reporting/reporting_utilities/response.rb', line 23

def server_features
  @server_features
end

#successBoolean

Success boolean message value

Returns:

  • (Boolean)


28
29
30
# File 'lib/contrast/agent/reporting/reporting_utilities/response.rb', line 28

def success
  @success
end

Class Method Details

.build_application_responseObject

All of the settings from TeamServer that apply at the application level.



39
40
41
42
43
# File 'lib/contrast/agent/reporting/reporting_utilities/response.rb', line 39

def build_application_response
  res = new
  res.application_settings = Contrast::Agent::Reporting::Settings::ApplicationSettings.new
  res
end

.build_server_responseObject

All of the settings from TeamServer that apply at the server level.



48
49
50
51
52
# File 'lib/contrast/agent/reporting/reporting_utilities/response.rb', line 48

def build_server_response
  res = new
  res.server_features = Contrast::Agent::Reporting::Settings::ServerFeatures.new
  res
end

Instance Method Details

#reactionsArray<Contrast::Agent::Reporting::Settings::Reaction>

Reaction the agent should take based on a state in TS. This is moved one level up because the responses we receive for feature and settings from TS have different place to store these reactions:

body.reactions vs body.settings.reactions



63
64
65
# File 'lib/contrast/agent/reporting/reporting_utilities/response.rb', line 63

def reactions
  @_reactions ||= []
end

#reactions=(reaction_array) ⇒ Array<Contrast::Agent::Reporting::Settings::Reaction>

Set the reaction

Parameters:

  • reaction_array (Array<Reaction>)

    { level [String] The level at which the agent should log this reaction.

    [ERROR, WARN, INFO, DEBUG, TRACE]
    

    message [String] A message to log when receiving this reaction. operation [String] What to do in response to this reaction.[NOOP, DISABLE] }

Returns:



75
76
77
78
79
80
81
# File 'lib/contrast/agent/reporting/reporting_utilities/response.rb', line 75

def reactions= reaction_array
  return unless reaction_array.is_a?(Array)

  reaction_array.each do |r|
    reactions << Contrast::Agent::Reporting::Settings::Reaction.new(r[:level], r[:operation], r[:message])
  end
end

#to_controlled_hashObject

This method is used only for testing with golden files.



84
85
86
87
88
89
90
91
92
# File 'lib/contrast/agent/reporting/reporting_utilities/response.rb', line 84

def to_controlled_hash
  {
      success: success,
      messages: messages,
      features: server_features.nil? ? nil : server_features.to_controlled_hash,
      settings: application_settings.nil? ? nil : application_settings.to_controlled_hash,
      reactions: server_features.nil? ? nil : reactions.map(&:to_controlled_hash)
  }.compact
end