# Copyright (c) 2022 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 MESSAGE_FAIL = 'Unable to connect to Contrast, configuration details from the Contrast UI will not be included.' MESSAGE_SUCCESSFUL = 'Connected to Contrast.' 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 @config_status == MESSAGE_FAIL || CONN_STATUS_MSG_FAILURE response_code = response.code.to_s @config_status = response_code.starts_with?('2') ? MESSAGE_SUCCESSFUL : MESSAGE_FAIL nil 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 }) end end end end end