Class: Auxilium::Grape::ParameterFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/auxilium/grape/parameter_filter.rb

Constant Summary collapse

FILTER_REGEX =
/password|token|api_key|Authorization/i

Class Method Summary collapse

Class Method Details

.filter(hash, regex = FILTER_REGEX) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/auxilium/grape/parameter_filter.rb', line 7

def filter(hash, regex = FILTER_REGEX)
  hash = hash.dup
  hash.each do |k, v|
    hash[k] = '[FILTERED]' if k.to_s =~ FILTER_REGEX
    hash[k] = filter(v, regex) if v.is_a?(Hash)
    hash[k] = v.map { |v| v.is_a?(Hash) ? filter(v, regex) : v } if v.is_a?(Array)
  end

  hash
end