---
platform: linux
inputs:
  - name: paas-cf
  - name: bosh-CA
  - name: config
image_resource:
  type: docker-image
  source:
    repository: governmentpaas/cf-cli
    tag: 895cf6752c8ec64af05a3a735186b90acd3db65a
run:
  path: sh
  args:
    - -e
    - -u
    - -c
    - |
      ./paas-cf/concourse/scripts/import_bosh_ca.sh
      . ./config/config.sh
      if ! curl -I -f "${API_ENDPOINT}/info"; then
        echo "CF API unavailable. Skipping..."
        exit 0
      fi
      if ! echo | cf login -a "${API_ENDPOINT}" -u "${CF_ADMIN}" -p "${CF_PASS}"; then
        echo "Login failed.  Skipping..."
        exit 0
      fi
      cf target -o "${ORG}" -s "${SPACE}"
      if cf services | grep -q "${DB_NAME}"; then
        cf unbind-service "${BOUND_APP}" "${DB_NAME}" || true
        cf delete-service "${DB_NAME}" -f
      fi

---
platform: linux
inputs:
  - name: paas-cf
  - name: bosh-CA
  - name: config
image_resource:
  type: docker-image
  source:
    repository: governmentpaas/cf-cli
    tag: 895cf6752c8ec64af05a3a735186b90acd3db65a
run:
  path: sh
  args:
    - -e
    - -u
    - -c
    - |
      ./paas-cf/concourse/scripts/import_bosh_ca.sh
      . ./config/config.sh
      if ! curl -I -f "${API_ENDPOINT}/info"; then
        echo "CF API unavailable. Skipping..."
        exit 0
      fi
      if ! echo | cf login -a "${API_ENDPOINT}" -u "${CF_ADMIN}" -p "${CF_PASS}"; then
        echo "Login failed.  Skipping..."
        exit 0
      fi
      if ! cf target -o "${ORG}" -s "${SPACE}"; then
        echo "${ORG}/${SPACE} space doesn't seem to exist. Skipping..."
        exit 0
      fi
      if cf services | grep -q "${DB_NAME}"; then
        cf unbind-service "${BOUND_APP}" "${DB_NAME}" || true
        cf delete-service "${DB_NAME}" -f
      fi

Handle space not existing in the database removal script.
Handle space not existing in the database removal script.

Otherwise, this script can sometimes erroneously fail if the space
doesn't exist or has already been deleted.
