Sha256: 4d2728520c1eb5e87e1a167dd730a070f01aa37f2a090e98f7fedd37171f586f

Contents?: true

Size: 1.81 KB

Versions: 2

Compression:

Stored size: 1.81 KB

Contents

# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

module Contrast
  module Config
    # Common Configuration settings. Those in this section pertain to the
    # logging in the Agent.
    class LoggerConfiguration < BaseConfiguration
      # @return [String, nil]
      attr_accessor :path
      # @return [String, nil]
      attr_accessor :level
      # @return [String, nil]
      attr_accessor :progname

      def initialize hsh = {}
        @path = traverse_config(hsh, :path)
        @level = traverse_config(hsh, :level)
        @progname = traverse_config(hsh, :progname)
        @configuration_map = {}
        build_configuration_map
      end

      # TODO: RUBY-1493 MOVE TO BASE CONFIG

      def []= key, value
        instance_variable_set("@#{ key }".to_sym, value)
        @configuration_map[key] = value
      end

      def [] key
        send(key.to_sym)
      end

      # Traverse the given entity to build out the configuration graph.
      #
      # The values will be either a hash, indicating internal nodes to
      # traverse, or a value to set or the EMPTY_VALUE symbol, indicating a
      # leaf node.
      #
      # The spec_key are the Contrast defined keys based on the instance variables of
      # a given configuration.
      def traverse_config values, spec_key
        internal_nodes = values.cs__respond_to?(:has_key?)
        val = internal_nodes ? value_from_key_config(spec_key, values) : nil
        val == EMPTY_VALUE ? nil : val
      end

      def build_configuration_map
        instance_variables.each do |key|
          str_key = key.to_s.tr('@', '')
          next if str_key == 'configuration_map'

          @configuration_map[str_key] = send(str_key.to_sym)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
contrast-agent-5.3.0 lib/contrast/config/logger_configuration.rb
contrast-agent-5.2.0 lib/contrast/config/logger_configuration.rb