Class: Raven::Processor::SanitizeData

Inherits:
Raven::Processor show all
Defined in:
lib/raven/processor/sanitizedata.rb

Constant Summary collapse

STRING_MASK =
'********'
INT_MASK =
0
DEFAULT_FIELDS =
%w(authorization password passwd secret ssn social(.*)?sec)
VALUES_RE =
/^\d{16}$/

Instance Attribute Summary

Attributes inherited from Raven::Processor

#sanitize_fields

Instance Method Summary collapse

Methods inherited from Raven::Processor

#initialize

Constructor Details

This class inherits a constructor from Raven::Processor

Instance Method Details

#process(value) ⇒ Object



8
9
10
# File 'lib/raven/processor/sanitizedata.rb', line 8

def process(value)
  value.inject(value) { |memo,(k,v)|  memo[k] = sanitize(k,v); memo }
end

#sanitize(k, v) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/raven/processor/sanitizedata.rb', line 12

def sanitize(k,v)
  if v.is_a?(Hash)
    process(v)
  elsif v.is_a?(Array)
    v.map{|a| sanitize(nil, a)}
  elsif v.is_a?(String) && (json = parse_json_or_nil(v))
    #if this string is actually a json obj, convert and sanitize
    json.is_a?(Hash) ? process(json).to_json : v
  elsif v.is_a?(Integer) && (VALUES_RE.match(v.to_s) || fields_re.match(k.to_s))
    INT_MASK
  elsif v.is_a?(String)  && (VALUES_RE.match(v.to_s) || fields_re.match(k.to_s))
    STRING_MASK
  else
    v
  end
end