lib/contrast/config/diagnostics/source_config_value.rb in contrast-agent-7.3.2 vs lib/contrast/config/diagnostics/source_config_value.rb in contrast-agent-7.4.0

- old
+ new

@@ -1,13 +1,18 @@ # Copyright (c) 2023 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true +require 'contrast/utils/object_share' +require 'contrast/utils/duck_utils' + module Contrast module Config module Diagnostics # All config values from all sources, stored in a easy to write representation. class SourceConfigValue + NULL = 'null' + # @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 @@ -18,26 +23,26 @@ 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 + name: key || Contrast::Utils::ObjectShare::EMPTY_STRING, + value: Contrast::Config::Diagnostics::Tools.value_to_s(value), + source: source || Contrast::Utils::ObjectShare::EMPTY_STRING, + filename: filename || Contrast::Utils::ObjectShare::EMPTY_STRING + } 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 + name: key || Contrast::Utils::ObjectShare::EMPTY_STRING, + value: Contrast::Config::Diagnostics::Tools.value_to_s(value) + } end # Assigns file name of the config iv viable, Currently supported formats for config file are *.yaml - # and *.yml + # and *.yml. For the config loaded from file the filename is kept as source. # # @param source [String] name of the source file yaml | yml # @return [Array<String>, nil] def assign_filename source Contrast::Components::Config::Sources::APP_CONFIGURATION_EXTENSIONS.each do |type|