github.com/sleungcy-sap/cli@v7.1.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  if [[ -z $CF_INT_API ]]; then
    14    echo "\$CF_INT_API is unset! Did you run 'int'?"
    15  fi
    16  
    17  CF_API=${CF_INT_API:-"NO-BOSH-LITE-SET"}
    18  export CF_USERNAME=${CF_INT_USERNAME:-"admin"}
    19  export CF_PASSWORD=${CF_INT_PASSWORD:-"admin"}
    20  
    21  export CF_CLI_EXPERIMENTAL=true
    22  export CF_DIAL_TIMEOUT=15
    23  
    24  if [[ -z $SKIP_SSL_VALIDATION || $SKIP_SSL_VALIDATION == "true" ]]; then
    25    cf api $CF_API --skip-ssl-validation
    26  else
    27    cf api $CF_API
    28  fi
    29  
    30  cf auth
    31  
    32  # we don't want the pipeline job to fail because there's a high chance of
    33  # failure when running commands in parallel
    34  set +e
    35  
    36  cf create-org temp-org
    37  cf target -o temp-org
    38  
    39  cf domains | egrep -i ^\(sub.\)?integration- | cut -d " " -f1 | xargs_func cf delete-shared-domain -f
    40  
    41  # This is required for older stacks where the delete-security-group API call was not implemented recursively by the CC.
    42  if [[ $1 == "unbind-first" ]]; then
    43    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
    44    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
    45    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
    46    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
    47  fi
    48  cf security-groups | grep -i "integration-sec-group" | sed 's=^#[0-9]*==' | awk '{print $1}' | xargs_func cf delete-security-group -f
    49  
    50  cf isolation-segments | grep -i ^integration-isolation-segment | xargs_func cf delete-isolation-segment -f
    51  
    52  cf service-brokers | grep -i -e ^integration-service-broker- -e CATS- | awk '{print $1}' | xargs_func cf delete-service-broker -f
    53  cf quotas | grep -i -e ^integration-quota -e CATS- | awk '{print $1}' | xargs_func cf delete-quota -f
    54  cf orgs | grep -i -e ^integration-org -e CATS- | xargs_func cf delete-org -f
    55  
    56  cf delete-org -f temp-org
    57  
    58  cf buildpacks | awk '/INTEGRATION-BUILDPACK/ { if(NF >= 6) { printf("cf delete-buildpack -f %s -s %s\n", $2, $3); } else { printf("cf delete-buildpack -f %s\n", $2); }}' | bash
    59  
    60  for stack in $(cf stacks | awk '/INTEGRATION-STACK/ { print $1 }'); do
    61    echo Deleting $stack
    62    cf curl -X DELETE "/v3/stacks/$(cf stack --guid $stack)"
    63  done
    64  
    65  CF_USERS=$(cf curl /v3/users | grep total_results | grep -o '[0-9]\+')
    66  USER_PAGES=$(( $CF_USERS / 50 + 1))
    67  
    68  for ((i=1; i<=${USER_PAGES}; i++)) ; do
    69    cf curl "/v3/users?per_page=50&page=${i}" | \
    70    jq -r .resources[].username | \
    71    grep -i -e ^integration-user -e CATS- | \
    72    xargs_func cf delete-user -f || echo
    73  done
    74