1*af546375SCole Faust#!/bin/bash 2*af546375SCole Faust# Copyright 2020 Google LLC. 3*af546375SCole Faust# 4*af546375SCole Faust# Licensed under the Apache License, Version 2.0 (the "License"); 5*af546375SCole Faust# you may not use this file except in compliance with the License. 6*af546375SCole Faust# You may obtain a copy of the License at 7*af546375SCole Faust# 8*af546375SCole Faust# http://www.apache.org/licenses/LICENSE-2.0 9*af546375SCole Faust# 10*af546375SCole Faust# Unless required by applicable law or agreed to in writing, software 11*af546375SCole Faust# distributed under the License is distributed on an "AS IS" BASIS, 12*af546375SCole Faust# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*af546375SCole Faust# See the License for the specific language governing permissions and 14*af546375SCole Faust# limitations under the License. 15*af546375SCole Faust 16*af546375SCole Faustset -eo pipefail 17*af546375SCole Faust 18*af546375SCole Faustfunction now { date +"%Y-%m-%d %H:%M:%S" | tr -d '\n' ;} 19*af546375SCole Faustfunction msg { println "$*" >&2 ;} 20*af546375SCole Faustfunction println { printf '%s\n' "$(now) $*" ;} 21*af546375SCole Faust 22*af546375SCole Faust 23*af546375SCole Faust# Populates requested secrets set in SECRET_MANAGER_KEYS from service account: 24*af546375SCole Faust# kokoro-trampoline@cloud-devrel-kokoro-resources.iam.gserviceaccount.com 25*af546375SCole FaustSECRET_LOCATION="${KOKORO_GFILE_DIR}/secret_manager" 26*af546375SCole Faustmsg "Creating folder on disk for secrets: ${SECRET_LOCATION}" 27*af546375SCole Faustmkdir -p ${SECRET_LOCATION} 28*af546375SCole Faustfor key in $(echo ${SECRET_MANAGER_KEYS} | sed "s/,/ /g") 29*af546375SCole Faustdo 30*af546375SCole Faust msg "Retrieving secret ${key}" 31*af546375SCole Faust docker run --entrypoint=gcloud \ 32*af546375SCole Faust --volume=${KOKORO_GFILE_DIR}:${KOKORO_GFILE_DIR} \ 33*af546375SCole Faust gcr.io/google.com/cloudsdktool/cloud-sdk \ 34*af546375SCole Faust secrets versions access latest \ 35*af546375SCole Faust --project cloud-devrel-kokoro-resources \ 36*af546375SCole Faust --secret ${key} > \ 37*af546375SCole Faust "${SECRET_LOCATION}/${key}" 38*af546375SCole Faust if [[ $? == 0 ]]; then 39*af546375SCole Faust msg "Secret written to ${SECRET_LOCATION}/${key}" 40*af546375SCole Faust else 41*af546375SCole Faust msg "Error retrieving secret ${key}" 42*af546375SCole Faust fi 43*af546375SCole Faustdone 44