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