Last active
October 20, 2022 21:03
-
-
Save bbejeck/b047323528b41575d7d53930a09eb7ec to your computer and use it in GitHub Desktop.
Script for creating a Kafka Cluster on Confluent Cloud, enables Schema Registry, generates API keys, and emits configs for Java client
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
echo "Enter the name for your cluster" | |
read CLUSTER_NAME; | |
echo "Enter the cloud (aws, azure, gcp)" | |
read CLOUD; | |
echo "Enter the region" | |
read REGION; | |
echo "Enter the geo location (us for now)" | |
read GEO; | |
# This script requires jq (https://stedolan.github.io/jq/) | |
# It also assumes you have an existing account on Confluent Cloud | |
# and that you've logged in before running this script | |
echo "Creating the cluster" | |
CLUSTER_ID=$(confluent kafka cluster create $CLUSTER_NAME -o json --cloud $CLOUD --region $REGION | jq -r .id); | |
BOOTSTRAP=$(confluent kafka cluster describe $CLUSTER_ID -o json | jq -r .endpoint) | |
echo "Creating cluster credentials" | |
CLUSTER_CREDS=$(confluent api-key create --resource $CLUSTER_ID -o json); | |
USER_NAME=$(jq -r .key <<< ${CLUSTER_CREDS}); | |
confluent api-key use $USER_NAME --resource $CLUSTER_ID; | |
PASSWORD=$(jq -r .secret <<< ${CLUSTER_CREDS}); | |
echo "Enabling schema registry" | |
SR=$(confluent schema-registry cluster enable --cloud $CLOUD --geo $GEO -o json); | |
SR_ID=$(jq -r .id <<< ${SR}); | |
SR_URL=$(jq -r .endpoint_url <<< ${SR}); | |
SR_CREDS=$(confluent api-key create --resource $SR_ID -o json); | |
SR_USER=$(jq -r .key <<< ${SR_CREDS}); | |
SR_PW=$(jq -r .secret <<< ${SR_CREDS}); | |
#TODO get the client type at startup and customize the configs emitted below | |
#Another option would be to generate a Map<String, Object> | |
echo "Now generating configs needed for connection" | |
echo | |
echo | |
echo "bootstrap.servers=${BOOTSTRAP#SASL_SSL://}" | |
echo "sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username='${USER_NAME}' password='${PASSWORD}';" | |
echo "schema.registry.url=${SR_URL}" | |
echo "basic.auth.user.info=${SR_USER}:${SR_PW}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment