github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+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_API:-"api.bosh-lite.com"}
    14  CF_USERNAME=${CF_USERNAME:-"admin"}
    15  CF_PASSWORD=${CF_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 $CF_USERNAME $CF_PASSWORD
    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 orgs | grep -i -e ^integration-org -e CATS- | xargs_func cf delete-org -f
    33  cf orgs | grep -i -e ^integration-org -e CATS- | xargs_func cf delete-org -f
    34  cf isolation-segments | grep -i ^integration-isolation-segment | xargs_func cf delete-isolation-segment -f
    35  cf service-brokers | grep -i -e ^integration-service-broker- -e CATS- | awk '{print $1}' | xargs_func cf delete-service-broker -f
    36  
    37  cf quotas | grep -i -e ^integration-quota -e CATS- | cut -d " " -f1 | xargs_func cf delete-quota -f
    38  
    39  cf create-org temp-org
    40  cf target -o temp-org
    41  cf domains | egrep -i ^\(sub.\)?integration- | cut -d " " -f1 | xargs_func cf delete-shared-domain -f
    42  
    43  cf security-groups | grep -i "^#.* integration-sec-group" | awk '{print $2}' | xargs_func cf delete-security-group -f
    44  
    45  cf delete-org -f temp-org
    46  
    47  CF_USERS=$(cf curl /v2/users | grep total_results | grep -o '[0-9]\+')
    48  USER_PAGES=$(( $CF_USERS / 50 + 1))
    49  
    50  for ((i=1; i<=${USER_PAGES}; i++)) ; do
    51    cf curl "/v2/users?results-per-page=50&page=${i}" | \
    52    jq -r .resources[].entity.username | \
    53    grep -i -e ^integration-user -e CATS- | \
    54    xargs_func cf delete-user -f || echo
    55  done
    56