Skip to content

Commit f76a893

Browse files
authored
[bazel] Use a credential helper (#12018)
1 parent bcd0c31 commit f76a893

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

.bazelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,6 @@ test:remote --test_tag_filters=-edge,-safari,-remote
119119
build:remote --action_env=HOME=/home/dev
120120
build:remote --action_env=PATH=/bin:/usr/bin:/usr/local/bin
121121
test:remote --test_env=HOME=/home/dev
122+
123+
# Make sure we sniff credentials properly
124+
build:remote --experimental_credential_helper=%workspace%/scripts/credential-helper.sh

scripts/credential-helper.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
3+
# We try not to rely on there being anything installed on the
4+
# local machine so although it would be nice to use `jq` here
5+
# we don't do so. This means that a selenium build needs very
6+
# little installed by the user
7+
8+
function emit_headers() {
9+
echo "{\"headers\":{\"Authorization\":[\"Bearer ${1}\"]}}"
10+
exit 0
11+
}
12+
13+
function get() {
14+
INPUT=$1
15+
16+
if [ -z "$(echo "$INPUT" | grep "gypsum.cluster")" ]; then
17+
exit 0
18+
fi
19+
20+
if [ -n "$GITHUB_TOKEN" ]; then
21+
emit_headers "$GITHUB_TOKEN"
22+
fi
23+
24+
if [ -n "$ENGFLOW_GITHUB_TOKEN" ]; then
25+
emit_headers "${ENGFLOW_GITHUB_TOKEN}"
26+
fi
27+
28+
KEYCHAIN="$(security find-generic-password -a selenium -s 'Selenium EngFlow' -w )"
29+
if [ -n "$KEYCHAIN" ]; then
30+
emit_headers "${KEYCHAIN}"
31+
fi
32+
33+
"{\"headers\":{}"
34+
exit 0
35+
}
36+
37+
function set() {
38+
security add-generic-password -a selenium -s 'Selenium EngFlow' -w "$1"
39+
exit 0
40+
}
41+
42+
cmd=$1
43+
44+
case $cmd in
45+
"get")
46+
get "$(</dev/stdin)"
47+
;;
48+
49+
"set")
50+
set "$(</dev/stdin)"
51+
;;
52+
53+
"test")
54+
get '{"uri":"https://gypsum.cluster.engflow.com/google.devtools.build.v1.PublishBuildEvent"}'
55+
;;
56+
57+
*)
58+
exit 1
59+
;;
60+
esac

0 commit comments

Comments
 (0)