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:
107
plugins/caddy-vhosts/command-functions
Executable file → Normal file
107
plugins/caddy-vhosts/command-functions
Executable file → Normal file
@@ -30,113 +30,6 @@ cmd-caddy-labels-show() {
|
||||
cmd-proxy-labels-show "proxy:labels:show" "caddy" "$@"
|
||||
}
|
||||
|
||||
cmd-caddy-report() {
|
||||
declare desc="displays a caddy report for one or more apps"
|
||||
declare cmd="caddy: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-caddy-report-single "$APP" "$INFO_FLAG" "$REPORT_FORMAT"
|
||||
elif [[ -z "$APP" ]]; then
|
||||
for app in $(dokku_apps); do
|
||||
cmd-caddy-report-single "$app" "$INFO_FLAG" "$REPORT_FORMAT" | tee || true
|
||||
done
|
||||
else
|
||||
cmd-caddy-report-single "$APP" "$INFO_FLAG" "$REPORT_FORMAT"
|
||||
fi
|
||||
}
|
||||
|
||||
cmd-caddy-report-single() {
|
||||
declare APP="$1" INFO_FLAG="$2" FORMAT="${3:-stdout}"
|
||||
if [[ "$INFO_FLAG" == "true" ]]; then
|
||||
INFO_FLAG=""
|
||||
fi
|
||||
local flag_map=()
|
||||
if [[ "$APP" == "--global" ]]; then
|
||||
flag_map=(
|
||||
"--caddy-computed-image: $(fn-caddy-computed-image)"
|
||||
"--caddy-computed-letsencrypt-email: $(fn-caddy-computed-letsencrypt-email)"
|
||||
"--caddy-computed-letsencrypt-server: $(fn-caddy-computed-letsencrypt-server)"
|
||||
"--caddy-computed-log-level: $(fn-caddy-computed-log-level)"
|
||||
"--caddy-computed-polling-interval: $(fn-caddy-computed-polling-interval)"
|
||||
"--caddy-computed-tls-internal: $(fn-caddy-computed-tls-internal "$APP")"
|
||||
"--caddy-global-image: $(fn-caddy-global-image)"
|
||||
"--caddy-global-letsencrypt-email: $(fn-caddy-global-letsencrypt-email)"
|
||||
"--caddy-global-letsencrypt-server: $(fn-caddy-global-letsencrypt-server)"
|
||||
"--caddy-global-log-level: $(fn-caddy-global-log-level)"
|
||||
"--caddy-global-polling-interval: $(fn-caddy-global-polling-interval)"
|
||||
"--caddy-global-tls-internal: $(fn-caddy-global-tls-internal)"
|
||||
)
|
||||
else
|
||||
verify_app_name "$APP"
|
||||
flag_map=(
|
||||
"--caddy-computed-image: $(fn-caddy-computed-image)"
|
||||
"--caddy-computed-letsencrypt-email: $(fn-caddy-computed-letsencrypt-email)"
|
||||
"--caddy-computed-letsencrypt-server: $(fn-caddy-computed-letsencrypt-server)"
|
||||
"--caddy-computed-log-level: $(fn-caddy-computed-log-level)"
|
||||
"--caddy-computed-polling-interval: $(fn-caddy-computed-polling-interval)"
|
||||
"--caddy-computed-tls-internal: $(fn-caddy-computed-tls-internal "$APP")"
|
||||
"--caddy-global-image: $(fn-caddy-global-image)"
|
||||
"--caddy-global-letsencrypt-email: $(fn-caddy-global-letsencrypt-email)"
|
||||
"--caddy-global-letsencrypt-server: $(fn-caddy-global-letsencrypt-server)"
|
||||
"--caddy-global-log-level: $(fn-caddy-global-log-level)"
|
||||
"--caddy-global-polling-interval: $(fn-caddy-global-polling-interval)"
|
||||
"--caddy-global-tls-internal: $(fn-caddy-global-tls-internal)"
|
||||
"--caddy-tls-internal: $(fn-caddy-tls-internal "$APP")"
|
||||
)
|
||||
fi
|
||||
|
||||
fn-report-validate-format "$FORMAT" "$INFO_FLAG"
|
||||
|
||||
if [[ "$FORMAT" == "json" ]]; then
|
||||
fn-report-emit-json flag_map "caddy"
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ -z "$INFO_FLAG" ]]; then
|
||||
if [[ "$APP" == "--global" ]]; then
|
||||
dokku_log_info2_quiet "global caddy information"
|
||||
else
|
||||
dokku_log_info2_quiet "${APP} caddy 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-caddy-logs() {
|
||||
declare desc="display caddy logs from command line"
|
||||
declare cmd="caddy:logs"
|
||||
|
||||
Reference in New Issue
Block a user