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:
@@ -29,6 +29,7 @@ fn-help-content() {
|
||||
cat <<help_content
|
||||
git:allow-host <host>, Adds a host to known_hosts
|
||||
git:auth <host> [<username> <password>], Configures netrc authentication for a given git server
|
||||
git:auth-status <host> [<username> <password>], Reports whether the netrc entry matches the requested state (exit 0 if matches)
|
||||
git:from-archive <app> <archive-url> [<git-username> <git-email>], Updates an app's git repository with a given archive file
|
||||
git:from-image <app> <docker-image> [<git-username> <git-email>], Updates an app's git repository with a given docker image
|
||||
git:load-image <app> <docker-image> [<git-username> <git-email>], Updates an app's git repository with a docker image loaded from stdin
|
||||
|
||||
@@ -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"
|
||||
|
||||
6
plugins/git/subcommands/auth-status
Executable file
6
plugins/git/subcommands/auth-status
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$PLUGIN_AVAILABLE_PATH/git/internal-functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
cmd-git-auth-status "$@"
|
||||
Reference in New Issue
Block a user