Skip to content

Commit cf1926a

Browse files
committed
[bazel] Also read credentials from .netrc file
1 parent 5e04a80 commit cf1926a

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

scripts/credential-helper.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ function emit_headers() {
1010
exit 0
1111
}
1212

13+
function netrc_password() {
14+
if [ ! -e "$HOME/.netrc" ]; then
15+
return
16+
fi
17+
18+
cat $HOME/.netrc | sed -e 's/#.*//' | awk -v host="$1" -v field=password '{
19+
if ($1 == "machine") {
20+
found = ($2 == host);
21+
} else if (found && ($1 == field)) {
22+
print $2;
23+
exit
24+
} else if (found && $1 == "machine") {
25+
found = false
26+
}
27+
}'
28+
}
29+
1330
function get() {
1431
INPUT=$1
1532

@@ -25,7 +42,12 @@ function get() {
2542
emit_headers "${ENGFLOW_GITHUB_TOKEN}"
2643
fi
2744

28-
KEYCHAIN="$(security find-generic-password -a selenium -s 'Selenium EngFlow' -w )"
45+
NETRC="$(netrc_password github.com)"
46+
if [ -n "${NETRC}" ]; then
47+
emit_headers "${NETRC}"
48+
fi
49+
50+
KEYCHAIN="$(security find-generic-password -a selenium -s 'Selenium EngFlow' -w )" 2>/dev/null
2951
if [ -n "$KEYCHAIN" ]; then
3052
emit_headers "${KEYCHAIN}"
3153
fi

0 commit comments

Comments
 (0)