...

Text file src/google.golang.org/api/internal/kokoro/populate-secrets.sh

Documentation: google.golang.org/api/internal/kokoro

     1#!/bin/bash
     2
     3# Copyright 2021 Google LLC.
     4# Use of this source code is governed by a BSD-style
     5# license that can be found in the LICENSE file.
     6
     7set -eo pipefail
     8
     9function now() { date +"%Y-%m-%d %H:%M:%S" | tr -d '\n'; }
    10function msg() { println "$*" >&2; }
    11function println() { printf '%s\n' "$(now) $*"; }
    12
    13# Populates requested secrets set in SECRET_MANAGER_KEYS from service account:
    14# kokoro-trampoline@cloud-devrel-kokoro-resources.iam.gserviceaccount.com
    15SECRET_LOCATION="${KOKORO_GFILE_DIR}/secret_manager"
    16msg "Creating folder on disk for secrets: ${SECRET_LOCATION}"
    17msg "Keys: ${SECRET_MANAGER_KEYS}"
    18mkdir -p ${SECRET_LOCATION}
    19for key in $(echo ${SECRET_MANAGER_KEYS} | sed "s/,/ /g"); do
    20    msg "Retrieving secret ${key}"
    21    docker run --entrypoint=gcloud \
    22        --volume=${KOKORO_GFILE_DIR}:${KOKORO_GFILE_DIR} \
    23        gcr.io/google.com/cloudsdktool/cloud-sdk \
    24        secrets versions access latest \
    25        --credential-file-override=${KOKORO_GFILE_DIR}/kokoro-trampoline.service-account.json \
    26        --project cloud-devrel-kokoro-resources \
    27        --secret ${key} > \
    28        "${SECRET_LOCATION}/${key}"
    29    if [[ $? == 0 ]]; then
    30        msg "Secret written to ${SECRET_LOCATION}/${key}"
    31    else
    32        msg "Error retrieving secret ${key}"
    33    fi
    34done

View as plain text