Sha256: a11b87f04b107628fa3f16b3c47761d35811ed06bb27912aa992e8a5c1289b63

Contents?: true

Size: 1.83 KB

Versions: 11

Compression:

Stored size: 1.83 KB

Contents

require "uri"

module PactBroker
  module Config
    module RuntimeConfigurationLoggingMethods
      module ClassMethods
        def sensitive_values(*values)
          @sensitive_values ||= []
          if values
            @sensitive_values.concat([*values])
          else
            @sensitive_values
          end
        end

        def sensitive_value?(value)
          sensitive_values.any? { |key| key == value || key == value.to_sym || key.kind_of?(Regexp) && key =~ value }
        end
      end

      module InstanceMethods
        def log_configuration(logger)
          to_source_trace.sort_by { |key, _| key }.each { |key, value| log_config_inner(key, value, logger) }
        end

        def log_config_inner(key, value, logger)
          if !value.has_key? :value
            value.sort_by { |inner_key, _| inner_key }.each { |inner_key, inner_value| log_config_inner("#{key}.#{inner_key}", inner_value, logger) }
          elsif self.class.sensitive_value?(key)
            logger.info "#{key}=#{redact(key, value[:value])} source=#{value[:source]}"
          else
            logger.info "#{key}=#{value[:value]} source=#{value[:source]}"
          end
        end
        private :log_config_inner

        def redact name, value
          if value && name.to_s.end_with?("_url")
            begin
              uri = URI(value)
              if uri.password
                uri.password = "*****"
                uri.to_s
              else
                value
              end
            rescue StandardError
              "*****"
            end
          elsif !value.nil?
            "*****"
          else
            nil
          end
        end
        private :redact
      end

      def self.included(receiver)
        receiver.extend         ClassMethods
        receiver.send :include, InstanceMethods
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
pact_broker-2.95.1 lib/pact_broker/config/runtime_configuration_logging_methods.rb
pact_broker-2.95.0 lib/pact_broker/config/runtime_configuration_logging_methods.rb
pact_broker-2.94.0 lib/pact_broker/config/runtime_configuration_logging_methods.rb
pact_broker-2.93.4 lib/pact_broker/config/runtime_configuration_logging_methods.rb
pact_broker-2.93.3 lib/pact_broker/config/runtime_configuration_logging_methods.rb
pact_broker-2.93.2 lib/pact_broker/config/runtime_configuration_logging_methods.rb
pact_broker-2.93.1 lib/pact_broker/config/runtime_configuration_logging_methods.rb
pact_broker-2.93.0 lib/pact_broker/config/runtime_configuration_logging_methods.rb
pact_broker-2.92.0 lib/pact_broker/config/runtime_configuration_logging_methods.rb
pact_broker-2.91.0 lib/pact_broker/config/runtime_configuration_logging_methods.rb
pact_broker-2.90.0 lib/pact_broker/config/runtime_configuration_logging_methods.rb