Skip to content

Commit

Permalink
fetch and set up secret for skaffold-metrics project
Browse files Browse the repository at this point in the history
  • Loading branch information
tejal29 committed Jun 29, 2021
1 parent 7b496d2 commit 5d7ae87
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions deploy/setup-secret.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
set -x
# set default project id
PROJECT_ID="k8s-skaffold"
METRICS_PROJECT_ID="skaffold-metrics"
KEY_FILE="./secrets/keys.json"
BUCKET_ID="k8s-skaffold-secrets"
LATEST_GCS_PATH="keys.json"
Expand All @@ -30,10 +31,10 @@ done

function download_existing_key() {
# Download a valid key created within the past two weeks.
KEY_IDS=$(gcloud iam service-accounts keys list --iam-account=metrics-writer@k8s-skaffold.iam.gserviceaccount.com --project=k8s-skaffold --managed-by=user --filter="validAfterTime>-P2W" --format="value(name)")
KEY_IDS=$(gcloud iam service-accounts keys list --iam-account=metrics-writer@${METRICS_PROJECT_ID}.iam.gserviceaccount.com --project=${METRICS_PROJECT_ID} --managed-by=user --format="value(name)")
while read -r KEY_ID
do
if gsutil cp gs://${BUCKET_ID}/${KEY_ID}.json ${KEY_FILE}; then
if gsutil cp gs://${BUCKET_ID}/${LATEST_GCS_PATH}.json ${KEY_FILE}; then
echo "Downloaded existing key to ${KEY_FILE}"
return 0
fi
Expand All @@ -43,7 +44,7 @@ function download_existing_key() {

function upload_new_key() {
echo "Creating new service account key..."
gcloud iam service-accounts keys create ${KEY_FILE} --iam-account=metrics-writer@${PROJECT_ID}.iam.gserviceaccount.com --project=${PROJECT_ID}
gcloud iam service-accounts keys create ${KEY_FILE} --iam-account=metrics-writer@${METRICS_PROJECT_ID}.iam.gserviceaccount.com --project=${METRICS_PROJECT_ID}
retVal=$?
if [ $retVal -ne 0 ]; then
echo "No key created."
Expand Down

0 comments on commit 5d7ae87

Please sign in to comment.