Created
December 10, 2023 01:55
-
-
Save pkit/a98411d21ecc9293066f4579088187d1 to your computer and use it in GitHub Desktop.
ghcr.io credential helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
cmd="$1" | |
if [ "erase" = "$cmd" ]; then | |
cat - >/dev/null | |
exit 0 | |
fi | |
if [ "store" = "$cmd" ]; then | |
cat - >/dev/null | |
exit 0 | |
fi | |
if [ "get" != "$cmd" ]; then | |
exit 1 | |
fi | |
host="$(cat -)" | |
host="${host#https://}" | |
host="${host%/}" | |
if [ "$host" != "ghcr.io" ] && [ "$host" != "docker.pkg.github.com" ]; then | |
exit 1 | |
fi | |
token="$(gh config get -h github.com oauth_token)" | |
if [ -z "$token" ]; then | |
exit 1 | |
fi | |
printf '{"Username":"%s", "Secret":"%s"}\n' "$(gh api user -q '.login')" "$token" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment