Skip to content

Instantly share code, notes, and snippets.

@ram-pi
Created October 30, 2023 15:19
Show Gist options
  • Save ram-pi/5ee328bb09209062a08d05a21f7a6db6 to your computer and use it in GitHub Desktop.
Save ram-pi/5ee328bb09209062a08d05a21f7a6db6 to your computer and use it in GitHub Desktop.
Clear the Schema Registry of all the schemas.
#!/bin/bash
# ./sr_clean.sh https://myhost.confluent.cloud MY_KEY MY_SECRET ":."
echo "Schema Registry URL: $1"
echo "Subjects Prefix: $4"
SR_URL=$1
API_KEY=$2
API_SECRET=$3
PREFIX=$4
AUTH_TOKEN=`printf "${API_KEY}:${API_SECRET}" | base64`
echo "Schema Registry Authentication Token: $AUTH_TOKEN"
curl -s --request GET --url "${SR_URL}/contexts" \
--header "Authorization: Basic ${AUTH_TOKEN}" | jq '.[]' | sed 's/"//g' >contexts.txt
echo "Available contexts:"
cat contexts.txt
curl -s --request GET --url "${SR_URL}/subjects?subjectPrefix=$PREFIX" \
--header "Authorization: Basic ${AUTH_TOKEN}" | jq '.[]' | sed 's/"//g' >subjects.txt
echo "Subjects to delete:"
cat subjects.txt
if [ ! -s "subjects.txt" ]; then
echo "Nothing to delete..."
exit 1
fi
read -p "Are you sure you want to continue? (y/n) " answer
if [[ $answer == "y" || $answer == "Y" ]]; then
echo "Deleting..."
# continue with your code here
filename='subjects.txt'
while read line; do
# reading each line
echo "Deleting subject: $line"
curl --request DELETE -s --url "${SR_URL}/subjects/$line" --header "Authorization: Basic ${AUTH_TOKEN}"
curl --request DELETE -s --url "${SR_URL}/subjects/$line?permanent=true" --header "Authorization: Basic ${AUTH_TOKEN}"
done <$filename
else
echo "Exiting..."
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment