Sha256: ef831d6180dd7ae081c92205b3b789e35cb8473d115104c730371c300ce5f2f7

Contents?: true

Size: 1.13 KB

Versions: 33

Compression:

Stored size: 1.13 KB

Contents

# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
# frozen_string_literal: true

module NewRelic
  module Agent
    module Datastores
      module NosqlObfuscator
        ALLOWLIST = [:operation].freeze

        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

        QUESTION_MARK = '?'.freeze

        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
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
newrelic_rpm-9.17.0 lib/new_relic/agent/datastores/nosql_obfuscator.rb
newrelic_rpm-9.16.1 lib/new_relic/agent/datastores/nosql_obfuscator.rb
newrelic_rpm-9.16.0 lib/new_relic/agent/datastores/nosql_obfuscator.rb
newrelic_rpm-9.15.0 lib/new_relic/agent/datastores/nosql_obfuscator.rb
newrelic_rpm-9.14.0 lib/new_relic/agent/datastores/nosql_obfuscator.rb
newrelic_rpm-9.13.0 lib/new_relic/agent/datastores/nosql_obfuscator.rb
newrelic_rpm-9.12.0 lib/new_relic/agent/datastores/nosql_obfuscator.rb
newrelic_rpm-9.11.0 lib/new_relic/agent/datastores/nosql_obfuscator.rb
newrelic_rpm-9.10.2 lib/new_relic/agent/datastores/nosql_obfuscator.rb
newrelic_rpm-9.10.1 lib/new_relic/agent/datastores/nosql_obfuscator.rb
newrelic_rpm-9.10.0 lib/new_relic/agent/datastores/nosql_obfuscator.rb
newrelic_rpm-9.9.0 lib/new_relic/agent/datastores/nosql_obfuscator.rb
newrelic_rpm-9.8.0 lib/new_relic/agent/datastores/nosql_obfuscator.rb
newrelic_rpm-9.7.1 lib/new_relic/agent/datastores/nosql_obfuscator.rb
newrelic_rpm-9.7.0 lib/new_relic/agent/datastores/nosql_obfuscator.rb
newrelic_rpm-9.6.0 lib/new_relic/agent/datastores/nosql_obfuscator.rb
newrelic_rpm-9.5.0 lib/new_relic/agent/datastores/nosql_obfuscator.rb
newrelic_rpm-9.4.2 lib/new_relic/agent/datastores/nosql_obfuscator.rb
newrelic_rpm-9.4.1 lib/new_relic/agent/datastores/nosql_obfuscator.rb
newrelic_rpm-9.4.0 lib/new_relic/agent/datastores/nosql_obfuscator.rb