Encrypting the connection between Kafka and the Heroku web app

This can be achieved by adding a small helper script at the root of your Node.js application. The file must be named env.sh. The following shows the code snippet for the env.sh file:

    #!/usr/bin/env bash

set -eo pipefail

function cleanup {
rm -f client.crt client.key
echo ""
echo "-----> Exiting."
exit
}
trap cleanup SIGINT SIGTERM

if [[ -z "${KAFKA_CLIENT_CERT}" ]]; then
echo "KAFKA_CLIENT_CERT is not set. Aborting"
exit 1
fi

if [[ -z "${KAFKA_CLIENT_CERT_KEY}" ]]; then
echo "KAFKA_CLIENT_CERT_KEY is not set. Aborting"
exit 1
fi

if [[ -z "${KAFKA_URL}" ]]; then
echo "KAFKA_URL is not set. Aborting"
exit 1
fi

# Setup cert and cert key
rm -f client.crt client.key
echo -n "$KAFKA_CLIENT_CERT" > client.crt
echo -n "$KAFKA_CLIENT_CERT_KEY" > client.key

The Heroku profile will have the following code:

web: ./env.sh && npm start
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset