Class: Fluent::Anonymizer

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/anonymizer.rb

Constant Summary collapse

HASH_ALGORITHM =
%w(md5 sha1 sha256 sha384 sha512 ipaddr_mask)
DIGEST =
{
  "md5" => Proc.new { OpenSSL::Digest.new('md5') },
  "sha1" => Proc.new { OpenSSL::Digest.new('sha1') },
  "sha256" => Proc.new { OpenSSL::Digest.new('sha256') },
  "sha384" => Proc.new { OpenSSL::Digest.new('sha384') },
  "sha512" => Proc.new { OpenSSL::Digest.new('sha512') }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plugin, conf) ⇒ Anonymizer

Returns a new instance of Anonymizer.


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fluent/plugin/anonymizer.rb', line 19

def initialize(plugin, conf)
  @log = plugin.log
  @hash_salt = plugin.hash_salt
  @ipv4_mask_subnet = plugin.ipv4_mask_subnet
  @ipv6_mask_subnet = plugin.ipv6_mask_subnet

  @hash_keys = {}
  conf.keys.select{|k| k =~ /_keys$/}.each do |key|
    hash_algorithm_name = key.sub('_keys','')
    raise Fluent::ConfigError, "anonymizer: unsupported key #{hash_algorithm_name}" unless HASH_ALGORITHM.include?(hash_algorithm_name)
    conf[key].gsub(' ', '').split(',').each do |record_key|
      @hash_keys.store(record_key.split('.'), hash_algorithm_name)
    end
  end

  if @hash_keys.empty?
    raise Fluent::ConfigError, "anonymizer: missing hash keys setting."
  end
  log.info "anonymizer: adding anonymize rules for each field. #{@hash_keys}"

  if plugin.is_a?(Fluent::Output)
    unless have_tag_option?(plugin)
      raise Fluent::ConfigError, "anonymizer: missing remove_tag_prefix, remove_tag_suffix, add_tag_prefix or add_tag_suffix."
    end
  end
end

Instance Attribute Details

#logObject (readonly)

Returns the value of attribute log


8
9
10
# File 'lib/fluent/plugin/anonymizer.rb', line 8

def log
  @log
end

Instance Method Details

#anonymize(record) ⇒ Object


46
47
48
49
50
51
# File 'lib/fluent/plugin/anonymizer.rb', line 46

def anonymize(record)
  @hash_keys.each do |hash_key, hash_algorithm|
    record = anonymize_record(record, hash_key, hash_algorithm)
  end
  record
end