Skip to content

Instantly share code, notes, and snippets.

@bb01100100
Last active March 30, 2021 01:40
Show Gist options
  • Save bb01100100/b1e4a4fde14c7a162398541e19559d6d to your computer and use it in GitHub Desktop.
Save bb01100100/b1e4a4fde14c7a162398541e19559d6d to your computer and use it in GitHub Desktop.
Simplify repetitive curl args on Confluent Platform ansible deployed components
#!/usr/bin/env bash
# Author: Kel Graham
# Date: 2021-03-30
# Purpose:
# This script wraps curl with caroot, cert and key files obtained from the standard
# /var/ssl/private folder used by cp-ansible for deployed Confluent Platform components.
# The idea is to allow you to get on with hitting the Schema Registry REST endpoing
# without faffing around providing repetitive cert args.
# Does some super basic checks if we are registering Schemas on SR and provides the
# correct content type if there is a POST detected.
ARGS="$@"
BASE=$(basename /var/ssl/private/*.key|cut -d. -f1)
CERTS_PATH="/var/ssl/private"
isSR=0
isPOST=0
echo "Confluent Platform curl hurler v0.1" > /dev/stderr
for a in $ARGS; do
if [[ "$a" =~ .*/subjects/.*versions ]]; then
echo " ...detected Schema Registry operation" > /dev/stderr
isSR=1
fi
if [[ "$a" =~ -X.*POST ]]; then
echo " ...detected POST operation" > /dev/stderr
isPOST=1
fi
done
if [ $isSR == 1 ] & [ $isPOST == 1 ]; then
ARGS="${ARGS} -H 'Content-Type: application/vnd.schemaregistry.v1+json'"
ARGS="${ARGS} -H 'Accept: application/json' "
else
ARGS="${ARGS} -H 'Content-Type: application/json' "
fi
ARGS=" --cacert ${CERTS_PATH}/ca.crt \
--cert ${CERTS_PATH}/${BASE}.crt \
--key ${CERTS_PATH}/${BASE}.key \
${ARGS}"
echo "" > /dev/stderr
eval "curl $ARGS"
echo "" > /dev/stderr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment