Sha256: 9eb02b575a6048b4b6fba174b64840a8093301527a574d56d6a0e0e962e29e85
Contents?: true
Size: 1.11 KB
Versions: 6
Compression:
Stored size: 1.11 KB
Contents
module RequestLogAnalyzer::Filter # Filter to select or reject a specific field # Options # * <tt>:mode</tt> :reject or :accept. # * <tt>:field</tt> Specific field to accept or reject. # * <tt>:value</tt> Value that the field should match to be accepted or rejected. class Anonimize < Base def prepare end def generate_random_ip "#{rand(256)}.#{rand(256)}.#{rand(256)}.#{rand(256)}" end def anonymize_url(value) return value.sub(/^https?\:\/\/[A-z0-9\.-]+\//, "http://example.com/") end def fuzz(value) value * ((75 + rand(50)) / 100.0) end def filter(request) return nil unless request request.attributes.each do |key, value| if key == :ip request.attributes[key] = generate_random_ip elsif key == :url request.attributes[key] = anonymize_url(value) elsif [ :duration, :view, :db, :type, :after_filters_time, :before_filters_time, :action_time].include?(key) request.attributes[key] = fuzz(value) end end return request end end end
Version data entries
6 entries across 6 versions & 2 rubygems