File: populate-secrets.sh

package info (click to toggle)
golang-google-api 0.61.0-6
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 209,156 kB
  • sloc: sh: 183; makefile: 22; python: 4
file content (33 lines) | stat: -rwxr-xr-x 1,252 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash

# Copyright 2021 Google LLC.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

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 \
        secrets versions access latest \
        --credential-file-override=${KOKORO_GFILE_DIR}/kokoro-trampoline.service-account.json \
        --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