Sha256: 73c7c3063e74bf8a178d8b7d775bf9866f9962a59a8ac8584adf33dbcd752c88

Contents?: true

Size: 1.19 KB

Versions: 6

Compression:

Stored size: 1.19 KB

Contents

module Hermes
  class Logger
    class ParamsFilter
      SENSITIVE_ATTRIBUTES_KEYWORDS = %w(token password credit_card card_number security_code verification_value
        private_key signature api_key secret_key publishable_key client_key client_secret secret).freeze
      STRIPPED_VALUE = "[STRIPPED]".freeze

      private_constant :SENSITIVE_ATTRIBUTES_KEYWORDS, :STRIPPED_VALUE

      attr_reader :sensitive_keywords, :stripped_value
      private     :sensitive_keywords, :stripped_value

      def initialize(sensitive_keywords: SENSITIVE_ATTRIBUTES_KEYWORDS, stripped_value: STRIPPED_VALUE)
        @sensitive_keywords = sensitive_keywords
        @stripped_value = stripped_value
      end

      def call(attribute, value)
        if sensitive_keywords.any? { |sensitive_attribute| match?(sensitive_attribute, attribute) } && value.respond_to?(:to_str)
          value.gsub!(value, stripped_value)
        end
      end

      private

      def match?(sensitive_attribute, attribute)
        if Regexp === sensitive_attribute
          attribute.to_s.match(sensitive_attribute)
        else
          attribute.to_s.downcase.match(sensitive_attribute.to_s.downcase)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hermes-rb-0.10.1 lib/hermes/logger/params_filter.rb
hermes-rb-0.10.0 lib/hermes/logger/params_filter.rb
hermes-rb-0.9.1 lib/hermes/logger/params_filter.rb
hermes-rb-0.9.0 lib/hermes/logger/params_filter.rb
hermes-rb-0.8.0 lib/hermes/logger/params_filter.rb
hermes-rb-0.7.5 lib/hermes/logger/params_filter.rb