Sha256: 71142fbd3fe05996e9c5156c7102aaf57665a1d511865e03c907b2fd60697870

Contents?: true

Size: 1.72 KB

Versions: 8

Compression:

Stored size: 1.72 KB

Contents

# 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 = '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_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 })
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
contrast-agent-7.0.0 lib/contrast/config/config.rb
contrast-agent-6.15.3 lib/contrast/config/config.rb
contrast-agent-6.15.2 lib/contrast/config/config.rb
contrast-agent-6.15.1 lib/contrast/config/config.rb
contrast-agent-6.15.0 lib/contrast/config/config.rb
contrast-agent-6.14.0 lib/contrast/config/config.rb
contrast-agent-6.13.0 lib/contrast/config/config.rb
contrast-agent-6.12.0 lib/contrast/config/config.rb