Created
January 8, 2020 00:10
-
-
Save andscoop/6dd7bf503f20a77a4770ff711578be20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# App Name - also used for conf file naming | |
## | |
app_name=$1 | |
| |
if [ -z "$1" ];then | |
echo "Must provide app_name!" | |
exit 1 | |
fi | |
| |
## | |
# ENV Prefix - in most cases this should be the standard "KAFKA" (ie KAKFA) | |
## | |
if [ -n "$2" ];then | |
env_prefix=$2 | |
env_prefix+="_" | |
else | |
env_prefix="KAFKA_" | |
fi | |
| |
## | |
# Defaults | |
## | |
| |
cli_cmd="heroku" | |
| |
# Heroku Kafka Env Defaults | |
env_trusted_cert="$env_prefix" | |
env_trusted_cert+="TRUSTED_CERT" | |
| |
env_client_cert="$env_prefix" | |
env_client_cert+="CLIENT_CERT" | |
| |
env_cert_key="$env_prefix" | |
env_cert_key+="CLIENT_CERT_KEY" | |
| |
env_kafka_url="$env_prefix" | |
env_kafka_url+="URL" | |
| |
## | |
# Echo Commands Needed to Pull App Vars | |
## | |
echo "\nRun the following commands to capture the cluster configuration" | |
echo "------------------------------------------------------------------\n" | |
| |
echo "$cli_cmd config:get $env_trusted_cert -a $app_name > $PWD/ca.pem" | |
echo "$cli_cmd config:get $env_client_cert -a $app_name > $PWD/cert.pem" | |
echo "$cli_cmd config:get $env_cert_key -a $app_name > $PWD/cert.key" | |
echo "\nKAFKA_URL=$(heroku config:get $env_kafka_url -a $app_name | sed 's/kafka\+ssl\:\/\///g')" | |
| |
## | |
# TODO: Run Commands in Subshells | |
## | |
# trusted_cert_out=$($cli_cmd config:get $env_trusted_cert -a $app_name) | |
# client_cert_out$($cli_cmd config:get $env_client_cert -a $app_name) | |
# cert_key_out=$($cli_cmd config:get $env_cert_key -a $app_name) | |
# kafka_url_out=$($cli_cmd config:get $env_kafka_url -a $app_name | sed 's/kafka\+ssl\:\/\///g') | |
| |
# Build the Config File | |
if [ ! -f kafkacat.conf ]; then | |
echo "\nCreating kafkacat.conf" | |
| |
echo "security.protocol=ssl\nssl.key.location=$PWD/cert.key\nssl.certificate.location=$PWD/cert.pem\nssl.ca.location=$PWD/ca.pem" > kafkacat.conf | |
else | |
echo "\nkafkacat.conf found!" | |
fi | |
| |
# kafkacat_config=${PWD} | |
# kafkacat_config+="/kafkacat.conf" | |
| |
# echo "Setting KAFKACAT_CONFIG to $kafkacat_config" | |
# export KAFKACAT_CONFIG="$kafkacat_config" | |
| |
## | |
# Print Command Template | |
## | |
| |
echo "\n Example kafkacat command" | |
echo "------------------" | |
echo "kafkacat -b \$KAFKA_URL -F kafkacat.conf -L\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment