Class: Appsignal::EventFormatter::MongoRubyDriver::QueryFormatter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

ALLOWED =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  "find" => {
    "find"   => :allow,
    "filter" => :sanitize_document
  },
  "count" => {
    "count" => :allow,
    "query" => :sanitize_document
  },
  "distinct" => {
    "distinct" => :allow,
    "key"      => :allow,
    "query"    => :sanitize_document
  },
  "insert" => {
    "insert"    => :allow,
    "documents" => :sanitize_document,
    "ordered"   => :allow
  },
  "update" => {
    "update"  => :allow,
    "updates" => :sanitize_document,
    "ordered" => :allow
  },
  "findandmodify" => {
    "findandmodify" => :allow,
    "query"         => :sanitize_document,
    "update"        => :sanitize_document,
    "new"           => :allow
  },
  "delete" => {
    "delete" => :allow,
    "deletes" => :sanitize_document,
    "ordered" => :allow
  },
  "bulk" => {
    "q"      => :sanitize_document,
    "u"      => :sanitize_document,
    "limit"  => :allow,
    "multi"  => :allow,
    "upsert" => :allow
  }
}.freeze

Class Method Summary collapse

Class Method Details

.apply_strategy(strategy, val) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Applies strategy on hash values based on keys



69
70
71
72
73
74
75
76
# File 'lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter.rb', line 69

def self.apply_strategy(strategy, val)
  case strategy
  when :allow then val
  when :sanitize_document
    Appsignal::Utils::QueryParamsSanitizer.sanitize(val, false, :mongodb)
  else "?"
  end
end

.format(strategy, command) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Format command based on given strategy



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter.rb', line 53

def self.format(strategy, command)
  # Stop processing if command is not a hash
  return {} unless command.is_a?(Hash)

  # Get the strategy and stop if it's not present
  strategies = ALLOWED[strategy.to_s]
  return {} unless strategies

  {}.tap do |hsh|
    command.each do |key, val|
      hsh[key] = apply_strategy(strategies[key], val)
    end
  end
end