github.com/arunkumar7540/cli@v6.45.0+incompatible/bin/cleanup-integration (about) 1 #!/usr/bin/env bash 2 3 set -e 4 5 xargs_func () { 6 if [[ $(uname) == "Darwin" ]]; then 7 xargs -n 1 -P 15 $@ 8 else 9 xargs -n 1 -P 15 -r $@ 10 fi 11 } 12 13 CF_API=${CF_INT_API:-"api.bosh-lite.com"} 14 export CF_USERNAME=${CF_INT_USERNAME:-"admin"} 15 export CF_PASSWORD=${CF_INT_PASSWORD:-"admin"} 16 17 export CF_CLI_EXPERIMENTAL=true 18 export CF_DIAL_TIMEOUT=15 19 20 if [[ -z $SKIP_SSL_VALIDATION || $SKIP_SSL_VALIDATION == "true" ]]; then 21 cf api $CF_API --skip-ssl-validation 22 else 23 cf api $CF_API 24 fi 25 26 cf auth 27 28 # we don't want the pipeline job to fail because there's a high chance of 29 # failure when running commands in parallel 30 set +e 31 32 cf create-org temp-org 33 cf target -o temp-org 34 35 cf domains | egrep -i ^\(sub.\)?integration- | cut -d " " -f1 | xargs_func cf delete-shared-domain -f 36 37 # This is required for older stacks where the delete-security-group API call was not implemented recursively by the CC. 38 if [[ $1 == "unbind-first" ]]; then 39 cf security-groups | grep -i "integration-sec-group" | grep -v \<all\>| grep -i staging | awk '{print $2 " " $3 " " $4}' | uniq - | xargs -n 3 -P 15 -r cf unbind-security-group --lifecycle staging 40 cf security-groups | grep -i "integration-sec-group" | grep -v \<all\>| grep -i staging | awk '{print $1 " " $2 " " $3}' | uniq - | xargs -n 3 -P 15 -r cf unbind-security-group --lifecycle staging 41 cf security-groups | grep -i "integration-sec-group" | grep -v \<all\>| grep -i running | awk '{print $2 " " $3 " " $4}' | uniq - | xargs -n 3 -P 15 -r cf unbind-security-group --lifecycle running 42 cf security-groups | grep -i "integration-sec-group" | grep -v \<all\>| grep -i running | awk '{print $1 " " $2 " " $3}' | uniq - | xargs -n 3 -P 15 -r cf unbind-security-group --lifecycle running 43 fi 44 cf security-groups | grep -i "integration-sec-group" | awk '{print $2}' | xargs_func cf delete-security-group -f 45 46 cf isolation-segments | grep -i ^integration-isolation-segment | xargs_func cf delete-isolation-segment -f 47 48 cf service-brokers | grep -i -e ^integration-service-broker- -e CATS- | awk '{print $1}' | xargs_func cf delete-service-broker -f 49 cf quotas | grep -i -e ^integration-quota -e CATS- | awk '{print $1}' | xargs_func cf delete-quota -f 50 cf orgs | grep -i -e ^integration-org -e CATS- | xargs_func cf delete-org -f 51 52 cf delete-org -f temp-org 53 54 if [[ $(cf version) == *"version 6"* ]]; then 55 for stack in $(cf stacks | tail -n +5 | awk '{print $1}'); do 56 cf buildpacks | \ 57 grep -i ^integration-buildpack | \ 58 grep -i -e \\s${stack} | \ 59 awk '{print $1}' | \ 60 xargs_func cf delete-buildpack -f -s $stack 61 62 # Delete stack if stack happens to be integration stack 63 if [[ $stack == INTEGRATION-STACK* ]]; then 64 echo Deleting $stack 65 cf curl -X DELETE /v2/stacks/$(cf stack --guid $stack) 66 fi 67 done 68 cf buildpacks | grep -i -e ^integration-buildpack | awk '{print $1}' | xargs_func cf delete-buildpack -f 69 else 70 for stack in $(cf stacks | tail -n +4 | awk '{print $1}'); do 71 cf buildpacks | \ 72 grep -i integration-buildpack | \ 73 grep -i -e \\s${stack} | \ 74 awk '{print $2}' | \ 75 xargs_func cf delete-buildpack -f -s $stack 76 77 # Delete stack if stack happens to be integration stack 78 if [[ $stack == INTEGRATION-STACK* ]]; then 79 echo Deleting $stack 80 cf curl -X DELETE /v2/stacks/$(cf stack --guid $stack) 81 fi 82 done 83 cf buildpacks | grep -i -e integration-buildpack | awk '{print $2}' | xargs_func cf delete-buildpack -f 84 fi 85 86 CF_USERS=$(cf curl /v2/users | grep total_results | grep -o '[0-9]\+') 87 USER_PAGES=$(( $CF_USERS / 50 + 1)) 88 89 for ((i=1; i<=${USER_PAGES}; i++)) ; do 90 cf curl "/v2/users?results-per-page=50&page=${i}" | \ 91 jq -r .resources[].entity.username | \ 92 grep -i -e ^integration-user -e CATS- | \ 93 xargs_func cf delete-user -f || echo 94 done 95