---
platform: linux
image_resource:
  type: docker-image
  source:
    repository: governmentpaas/cf-uaac
inputs:
  - name: paas-cf
  - name: cf-secrets
  - name: cf-manifest
  - name: admin-creds
  - name: bosh-CA
run:
  path: sh
  args:
    - -e
    - -c
    - |
      NAME=$(cat admin-creds/username)
      if [ "${ENABLE_ADMIN_USER_CREATION}" == "false" ]; then
        echo "Temporary user creation is disabled (ENABLE_ADMIN_USER_CREATION=${ENABLE_ADMIN_USER_CREATION}). Skipping."
        exit 0
      fi
      ./paas-cf/concourse/scripts/import_bosh_ca.sh

      VAL_FROM_YAML=$(pwd)/paas-cf/concourse/scripts/val_from_yaml.rb
      UAA_ADMIN_CLIENT_PASS=$($VAL_FROM_YAML secrets.uaa_admin_client_secret cf-secrets/cf-secrets.yml)
      UAA_ENDPOINT=$($VAL_FROM_YAML properties.uaa.url cf-manifest/cf-manifest.yml)

      echo "Removing user ${NAME}"
      uaac target "${UAA_ENDPOINT}"
      uaac token client get admin -s "${UAA_ADMIN_CLIENT_PASS}"

      uaac user delete "${NAME}"

---
platform: linux
image_resource:
  type: docker-image
  source:
    repository: governmentpaas/cf-cli
inputs:
  - name: paas-cf
  - name: cf-secrets
  - name: cf-manifest
  - name: admin-creds
  - name: bosh-CA
run:
  path: sh
  args:
    - -e
    - -u
    - -c
    - |
      NAME=$(cat admin-creds/username)
      if [ "${ENABLE_ADMIN_USER_CREATION:-}" == "false" ]; then
        echo "Temporary user creation is disabled (ENABLE_ADMIN_USER_CREATION=${ENABLE_ADMIN_USER_CREATION}). Skipping."
        exit 0
      fi
      ./paas-cf/concourse/scripts/import_bosh_ca.sh

      VAL_FROM_YAML=$(pwd)/paas-cf/concourse/scripts/val_from_yaml.rb
      CF_ADMIN=admin
      CF_PASS=$($VAL_FROM_YAML secrets.uaa_admin_password cf-secrets/cf-secrets.yml)
      API_ENDPOINT=$($VAL_FROM_YAML properties.cc.srv_api_uri cf-manifest/cf-manifest.yml)

      echo "Removing user ${NAME}"

      echo | cf login -a ${API_ENDPOINT} -u ${CF_ADMIN} -p ${CF_PASS}

      cf delete-user "${NAME}" -f

Use `cf remove-user` to remove user from test jobs
Use `cf remove-user` to remove user from test jobs

Here we rework the common delete_admin.yml task to use cf(1) rather
than uaac(1) when deleting the user, so that the deletion is progated to
the cloudcontroller.

There is still an asymetry here in that we use uaac to make the testing
admin user, as you cannot create an admin with `cf create-user`.
