Skip to content

Instantly share code, notes, and snippets.

@balcsida
Created December 23, 2020 13:42
Show Gist options
  • Save balcsida/d488fd35ba64b218738e07daa73b464c to your computer and use it in GitHub Desktop.
Save balcsida/d488fd35ba64b218738e07daa73b464c to your computer and use it in GitHub Desktop.
#!/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