Sha256: 89430abd0e167cecafdc43d0dc38ebbeae28872145f2f9dc4d4e253d16c65e15

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require 'fluent/plugin/filter'
require 'fluent/plugin/pan/masker'

module Fluent::Plugin
  class PANAnonymizerFilter < Filter
    Fluent::Plugin.register_filter("pan_anonymizer", self)

    config_section :pan, param_name: :pan_configs, required: true, multi: true do
      config_param :formats,            :array,  value_type: :regexp, default: []
      config_param :checksum_algorithm, :enum,   list: Fluent::PAN::Masker::CHECKSUM_FUNC.keys, default: :luhn
      config_param :mask,               :string, default: "****"
      config_param :force,              :bool,   default: false
    end
    config_param :ignore_keys,          :array,  default: []

    def initialize
      super
    end

    def configure(conf)
      super

      @pan_masker = @pan_configs.map do |i|
        i[:formats].map do |format|
          Fluent::PAN::Masker.new(format, i[:checksum_algorithm], i[:mask], i[:force])
        end
      end.flatten
    end

    def filter(tag, time, record)
      record.map do |key, value|
        if @ignore_keys.include? key.to_s
          [key, value]
        else
          _value = value
          @pan_masker.each do |i|
            _value = i.mask_if_found_pan(_value)
          end
          [key, _value]
        end
      end.to_h
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-pan-anonymizer-0.0.1 lib/fluent/plugin/filter_pan_anonymizer.rb