You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: deploy/setup-secret.sh
+23-7
Original file line number
Diff line number
Diff line change
@@ -28,17 +28,33 @@ while getopts "p:" opt; do
28
28
esac
29
29
done
30
30
31
+
functiondownload_existing_key() {
32
+
# Download a valid key created within the past two weeks.
33
+
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)")
34
+
whileread -r KEY_ID
35
+
do
36
+
if gsutil cp gs://${BUCKET_ID}/${KEY_ID}.json ${KEY_FILE};then
37
+
echo"Downloaded existing key to ${KEY_FILE}"
38
+
return 0
39
+
fi
40
+
done<<<"$KEY_IDS"
41
+
return 1
42
+
}
31
43
32
-
# create a new valid key
33
-
KEY_ID=$(gcloud iam service-accounts keys list --iam-account=metrics-writer@k8s-skaffold.iam.gserviceaccount.com --project=k8s-skaffold --managed-by=user --filter="validAfterTime.date('%Y-%m-%d', Z) = `date +%F`" --format="value(name)" --limit=1)
34
-
if [ -z"$KEY_ID" ];then
44
+
functionupload_new_key() {
45
+
echo"Creating new service account key..."
35
46
gcloud iam service-accounts keys create ${KEY_FILE} --iam-account=metrics-writer@${PROJECT_ID}.iam.gserviceaccount.com --project=${PROJECT_ID}
36
47
retVal=$?
37
48
if [ $retVal-ne 0 ];then
38
49
echo"No key created."
39
-
exit 1
50
+
return 1
40
51
fi
52
+
echo"New service account key created."
41
53
KEY_ID=$(gcloud iam service-accounts keys list --iam-account=metrics-writer@k8s-skaffold.iam.gserviceaccount.com --project=k8s-skaffold --managed-by=user --filter="validAfterTime.date('%Y-%m-%d', Z) = `date +%F`" --format="value(name)" --limit=1)
0 commit comments