Class: Fluent::Plugin::EmailObfuscateFilter
- Inherits:
-
Filter
- Object
- Filter
- Fluent::Plugin::EmailObfuscateFilter
- Defined in:
- lib/fluent/plugin/filter_email_obfuscate.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #deep_process(o) ⇒ Object
- #filter(tag, time, record) ⇒ Object
- #hide_partial(str) ⇒ Object
- #obfuscate(str) ⇒ Object
Instance Method Details
#configure(conf) ⇒ Object
40 41 42 |
# File 'lib/fluent/plugin/filter_email_obfuscate.rb', line 40 def configure(conf) super end |
#deep_process(o) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# 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) ⇒ Object
102 103 104 |
# File 'lib/fluent/plugin/filter_email_obfuscate.rb', line 102 def filter(tag, time, record) deep_process(record) end |
#hide_partial(str) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# 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) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# 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 |