# works for bash and zsh
script_dir=$(readlink -f $(dirname "${BASH_SOURCE[0]:-${(%):-%x}}"))

# TODO should use `docker secret` instead of this file
# https://docs.docker.com/engine/swarm/secrets/#defining-and-using-secrets-in-compose-files
export MAPBOX_TOKEN=$(vault read -field=token secret/map_box)
export SAMSARA_API_KEY=$(vault read -field=key secret/samsara)
export VAULT_SP_KEY="$(vault read -field=key secret/fleetdash_gateway_cert)"
export VAULT_JWT_SECRET="$(vault read -field=secret secret/fleetdash/jwt_secret)"
export FLEETDASH_GATEWAY__SLACK_CLIENT__WEBHOOK_URL=$(vault read -field=value secret/fleetdash/slack-feedback-webhook)

export VUE_APP_MAPBOX_TOKEN=${MAPBOX_TOKEN:-$(vault read -field=token secret/map_box)}
export VUE_APP_SAMSARA_API_KEY=${SAMSARA_API_KEY:-$(vault read -field=key secret/samsara)}
export CYPRESS_JWT_TESTING_TOKEN="$(vault read -field=token secret/fleetdash/jwt_testing_token)"
export CYPRESS_VUE_APP_MAPBOX_TOKEN="${VUE_APP_MAPBOX_TOKEN}"

echo ${VAULT_SP_KEY} > $script_dir/../fleetdash_gateway/fleetdash_gateway/auth/sp-key.key
