Module: NewRelic::Agent::Datastores::NosqlObfuscator

Defined in:
lib/new_relic/agent/datastores/nosql_obfuscator.rb

Constant Summary collapse

ALLOWLIST =
[:operation].freeze
QUESTION_MARK =
'?'.freeze

Class Method Summary collapse

Class Method Details

.obfuscate_statement(source, allowlist = ALLOWLIST) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/new_relic/agent/datastores/nosql_obfuscator.rb', line 11

def self.obfuscate_statement(source, allowlist = ALLOWLIST)
  if source.is_a?(Hash)
    obfuscated = {}
    source.each do |key, value|
      if allowlist.include?(key)
        obfuscated[key] = value
      else
        obfuscated[key] = obfuscate_value(value, allowlist)
      end
    end
    obfuscated
  else
    obfuscate_value(source, allowlist)
  end
end

.obfuscate_value(value, allowlist = ALLOWLIST) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/new_relic/agent/datastores/nosql_obfuscator.rb', line 29

def self.obfuscate_value(value, allowlist = ALLOWLIST)
  if value.is_a?(Hash)
    obfuscate_statement(value, allowlist)
  elsif value.is_a?(Array)
    value.map { |v| obfuscate_value(v, allowlist) }
  else
    QUESTION_MARK
  end
end