forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
credential-helper.sh
executable file
·82 lines (65 loc) · 1.6 KB
/
credential-helper.sh
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
# We try not to rely on there being anything installed on the
# local machine so although it would be nice to use `jq` here
# we don't do so. This means that a selenium build needs very
# little installed by the user
function emit_headers() {
echo "{\"headers\":{\"Authorization\":[\"Bearer ${1}\"]}}"
exit 0
}
function netrc_password() {
if [ ! -e "$HOME/.netrc" ]; then
return
fi
cat $HOME/.netrc | sed -e 's/#.*//' | awk -v host="$1" -v field=password '{
if ($1 == "machine") {
found = ($2 == host);
} else if (found && ($1 == field)) {
print $2;
exit
} else if (found && $1 == "machine") {
found = false
}
}'
}
function get() {
INPUT=$1
if [ -z "$(echo "$INPUT" | grep "gypsum.cluster")" ]; then
exit 0
fi
if [ -n "$GITHUB_TOKEN" ]; then
emit_headers "$GITHUB_TOKEN"
fi
if [ -n "$ENGFLOW_GITHUB_TOKEN" ]; then
emit_headers "${ENGFLOW_GITHUB_TOKEN}"
fi
NETRC="$(netrc_password github.com)"
if [ -n "${NETRC}" ]; then
emit_headers "${NETRC}"
fi
KEYCHAIN="$(security find-generic-password -a selenium -s 'Selenium EngFlow' -w )" 2>/dev/null
if [ -n "$KEYCHAIN" ]; then
emit_headers "${KEYCHAIN}"
fi
echo "{\"headers\":{}}"
exit 0
}
function set() {
security add-generic-password -a selenium -s 'Selenium EngFlow' -w "$1"
exit 0
}
cmd=$1
case $cmd in
"get")
get "$(</dev/stdin)"
;;
"set")
set "$(</dev/stdin)"
;;
"test")
get '{"uri":"https://gypsum.cluster.engflow.com/google.devtools.build.v1.PublishBuildEvent"}'
;;
*)
exit 1
;;
esac