class Fluent::EncryptFilter
Constants
- SUPPORTED_ALGORITHMS
Attributes
target_keys[R]
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_encrypt.rb, line 29 def configure(conf) super @target_keys = @keys + [@key] if @target_keys.empty? raise Fluent::ConfigError, "no keys specified to be encrypted" end algorithm = SUPPORTED_ALGORITHMS[@algorithm] if algorithm[:use_iv] && !@encrypt_iv_hex raise Fluent::ConfigError, "Encryption algorithm #{@algorithm} requires 'encrypt_iv_hex'" end @enc_key = Base64.decode64(@encrypt_key_hex) @enc_iv = if @encrypt_iv_hex Base64.decode64(@encrypt_iv_hex) else nil end @enc_generator = ->(){ enc = OpenSSL::Cipher.new(algorithm[:name]) enc.encrypt enc.key = @enc_key[0..31] enc.iv = @enc_iv[0..15] if @enc_iv enc } end
encrypt(value)
click to toggle source
# File lib/fluent/plugin/filter_encrypt.rb, line 71 def encrypt(value) encrypted = "" enc = @enc_generator.call() encrypted << enc.update(value) encrypted << enc.final Base64.encode64(encrypted) end
filter_stream(tag, es)
click to toggle source
# File lib/fluent/plugin/filter_encrypt.rb, line 57 def filter_stream(tag, es) new_es = MultiEventStream.new es.each do |time, record| r = record.dup record.each_pair do |key, value| if @target_keys.include?(key) r[key] = encrypt(value) end end new_es.add(time, r) end new_es end