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



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/karafka/pro/encryption/messages/middleware.rb', line 31

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