Skip to content

Commit fc66946

Browse files
log in using GOOGLE_*_CREDENTIALS if present; log more (#1137)
Backport of #1136 Signed-off-by: Stephen Compall <[email protected]>
1 parent 83ec825 commit fc66946

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

cluster/pulumi/canton-network/src/bigQuery.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,25 @@ function databaseCommandBracket(postgres: CloudPostgres) {
337337
TMP_SQL_FILE="$(mktemp tmp_pub_rep_slots_XXXXXXXXXX.sql --tmpdir)"
338338
GCS_URI="gs://$TMP_BUCKET/$(basename "$TMP_SQL_FILE")"
339339
340+
if [ -s "$GOOGLE_APPLICATION_CREDENTIALS" ]; then
341+
echo "Using $GOOGLE_APPLICATION_CREDENTIALS for authentication"
342+
gcloud auth activate-service-account --key-file="$GOOGLE_APPLICATION_CREDENTIALS"
343+
elif [ -n "$GOOGLE_CREDENTIALS" ]; then
344+
echo "Using GOOGLE_CREDENTIALS for authentication"
345+
echo "$GOOGLE_CREDENTIALS" | gcloud auth activate-service-account --key-file=-
346+
else
347+
echo 'No GCP credentials found, using default'
348+
fi
349+
echo 'Current gcloud login:'
350+
gcloud auth list --format=config
351+
340352
# create temporary bucket
353+
echo "Creating temporary bucket $TMP_BUCKET"
341354
gsutil mb --pap enforced -p "${privateNetwork.project}" \
342355
-l "${cloudsdkComputeRegion()}" "gs://$TMP_BUCKET"
343356
344357
# grant DB service account access to the bucket
358+
echo "Granting CloudSQL DB access to $TMP_BUCKET"
345359
gsutil iam ch "serviceAccount:${postgres.databaseInstance.serviceAccountEmailAddress}:roles/storage.objectAdmin" \
346360
"gs://$TMP_BUCKET"
347361
@@ -350,16 +364,16 @@ function databaseCommandBracket(postgres: CloudPostgres) {
350364
footer: pulumi.interpolate`
351365
EOT
352366
353-
# upload SQL to temporary bucket
367+
echo 'Uploading SQL to temporary bucket'
354368
gsutil cp "$TMP_SQL_FILE" "$GCS_URI"
355369
356-
# then import into Cloud SQL
370+
echo 'Importing into CloudSQL'
357371
gcloud sql import sql ${postgres.databaseInstance.name} "$GCS_URI" \
358372
--database="${scanAppDatabaseName(postgres)}" \
359373
--user="${postgres.user.name}" \
360374
--quiet
361375
362-
# cleanup: remove the file from GCS, delete the bucket, remove the local file
376+
echo 'Cleaning up temporary GCS object and bucket'
363377
gsutil rm "$GCS_URI"
364378
gsutil rb "gs://$TMP_BUCKET"
365379
rm "$TMP_SQL_FILE"

0 commit comments

Comments
 (0)