feat: port vhost proxy :report subcommands to golang

The bash :report implementations for the caddy, haproxy, openresty, and traefik proxy plugins are replaced with a compiled golang binary that collects report keys in parallel and marshals json directly. The traefik dns-provider values keep their masking behaviour, remaining hidden in the default stdout report while surfacing for --format json or an explicit flag query. These four plugins previously had no unit tests, so a bats suite covering the report matrix is added for each.
This commit is contained in:
Jose Diaz-Gonzalez
2026-07-07 06:29:01 -04:00
parent f9db9583a1
commit 5faabea3d4
49 changed files with 1853 additions and 605 deletions

125
plugins/traefik-vhosts/command-functions Executable file → Normal file
View File

@@ -30,131 +30,6 @@ cmd-traefik-labels-show() {
cmd-proxy-labels-show "proxy:labels:show" "traefik" "$@"
}
cmd-traefik-report() {
declare desc="displays a traefik report for one or more apps"
declare cmd="traefik:report"
[[ "$1" == "$cmd" ]] && shift 1
fn-report-parse-args "$@"
set -- "${REPORT_ARGS[@]}"
declare APP="${1:-}" INFO_FLAG="${2:-}"
if [[ -n "$APP" ]] && [[ "$APP" == --* ]]; then
INFO_FLAG="$APP"
APP=""
fi
if [[ "$REPORT_IS_GLOBAL" == "true" ]]; then
APP="--global"
fi
if [[ -z "$APP" ]] && [[ -z "$INFO_FLAG" ]]; then
INFO_FLAG="true"
fi
if [[ "$APP" == "--global" ]]; then
cmd-traefik-report-single "$APP" "$INFO_FLAG" "$REPORT_FORMAT"
elif [[ -z "$APP" ]]; then
for app in $(dokku_apps); do
cmd-traefik-report-single "$app" "$INFO_FLAG" "$REPORT_FORMAT" | tee || true
done
else
cmd-traefik-report-single "$APP" "$INFO_FLAG" "$REPORT_FORMAT"
fi
}
cmd-traefik-report-single() {
declare APP="$1" INFO_FLAG="$2" FORMAT="${3:-stdout}"
if [[ "$INFO_FLAG" == "true" ]]; then
INFO_FLAG=""
fi
if [[ "$APP" != "--global" ]]; then
verify_app_name "$APP"
fi
local flag_map=(
"--traefik-computed-api-enabled: $(fn-traefik-computed-api-enabled)"
"--traefik-computed-api-entry-point: $(fn-traefik-computed-api-entry-point)"
"--traefik-computed-api-entry-point-address: $(fn-traefik-computed-api-entry-point-address)"
"--traefik-computed-api-vhost: $(fn-traefik-computed-api-vhost)"
"--traefik-computed-basic-auth-password: $(fn-traefik-computed-basic-auth-password)"
"--traefik-computed-basic-auth-username: $(fn-traefik-computed-basic-auth-username)"
"--traefik-computed-challenge-mode: $(fn-traefik-computed-challenge-mode)"
"--traefik-computed-dashboard-enabled: $(fn-traefik-computed-dashboard-enabled)"
"--traefik-computed-dns-provider: $(fn-traefik-computed-dns-provider)"
"--traefik-computed-http-entry-point: $(fn-traefik-computed-http-entry-point)"
"--traefik-computed-https-entry-point: $(fn-traefik-computed-https-entry-point)"
"--traefik-computed-image: $(fn-traefik-computed-image)"
"--traefik-computed-letsencrypt-email: $(fn-traefik-computed-letsencrypt-email)"
"--traefik-computed-letsencrypt-server: $(fn-traefik-computed-letsencrypt-server)"
"--traefik-computed-log-level: $(fn-traefik-computed-log-level)"
"--traefik-global-api-enabled: $(fn-traefik-global-api-enabled)"
"--traefik-global-api-entry-point: $(fn-traefik-global-api-entry-point)"
"--traefik-global-api-entry-point-address: $(fn-traefik-global-api-entry-point-address)"
"--traefik-global-api-vhost: $(fn-traefik-global-api-vhost)"
"--traefik-global-basic-auth-password: $(fn-traefik-global-basic-auth-password)"
"--traefik-global-basic-auth-username: $(fn-traefik-global-basic-auth-username)"
"--traefik-global-challenge-mode: $(fn-traefik-global-challenge-mode)"
"--traefik-global-dashboard-enabled: $(fn-traefik-global-dashboard-enabled)"
"--traefik-global-dns-provider: $(fn-traefik-global-dns-provider)"
"--traefik-global-http-entry-point: $(fn-traefik-global-http-entry-point)"
"--traefik-global-https-entry-point: $(fn-traefik-global-https-entry-point)"
"--traefik-global-image: $(fn-traefik-global-image)"
"--traefik-global-letsencrypt-email: $(fn-traefik-global-letsencrypt-email)"
"--traefik-global-letsencrypt-server: $(fn-traefik-global-letsencrypt-server)"
"--traefik-global-log-level: $(fn-traefik-global-log-level)"
)
local dns_provider_env_vars
dns_provider_env_vars="$(fn-traefik-dns-provider-env-vars)"
if [[ -n "$dns_provider_env_vars" ]]; then
while IFS= read -r line; do
local key value
key="$(echo "$line" | cut -d' ' -f1)"
value="$(echo "$line" | cut -d' ' -f2-)"
if [[ -n "$key" ]]; then
if [[ "$FORMAT" == "json" ]] || [[ "$INFO_FLAG" == "--traefik-${key}" ]]; then
flag_map+=("--traefik-${key}: ${value}")
else
flag_map+=("--traefik-${key}: *******")
fi
fi
done <<<"$dns_provider_env_vars"
fi
fn-report-validate-format "$FORMAT" "$INFO_FLAG"
if [[ "$FORMAT" == "json" ]]; then
fn-report-emit-json flag_map "traefik"
return
fi
if [[ -z "$INFO_FLAG" ]]; then
if [[ "$APP" == "--global" ]]; then
dokku_log_info2_quiet "global traefik information"
else
dokku_log_info2_quiet "${APP} traefik information"
fi
for flag in "${flag_map[@]}"; do
key="$(echo "${flag#--}" | cut -f1 -d' ' | tr - ' ')"
dokku_log_verbose "$(printf "%-30s %-25s" "${key^}" "${flag#*: }")"
done
else
local match=false
for flag in "${flag_map[@]}"; do
valid_flags="${valid_flags} $(echo "$flag" | cut -d':' -f1)"
if [[ "$flag" == "${INFO_FLAG}:"* ]]; then
value=${flag#*: }
size="${#value}"
if [[ "$size" -ne 0 ]]; then
echo "$value" && match=true
else
match=true
fi
fi
done
[[ "$match" == "true" ]] || dokku_log_fail "Invalid flag passed, valid flags:${valid_flags}"
fi
}
cmd-traefik-logs() {
declare desc="display traefik logs from command line"
declare cmd="traefik:logs"