lib/contrast/config/config.rb in contrast-agent-6.11.0 vs lib/contrast/config/config.rb in contrast-agent-6.12.0

- old
+ new

@@ -1,45 +1,47 @@ -# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. +# Copyright (c) 2023 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true require 'contrast/config/effective_config' module Contrast module Agent module DiagnosticsConfig # This class is responsible for logging to file the effective Agent configurations after startup. class Config attr_reader :effective_config + # @return [String] Status message of the connection with TS. + attr_accessor :config_status MESSAGE_FAIL = 'Unable to connect to Contrast, configuration details from the Contrast UI will not be included.' - MESSAGE_SUCCESSFUL = 'Connected to Contrast.' + MESSAGE_SUCCESSFUL = 'Success' CONN_STATUS_MSG_FAILURE = 'Unable to connect to Contrast, insufficient connection properties provided.' def initialize @effective_config = Contrast::Agent::DiagnosticsConfig::EffectiveConfig.new @config_status = Contrast::Utils::ObjectShare::EMPTY_STRING end # This method will set the status from the request/response cycles # - # @param response [Contrast::Agent::Reporting::Response] - def determine_config_status response - return unless response - # If we encounter for some of the startup events failure - always return failure - return if [MESSAGE_FAIL, CONN_STATUS_MSG_FAILURE].include?(@config_status) - - response_code = response.code.to_s - @config_status = response_code.start_with?('2') ? MESSAGE_SUCCESSFUL : MESSAGE_FAIL - nil + # @param response_code [string] + def determine_config_status response_code + @config_status = case response_code + when '200', '304' + MESSAGE_SUCCESSFUL + else + MESSAGE_FAIL + end + true end # This method will set the status message from the config validation def populate_fail_connection @config_status = CONN_STATUS_MSG_FAILURE end def to_controlled_hash - @effective_config.to_controlled_hash.merge({ Status: @config_status }) + @effective_config.to_controlled_hash.merge({ status: @config_status }) end end end end end