Class: Fluent::TreasureDataLogOutput::IPXORAnonymizer

Inherits:
RawAnonymizer show all
Defined in:
lib/fluent/plugin/out_tdlog.rb

Instance Method Summary collapse

Methods inherited from RawAnonymizer

#anonymize

Instance Method Details

#anonymize_raw(raw) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fluent/plugin/out_tdlog.rb', line 49

def anonymize_raw(raw)
  m = /\A(\d+)\.(\d+)\.(\d+)\.(\d+)/.match(raw)
  return nil unless m

  k1, k2, k3, k4 = @xor_keys

  o1 = m[1].to_i ^ k1
  o2 = m[2].to_i ^ k2
  o3 = m[3].to_i ^ k3
  o4 = m[4].to_i ^ k4

  "#{o1}.#{o2}.#{o3}.#{o4}"
end

#configure(conf) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/fluent/plugin/out_tdlog.rb', line 38

def configure(conf)
  super

  a1, a2, a3, a4 = @xor_key.split('.')
  @xor_keys = [a1.to_i, a2.to_i, a3.to_i, a4.to_i]

  if @xor_keys == [0, 0, 0, 0]
    raise ConfigError, "'xor_key' must be IPv4 address"
  end
end