Class: Karafka::Pro::Encryption::Messages::Middleware
- Inherits:
-
Object
- Object
- Karafka::Pro::Encryption::Messages::Middleware
- 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
-
#call(message) ⇒ Hash
Hash with encrypted payload and encryption version indicator.
Instance Method Details
#call(message) ⇒ Hash
Returns hash with encrypted payload and encryption version indicator.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/karafka/pro/encryption/messages/middleware.rb', line 48 def call() payload = [:payload] # Tombstones (records with a nil payload) carry no data to encrypt. We pass them # through untouched so they remain valid tombstones (for example for log compaction) # instead of crashing on `cipher.encrypt(nil)`. return if payload.nil? [:headers] ||= {} [:headers]["encryption"] = version [:payload] = cipher.encrypt(payload) return unless fingerprinter [:headers]["encryption_fingerprint"] = fingerprinter.hexdigest(payload) end |