Sha256: 0ca6555f9525443153feda7f908caeb95fced0343dc195d8b7154cb0729dcace

Contents?: true

Size: 1.86 KB

Versions: 1

Compression:

Stored size: 1.86 KB

Contents

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

module Contrast
  module Config
    module Diagnostics
      # All config values from all sources, stored in a easy to write representation.
      class SourceConfigValue
        # @return [String] Name of the config starting form root of yaml config.
        attr_accessor :canonical_name
        # @return [String] Name of the config.
        attr_accessor :key
        # @return [String, Boolean, array<String>] Value set for the config. Current Effective Value
        attr_accessor :value
        # @return [String] The source for the entry in the config.
        attr_accessor :source
        # @return [String,nil] The filename for the source of the config, if the source was "yaml".
        attr_accessor :filename

        def to_controlled_hash
          {
              canonical_name: canonical_name,
              name: key,
              value: value.cs__is_a?(Array) ? value.map(&:to_s) : value.to_s,
              source: source,
              filename: filename
          }.compact
        end

        def to_source_hash
          {
              canonical_name: canonical_name,
              name: key,
              value: value.cs__is_a?(Array) ? value.map(&:to_s) : value.to_s
          }.compact
        end

        # Assigns file name of the config iv viable, Currently supported formats for config file are *.yaml
        # and *.yml
        #
        # @param source [String] name of the source file yaml | yml
        # @return [Array<String>, nil]
        def assign_filename source
          Contrast::Components::Config::Sources::APP_CONFIGURATION_FILE.each do |type|
            instance_variable_set(:@filename, source) if source.include?(".#{ type.downcase }")
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
contrast-agent-7.1.0 lib/contrast/config/diagnostics/source_config_value.rb