class Mmtrix::Agent::Database::Obfuscator
Constants
- FAILED_TO_OBFUSCATE_MESSAGE
- QUERY_TOO_LARGE_MESSAGE
Attributes
obfuscator[R]
Public Class Methods
new()
click to toggle source
# File lib/mmtrix/agent/database/obfuscator.rb, line 19 def initialize reset end
Public Instance Methods
default_sql_obfuscator(sql)
click to toggle source
# File lib/mmtrix/agent/database/obfuscator.rb, line 50 def default_sql_obfuscator(sql) if sql[-3,3] == '...' return QUERY_TOO_LARGE_MESSAGE end stmt = sql.kind_of?(Statement) ? sql : Statement.new(sql) obfuscate_double_quotes = stmt.adapter.to_s !~ /postgres|sqlite/ obfuscated = obfuscate_numeric_literals(stmt) if obfuscate_double_quotes obfuscated = obfuscate_quoted_literals(obfuscated) obfuscated = remove_comments(obfuscated) if contains_quotes?(obfuscated) obfuscated = FAILED_TO_OBFUSCATE_MESSAGE end else obfuscated = obfuscate_single_quote_literals(obfuscated) obfuscated = remove_comments(obfuscated) if contains_single_quotes?(obfuscated) obfuscated = FAILED_TO_OBFUSCATE_MESSAGE end end obfuscated.to_s # return back to a regular String end
reset()
click to toggle source
# File lib/mmtrix/agent/database/obfuscator.rb, line 23 def reset @obfuscator = method(:default_sql_obfuscator) end
set_sql_obfuscator(type, &block)
click to toggle source
Sets the sql obfuscator used to clean up sql when sending it to the server. Possible types are:
:before => sets the block to run before the existing obfuscators
:after => sets the block to run after the existing obfuscator(s)
:replace => removes the current obfuscator and replaces it with the provided block
# File lib/mmtrix/agent/database/obfuscator.rb, line 38 def set_sql_obfuscator(type, &block) if type == :before @obfuscator = Mmtrix::ChainedCall.new(block, @obfuscator) elsif type == :after @obfuscator = Mmtrix::ChainedCall.new(@obfuscator, block) elsif type == :replace @obfuscator = block else fail "unknown sql_obfuscator type #{type}" end end