Skip to content

Commit

Permalink
chore(nodejs_templates): add script logging to node_library populate-…
Browse files Browse the repository at this point in the history
…secrets.sh (#618)

Co-authored-by: Benjamin E. Coe <[email protected]>
  • Loading branch information
BenWhitehead and bcoe authored Jun 11, 2020
1 parent fc0fce9 commit e703494
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions synthtool/gcp/templates/node_library/.kokoro/populate-secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@

set -eo pipefail

function now { date +"%Y-%m-%d %H:%M:%S" | tr -d '\n' ;}
function msg { println "$*" >&2 ;}
function println { printf '%s\n' "$(now) $*" ;}


# Populates requested secrets set in SECRET_MANAGER_KEYS from service account:
# kokoro-trampoline@cloud-devrel-kokoro-resources.iam.gserviceaccount.com
SECRET_LOCATION="${KOKORO_GFILE_DIR}/secret_manager"
msg "Creating folder on disk for secrets: ${SECRET_LOCATION}"
mkdir -p ${SECRET_LOCATION}
for key in $(echo ${SECRET_MANAGER_KEYS} | sed "s/,/ /g")
do
msg "Retrieving secret ${key}"
docker run --entrypoint=gcloud \
--volume=${KOKORO_GFILE_DIR}:${KOKORO_GFILE_DIR} \
gcr.io/google.com/cloudsdktool/cloud-sdk \
Expand All @@ -29,4 +36,9 @@ do
--project cloud-devrel-kokoro-resources \
--secret $key > \
"$SECRET_LOCATION/$key"
if [[ $? == 0 ]]; then
msg "Secret written to ${SECRET_LOCATION}/${key}"
else
msg "Error retrieving secret ${key}"
fi
done

0 comments on commit e703494

Please sign in to comment.