class ElasticAPM::Transport::Filters::SecretsFilter
@api private
Constants
- FILTERED
- KEY_FILTERS
- VALUE_FILTERS
Public Class Methods
new(config)
click to toggle source
# File lib/elastic_apm/transport/filters/secrets_filter.rb, line 25 def initialize(config) @config = config @key_filters = KEY_FILTERS + config.custom_key_filters end
Public Instance Methods
call(payload)
click to toggle source
# File lib/elastic_apm/transport/filters/secrets_filter.rb, line 30 def call(payload) strip_from! payload.dig(:transaction, :context, :request, :headers) strip_from! payload.dig(:transaction, :context, :request, :env) strip_from! payload.dig(:transaction, :context, :request, :cookies) strip_from! payload.dig(:transaction, :context, :response, :headers) strip_from! payload.dig(:error, :context, :request, :headers) strip_from! payload.dig(:error, :context, :response, :headers) strip_from! payload.dig(:transaction, :context, :request, :body) payload end
filter_key?(key)
click to toggle source
rubocop:enable Metrics/MethodLength, Metrics/CyclomaticComplexity
# File lib/elastic_apm/transport/filters/secrets_filter.rb, line 63 def filter_key?(key) @key_filters.any? { |regex| key.match regex } end
filter_value?(value)
click to toggle source
# File lib/elastic_apm/transport/filters/secrets_filter.rb, line 67 def filter_value?(value) VALUE_FILTERS.any? { |regex| value.match regex } end
strip_from!(obj)
click to toggle source
rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
# File lib/elastic_apm/transport/filters/secrets_filter.rb, line 43 def strip_from!(obj) return unless obj && obj.is_a?(Hash) obj.each do |k, v| if filter_key?(k) next obj[k] = FILTERED end case v when Hash strip_from!(v) when String if filter_value?(v) obj[k] = FILTERED end end end end