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. It also fingerprints the payload for verification if fingerprinting was 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



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/karafka/pro/encryption/messages/middleware.rb', line 23

def call(message)
  payload = message[:payload]

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

  return message unless fingerprinter

  message[:headers]['encryption_fingerprint'] = fingerprinter.hexdigest(payload)

  message
end