class Fluent::Plugin::EmailObfuscateFilter

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_email_obfuscate.rb, line 40
def configure(conf)
  super
end
deep_process(o) click to toggle source
# File lib/fluent/plugin/filter_email_obfuscate.rb, line 78
def deep_process(o)
  case o
  when String
    case @mode
    when :name_substring
      o = o.gsub(/([a-zA-Z0-9_+\.\-]+@[a-zA-Z0-9\.\-]+)/) { |om|
        obfuscate(om)
      }
    else
      os = o.scan(/<([^<>]+@[^<>]+)>/)
      o = os.length.zero? ? obfuscate(o) : deep_process(os).join(", ")
    end
  when Array
    o.map! do |obj|
      deep_process(obj)
    end
  when Hash
    o.each_pair do |key, value|
      o[key] = deep_process(value)
    end
  end
  o
end
filter(tag, time, record) click to toggle source
# File lib/fluent/plugin/filter_email_obfuscate.rb, line 102
def filter(tag, time, record)
  deep_process(record)
end
hide_partial(str) click to toggle source
# File lib/fluent/plugin/filter_email_obfuscate.rb, line 44
def hide_partial(str)
    case
    when str.length < 5
      len = str.length
    when str.length < 11
      len = (str.length / 2) + 2
    else
      len = (str.length / 3) + 4
    end
    str[0, len] + '*' * (str.length - len)
end
obfuscate(str) click to toggle source
# File lib/fluent/plugin/filter_email_obfuscate.rb, line 56
def obfuscate(str)
  strmatch = str.match(/^([^@]+)(@.+)$/) { |m|
     case @mode
     when :domain_only
       m[1] + m[2].tr("@.a-zA-Z0-9", "@.*")
     when :full
       m[1].gsub(/./, '*') + m[2].tr("@.a-zA-Z0-9", "@.*")
     when :name_substring
       m[1].gsub(/./, '*') + m[2]
     else
       hide_partial(m[1]) + m[2].tr("@.a-zA-Z0-9", "@.*")
     end
  }
  if strmatch.nil?
    str
  elsif @suffix_whitelist.select{ |a| str.downcase.end_with?(a.downcase)}.empty?
    strmatch
  else
    str
  end
end