Created
May 3, 2020 15:19
-
-
Save dangtrinhnt/2f75490f46bf2425246a29832bf99871 to your computer and use it in GitHub Desktop.
Delete all Kong targets
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
#! /bin/bash | |
# Run this script inside a bastion instance | |
# $1: kong address and administration port, e.g., kong.dangtrinh.com:8001 | |
KONG_URL=$1 | |
# get all hosts of the services | |
latest_hosts=( $(curl ${KONG_URL}/services | jq -r '.["data"][] | .host') ) | |
# list all upstream names | |
all_upstreams=( $(curl ${KONG_URL}/upstreams | jq -r '.["data"][] | .name') ) | |
for upstream in ${all_upstreams[@]} | |
do | |
if [[ ! " ${latest_hosts[@]} " =~ " ${upstream} " ]]; then | |
echo "-Upstream ${upstream} is not the latest one." | |
targets=( $(curl ${KONG_URL}/upstreams/${upstream}/targets/all/ | jq -r '.["data"][] | .id') ) | |
for target in ${targets[@]} | |
do | |
echo "Deleting target $target of upstream $upstream" | |
curl -X DELETE ${KONG_URL}/upstreams/${upstream}/targets/${target} | |
done | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment