lib/contrast/configuration.rb in contrast-agent-7.1.0 vs lib/contrast/configuration.rb in contrast-agent-7.2.0

- old
+ new

@@ -79,15 +79,15 @@ end # Overlay CLI options - they take precedence over config file cli_options = Contrast::Utils::HashUtils.deep_symbolize_all_keys(cli_options) if cli_options - config_kv = Contrast::Utils::HashUtils.deep_merge(cli_options, config_kv) + config_kv = Contrast::Utils::HashUtils.precedence_merge(cli_options, config_kv) @_source_file_extensions = Contrast::Utils::HashUtils. - deep_merge(assign_source_to(cli_options, - Contrast::Components::Config::Sources::COMMAND_LINE), - @_source_file_extensions) + precedence_merge(assign_source_to(cli_options, + Contrast::Components::Config::Sources::COMMAND_LINE), + @_source_file_extensions) end # Some in-flight rewrites to maintain backwards compatibility config_kv = update_prop_keys(config_kv) @loaded_config = config_kv @@ -155,11 +155,11 @@ # reverse order of precedence (first is most important). def configuration_paths @_configuration_paths ||= begin basename = default_name.split('.').first # Order of extensions comes from here: - extensions = Contrast::Components::Config::Sources::APP_CONFIGURATION_FILE.map(&:downcase) + extensions = Contrast::Components::Config::Sources::APP_CONFIGURATION_EXTENSIONS paths = [] # Environment paths takes precedence here. Look first through them. paths << ENV['CONTRAST_CONFIG_PATH'] if ENV['CONTRAST_CONFIG_PATH'] paths << ENV['CONTRAST_SECURITY_CONFIG'] if ENV['CONTRAST_SECURITY_CONFIG'] @@ -214,26 +214,27 @@ log_file_read_error(path) next end origin.add_source_file(path, (yaml_to_hash(path) || {})) end - # Legacy usage: Assign main configuration file for reference. @config_file = origin.main_file # merge all settings keeping the top yaml files values as priority. # If in top file a key exists it's value won't be changed if same key has different value in one # of the other config files. Only unique values will be taken in consideration.w # precedence of paths: see Contrast::Configuration::CONFIG_BASE_PATHS extensions_maps = [] origin.source_files.each do |file| - # config.merge!(file.values) { |_key, oldval, _newval| oldval = oldval } - precedence_merge!(config, file.values) + config = Contrast::Utils::HashUtils.precedence_merge(config, file.values) # assign source values extentions: extensions_maps << assign_source_to(Contrast::Utils::HashUtils.deep_symbolize_all_keys(file.values), file.path) end + # merge all origin paths to be used as extension classification to preserve the precedence of config files: - extensions_maps.each { |path| @_source_file_extensions = precedence_merge!(@_source_file_extensions, path) } + extensions_maps.each do |path| + @_source_file_extensions = Contrast::Utils::HashUtils.precedence_merge!(@_source_file_extensions, path) + end config end # We're updating properties loaded from the configuration files to match the new agreed upon standard configuration @@ -355,25 +356,16 @@ # @return[Boolean] true | false def redactable? key KEYS_TO_REDACT.include?(key.to_sym) end - def assign_source_to hash, source = Contrast::Components::Config::Sources::APP_CONFIGURATION_FILE[0] + def assign_source_to hash, source = Contrast::Components::Config::Sources::APP_CONFIGURATION_FILE hash.transform_values do |value| if value.is_a?(Hash) assign_source_to(value, source) else source end end - end - - # Merges two hashes, first hash will preserve it's values and will only add unique values. - # - # @param hsh [Hash] - # @param other_hsh [Hash] - # @return [Hash] - def precedence_merge! hsh, other_hsh - hsh.merge!(other_hsh) { |_key, old_val, _new_val| old_val } end end end