improve how scripts check for gcloud auth

This commit is contained in:
Ryan Richard
2024-11-15 09:40:22 -08:00
parent 9446262246
commit e1464c379c
8 changed files with 34 additions and 18 deletions

View File

@@ -23,11 +23,10 @@ if ! command -v gcloud &> /dev/null; then
echo "Please install the gcloud CLI"
exit 1
fi
if [[ -z "$(gcloud config list account --format "value(core.account)")" ]]; then
echo "Please run \`gcloud auth login\`"
if ! gcloud auth print-access-token &>/dev/null; then
echo "Please run \`gcloud auth login\` and try again."
exit 1
fi
if [[ -z "${PINNIPED_GCP_PROJECT:-}" ]]; then
echo "PINNIPED_GCP_PROJECT env var must be set"
exit 1

View File

@@ -19,7 +19,7 @@ function set_pipeline() {
"$ROOT_DIR"/hack/setup-fly.sh
# Ensure that the user is authenticated with gcloud.
if [[ -z "$(gcloud config list account --format "value(core.account)")" ]]; then
if ! gcloud auth print-access-token &>/dev/null; then
echo "Please run \`gcloud auth login\` and try again."
exit 1
fi

View File

@@ -6,8 +6,8 @@
# To be run before local integration tests.
# From the pinniped repo:
# hack/prepare-for-integration-tests.sh --get-active-directory-vars "../pinniped-ci-branch/hack/get-aws-ad-env-vars.sh"
if [[ -z "$(gcloud config list account --format "value(core.account)")" ]]; then
echo "Please run \`gcloud auth login\`"
if ! gcloud auth print-access-token &>/dev/null; then
echo "Please run \`gcloud auth login\` and try again."
exit 1
fi

View File

@@ -6,8 +6,8 @@
# To be run before local integration tests.
# From the pinniped repo:
# hack/prepare-for-integration-tests.sh --get-github-vars "../pinniped-ci-branch/hack/get-github-env-vars.sh"
if [[ -z "$(gcloud config list account --format "value(core.account)")" ]]; then
echo "Please run \`gcloud auth login\`"
if ! gcloud auth print-access-token &>/dev/null; then
echo "Please run \`gcloud auth login\` and try again."
exit 1
fi

View File

@@ -5,7 +5,7 @@
set -euo pipefail
# Require two env vars.
# Require env vars.
if [[ -z "${GITHUB_CLIENT_ID:-}" ]]; then
echo "GITHUB_CLIENT_ID env var must be set"
exit 1
@@ -14,7 +14,6 @@ if [[ -z "${GITHUB_CLIENT_SECRET:-}" ]]; then
echo "GITHUB_CLIENT_SECRET env var must be set"
exit 1
fi
if [[ -z "${PINNIPED_GCP_PROJECT:-}" ]]; then
echo "PINNIPED_GCP_PROJECT env var must be set"
exit 1
@@ -29,8 +28,8 @@ if ! command -v yq &>/dev/null; then
echo "Please install the yq CLI"
exit
fi
if [[ -z "$(gcloud config list account --format "value(core.account)")" ]]; then
echo "Please run \`gcloud auth login\`"
if ! gcloud auth print-access-token &>/dev/null; then
echo "Please run \`gcloud auth login\` and try again."
exit 1
fi

View File

@@ -31,8 +31,14 @@ if ! command -v terraform &>/dev/null; then
echo "Please install the terraform CLI"
exit
fi
if [[ -z "$(gcloud config list account --format "value(core.account)")" ]]; then
echo "Please run \`gcloud auth login\`"
# This is needed for running gcloud commands.
if ! gcloud auth print-access-token &>/dev/null; then
echo "Please run \`gcloud auth login\` and try again."
exit 1
fi
# This is needed for running terraform commands.
if ! gcloud auth application-default print-access-token --quiet &>/dev/null; then
echo "Please run \`gcloud auth application-default login\` and try again."
exit 1
fi

View File

@@ -36,8 +36,14 @@ if ! command -v terraform &>/dev/null; then
echo "Please install the terraform CLI"
exit
fi
if [[ -z "$(gcloud config list account --format "value(core.account)")" ]]; then
echo "Please run \`gcloud auth login\`"
# This is needed for running gcloud commands.
if ! gcloud auth print-access-token &>/dev/null; then
echo "Please run \`gcloud auth login\` and try again."
exit 1
fi
# This is needed for running terraform commands.
if ! gcloud auth application-default print-access-token --quiet &>/dev/null; then
echo "Please run \`gcloud auth application-default login\` and try again."
exit 1
fi

View File

@@ -36,8 +36,14 @@ if ! command -v terraform &>/dev/null; then
echo "Please install the terraform CLI"
exit
fi
if [[ -z "$(gcloud config list account --format "value(core.account)")" ]]; then
echo "Please run \`gcloud auth login\`"
# This is needed for running gcloud commands.
if ! gcloud auth print-access-token &>/dev/null; then
echo "Please run \`gcloud auth login\` and try again."
exit 1
fi
# This is needed for running terraform commands.
if ! gcloud auth application-default print-access-token --quiet &>/dev/null; then
echo "Please run \`gcloud auth application-default login\` and try again."
exit 1
fi