Sha256: c8c3170081015f89539976430091d0dc0575fbc0591f70faeaf2ae51415abb48

Contents?: true

Size: 1.99 KB

Versions: 5

Compression:

Stored size: 1.99 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/base_configuration'

module Contrast
  module Config
    # Common Configuration settings. Those in this section pertain to the server identification functionality of the
    # Agent.
    class ServerConfiguration
      include Contrast::Config::BaseConfiguration
      include Contrast::Components::ComponentBase

      CANON_NAME = 'server'
      CONFIG_VALUES = %w[tags environment version].cs__freeze

      # @return [String, nil]
      attr_accessor :name
      # @return [String, nil]
      attr_accessor :path
      # @return [String, nil]
      attr_accessor :type
      attr_writer :tags
      # @return [String, nil]
      attr_accessor :environment
      # @return [String, nil]
      attr_accessor :version
      # @return [String]
      attr_reader :canon_name
      # @return [Array]
      attr_reader :config_values

      def initialize hsh = {}
        @config_values = CONFIG_VALUES
        @canon_name = CANON_NAME
        return unless hsh

        @path = hsh[:path]
        @name = hsh[:name]
        @type = hsh[:type]
        @tags = hsh[:tags]
        @environment = hsh[:environment]
        @version = hsh[:version]
      end

      # @return [String, nil]
      def tags
        stringify_array(@tags)
      end

      # Converts current configuration to effective config values class and appends them to
      # EffectiveConfig class.
      #
      # @param effective_config [Contrast::Config::Diagnostics::EffectiveConfig]
      def to_effective_config effective_config
        super
        add_single_effective_value(effective_config, 'type', Contrast::APP_CONTEXT.server_type, CANON_NAME)
        add_single_effective_value(effective_config, 'name', Contrast::APP_CONTEXT.server_name, CANON_NAME)
        add_single_effective_value(effective_config, 'path', Contrast::APP_CONTEXT.server_path, CANON_NAME)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
contrast-agent-7.6.1 lib/contrast/config/server_configuration.rb
contrast-agent-7.6.0 lib/contrast/config/server_configuration.rb
contrast-agent-7.5.0 lib/contrast/config/server_configuration.rb
contrast-agent-7.4.1 lib/contrast/config/server_configuration.rb
contrast-agent-7.4.0 lib/contrast/config/server_configuration.rb