Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.

Commit 772c2a2

Browse files
ci: switch to secret manager for sample/integration tests (#81)
This PR was generated using Autosynth. 🌈 Synth log will be available here: https://source.cloud.google.com/results/invocations/2c593734-539a-435d-8a04-27f04c90082f/targets - [ ] To automatically regenerate this PR, check this box. Source-Link: googleapis/synthtool@c4f3059 Source-Link: googleapis/synthtool@6eb80fa Source-Link: googleapis/synthtool@6d3eed6 Source-Link: googleapis/synthtool@d1addcd
1 parent 60814f8 commit 772c2a2

File tree

8 files changed

+67
-38
lines changed

8 files changed

+67
-38
lines changed

.kokoro/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ retry_with_backoff 3 10 \
3939

4040
# if GOOGLE_APPLICATION_CREDIENTIALS is specified as a relative path prepend Kokoro root directory onto it
4141
if [[ ! -z "${GOOGLE_APPLICATION_CREDENTIALS}" && "${GOOGLE_APPLICATION_CREDENTIALS}" != /* ]]; then
42-
export GOOGLE_APPLICATION_CREDENTIALS=$(realpath ${KOKORO_ROOT}/src/${GOOGLE_APPLICATION_CREDENTIALS})
42+
export GOOGLE_APPLICATION_CREDENTIALS=$(realpath ${KOKORO_GFILE_DIR}/${GOOGLE_APPLICATION_CREDENTIALS})
4343
fi
4444

4545
RETURN_CODE=0

.kokoro/nightly/integration.cfg

+4-8
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,10 @@ env_vars: {
2828

2929
env_vars: {
3030
key: "GOOGLE_APPLICATION_CREDENTIALS"
31-
value: "keystore/73713_java_it_service_account"
31+
value: "secret_manager/java-it-service-account"
3232
}
3333

34-
before_action {
35-
fetch_keystore {
36-
keystore_resource {
37-
keystore_config_id: 73713
38-
keyname: "java_it_service_account"
39-
}
40-
}
34+
env_vars: {
35+
key: "SECRET_MANAGER_KEYS"
36+
value: "java-it-service-account"
4137
}

.kokoro/nightly/samples.cfg

+6-10
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,15 @@ env_vars: {
2424

2525
env_vars: {
2626
key: "GOOGLE_APPLICATION_CREDENTIALS"
27-
value: "keystore/73713_java_it_service_account"
27+
value: "secret_manager/java-docs-samples-service-account"
2828
}
2929

3030
env_vars: {
31-
key: "ENABLE_BUILD_COP"
32-
value: "true"
31+
key: "SECRET_MANAGER_KEYS"
32+
value: "java-docs-samples-service-account"
3333
}
3434

35-
before_action {
36-
fetch_keystore {
37-
keystore_resource {
38-
keystore_config_id: 73713
39-
keyname: "java_it_service_account"
40-
}
41-
}
35+
env_vars: {
36+
key: "ENABLE_BUILD_COP"
37+
value: "true"
4238
}

.kokoro/populate-secrets.sh

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

.kokoro/presubmit/integration.cfg

+4-8
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,10 @@ env_vars: {
2424

2525
env_vars: {
2626
key: "GOOGLE_APPLICATION_CREDENTIALS"
27-
value: "keystore/73713_java_it_service_account"
27+
value: "secret_manager/java-it-service-account"
2828
}
2929

30-
before_action {
31-
fetch_keystore {
32-
keystore_resource {
33-
keystore_config_id: 73713
34-
keyname: "java_it_service_account"
35-
}
36-
}
30+
env_vars: {
31+
key: "SECRET_MANAGER_KEYS"
32+
value: "java-it-service-account"
3733
}

.kokoro/presubmit/samples.cfg

+5-9
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,10 @@ env_vars: {
2424

2525
env_vars: {
2626
key: "GOOGLE_APPLICATION_CREDENTIALS"
27-
value: "keystore/73713_java_it_service_account"
27+
value: "secret_manager/java-docs-samples-service-account"
2828
}
2929

30-
before_action {
31-
fetch_keystore {
32-
keystore_resource {
33-
keystore_config_id: 73713
34-
keyname: "java_it_service_account"
35-
}
36-
}
37-
}
30+
env_vars: {
31+
key: "SECRET_MANAGER_KEYS"
32+
value: "java-docs-samples-service-account"
33+
}

.kokoro/trampoline.sh

+2
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ function cleanup() {
2121
echo "cleanup";
2222
}
2323
trap cleanup EXIT
24+
25+
$(dirname $0)/populate-secrets.sh # Secret Manager secrets.
2426
python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py"

synth.metadata

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
"git": {
55
"name": ".",
66
"remote": "https://github.com/googleapis/java-shared-dependencies.git",
7-
"sha": "d5d50eed4fe5a0142b2bf1c9fb6f1064d6205cf8"
7+
"sha": "60814f8f3dd42e6111cab2276f7cd74c4b32d434"
88
}
99
},
1010
{
1111
"git": {
1212
"name": "synthtool",
1313
"remote": "https://github.com/googleapis/synthtool.git",
14-
"sha": "987270824bd26f6a8c716d5e2022057b8ae7b26e"
14+
"sha": "c4f3059c27591eb24d6942a0e357ec94c80459f2"
1515
}
1616
}
1717
]

0 commit comments

Comments
 (0)