# 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] 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, nil] def assign_filename source Contrast::Components::Config::Sources::APP_CONFIGURATION_EXTENSIONS.each do |type| # We use the source to transfer the file's name from the mapping of the extensions. # This is done b/c the user_configuration file has a second field to be filled, # and other sources don't. Transfer the source as filename and set the default value # for it later when we find the sources. instance_variable_set(:@filename, source) if source.include?(".#{ type.downcase }") end end end end end end