Created
December 23, 2020 13:42
-
-
Save balcsida/d488fd35ba64b218738e07daa73b464c 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
#!/usr/bin/env bash | |
readonly INFRASTRUCTURE=liferay.cloud | |
readonly API_URL=https://api.${INFRASTRUCTURE} | |
readonly PROJECTS_URL=${API_URL}/projects | |
while getopts p:e: flag | |
do | |
case "${flag}" in | |
p) PROJECT_ID=${OPTARG};; | |
e) ENVIRONMENT=${OPTARG};; | |
esac | |
done | |
LCP_CONFIG_FILE=$HOME/.lcp | |
if [[ -f "$LCP_CONFIG_FILE" ]]; then | |
echo "$LCP_CONFIG_FILE exists" | |
else | |
echo "$LCP_CONFIG_FILE does not exist!" | |
exit 1 | |
fi | |
TOKEN=$(grep -A 2 "infrastructure=${INFRASTRUCTURE}" "$LCP_CONFIG_FILE" | awk -F "=" '/token/ {print $2}') | |
readarray -t SERVICES < <(curl "${PROJECTS_URL}/${PROJECT_ID}-${ENVIRONMENT}/services" \ | |
-X GET \ | |
-H "Authorization: Bearer ${TOKEN}" | jq --raw-output '.[].serviceId') | |
for serviceId in "${SERVICES[@]}"; do | |
echo "Deleting: $PROJECT_ID-$ENVIRONMENT-$serviceId" | |
curl "${PROJECTS_URL}/${PROJECT_ID}-${ENVIRONMENT}/services/${serviceId}" \ | |
-X DELETE \ | |
-H "Authorization: Bearer ${TOKEN}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment