feat: add git:auth-status to check netrc match

Adds `git:auth-status HOST [USERNAME] [PASSWORD]` which exits 0 when the
configured `.netrc` entry matches the requested state and 1 otherwise,
allowing external tooling to detect whether `git:auth` would change
anything without reading `$DOKKU_ROOT/.netrc` directly. Both `git:auth`
and `git:auth-status` now also accept the password via `STDIN`.
This commit is contained in:
Jose Diaz-Gonzalez
2026-04-26 23:10:30 -04:00
parent ad00918891
commit 65bdbefbea
5 changed files with 139 additions and 0 deletions

View File

@@ -76,6 +76,8 @@ cmd-git-auth() {
declare HOST="$1" USERNAME="$2" PASSWORD="$3"
[[ -z "$HOST" ]] && dokku_log_fail "Please supply a git host"
PASSWORD="$(fn-git-auth-read-password "$USERNAME" "$PASSWORD")"
if [[ -n "$USERNAME" ]] && [[ -z "$PASSWORD" ]]; then
dokku_log_fail "Missing password for netrc auth entry"
fi
@@ -91,6 +93,42 @@ cmd-git-auth() {
netrc set "$HOST" "$USERNAME" "$PASSWORD"
}
cmd-git-auth-status() {
declare desc="reports whether netrc authentication matches the requested state"
local cmd="git:auth-status"
[[ "$1" == "$cmd" ]] && shift 1
declare HOST="$1" USERNAME="$2" PASSWORD="$3"
[[ -z "$HOST" ]] && dokku_log_fail "Please supply a git host"
PASSWORD="$(fn-git-auth-read-password "$USERNAME" "$PASSWORD")"
if [[ -n "$USERNAME" ]] && [[ -z "$PASSWORD" ]]; then
dokku_log_fail "Missing password for netrc auth entry"
fi
local current
current="$(netrc get "$HOST" 2>/dev/null)" || current=""
if [[ -z "$USERNAME" ]]; then
[[ -z "$current" ]] && return 0
return 1
fi
[[ "$current" == "${USERNAME}:${PASSWORD}" ]] && return 0
return 1
}
fn-git-auth-read-password() {
declare desc="reads a netrc password from stdin when not provided as an argument"
declare USERNAME="$1" PASSWORD="$2"
if [[ -n "$USERNAME" ]] && [[ -z "$PASSWORD" ]] && [[ -p /dev/stdin ]]; then
IFS= read -r PASSWORD || true
fi
echo -n "$PASSWORD"
}
cmd-git-load-image() {
declare desc="updates an app's git repository with a docker image loaded from stdin"
local cmd="git:load-image"