Class: Karafka::Pro::Encryption::Messages::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/pro/encryption/messages/middleware.rb

Overview

Middleware for WaterDrop. It automatically encrypts messages payload. It is injected only if encryption is enabled.

Instance Method Summary collapse

Instance Method Details

#call(message) ⇒ Hash

Returns hash with encrypted payload and encryption version indicator.

Parameters:

  • message (Hash)

    WaterDrop message hash

Returns:

  • (Hash)

    hash with encrypted payload and encryption version indicator



24
25
26
27
28
29
# File 'lib/karafka/pro/encryption/messages/middleware.rb', line 24

def call(message)
  message[:headers] ||= {}
  message[:headers]['encryption'] = version
  message[:payload] = cipher.encrypt(message[:payload])
  message
end