blob: 21f6d2a26d909ea199b3385eced208e30b4c54f2 [file] [log] [blame]
release-please[bot]fd2965c2021-08-11 17:00:21 +00001#!/bin/bash
2
3# Copyright 2015 Google Inc. All rights reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
18ROOT=$( dirname "$DIR" )
19
20# Work from the project root.
21cd $ROOT
22
23# Prevent it from overriding files.
24# We recommend that sample authors use their own service account files and cloud project.
25# In that case, they are supposed to prepare these files by themselves.
26if [[ -f "testing/test-env.sh" ]] || \
27 [[ -f "testing/service-account.json" ]] || \
28 [[ -f "testing/client-secrets.json" ]]; then
29 echo "One or more target files exist, aborting."
30 exit 1
31fi
32
33# Use SECRET_MANAGER_PROJECT if set, fallback to cloud-devrel-kokoro-resources.
34PROJECT_ID="${SECRET_MANAGER_PROJECT:-cloud-devrel-kokoro-resources}"
35
36gcloud secrets versions access latest --secret="python-docs-samples-test-env" \
37 --project="${PROJECT_ID}" \
38 > testing/test-env.sh
39gcloud secrets versions access latest \
40 --secret="python-docs-samples-service-account" \
41 --project="${PROJECT_ID}" \
42 > testing/service-account.json
43gcloud secrets versions access latest \
44 --secret="python-docs-samples-client-secrets" \
45 --project="${PROJECT_ID}" \
46 > testing/client-secrets.json