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:
237
plugins/openresty-vhosts/command-functions
Executable file → Normal file
237
plugins/openresty-vhosts/command-functions
Executable file → Normal file
@@ -30,243 +30,6 @@ cmd-openresty-labels-show() {
|
||||
cmd-proxy-labels-show "proxy:labels:show" "openresty" "$@"
|
||||
}
|
||||
|
||||
cmd-openresty-report() {
|
||||
declare desc="displays a openresty report for one or more apps"
|
||||
declare cmd="openresty: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-openresty-report-single "$APP" "$INFO_FLAG" "$REPORT_FORMAT"
|
||||
elif [[ -z "$APP" ]]; then
|
||||
for app in $(dokku_apps); do
|
||||
cmd-openresty-report-single "$app" "$INFO_FLAG" "$REPORT_FORMAT" | tee || true
|
||||
done
|
||||
else
|
||||
cmd-openresty-report-single "$APP" "$INFO_FLAG" "$REPORT_FORMAT"
|
||||
fi
|
||||
}
|
||||
|
||||
cmd-openresty-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=(
|
||||
"--openresty-global-access-log-format: $(fn-openresty-global-access-log-format)"
|
||||
"--openresty-computed-access-log-format: $(fn-openresty-computed-access-log-format "$APP")"
|
||||
"--openresty-global-access-log-path: $(fn-openresty-global-access-log-path)"
|
||||
"--openresty-computed-access-log-path: $(fn-openresty-computed-access-log-path "$APP")"
|
||||
"--openresty-global-allowed-letsencrypt-domains-func-base64: $(fn-openresty-global-allowed-letsencrypt-domains-func-base64)"
|
||||
"--openresty-computed-allowed-letsencrypt-domains-func-base64: $(fn-openresty-computed-allowed-letsencrypt-domains-func-base64)"
|
||||
"--openresty-global-bind-address-ipv4: $(fn-openresty-global-bind-address-ipv4)"
|
||||
"--openresty-computed-bind-address-ipv4: $(fn-openresty-computed-bind-address-ipv4 "$APP")"
|
||||
"--openresty-global-bind-address-ipv6: $(fn-openresty-global-bind-address-ipv6)"
|
||||
"--openresty-computed-bind-address-ipv6: $(fn-openresty-computed-bind-address-ipv6 "$APP")"
|
||||
"--openresty-global-client-body-timeout: $(fn-openresty-global-client-body-timeout)"
|
||||
"--openresty-computed-client-body-timeout: $(fn-openresty-computed-client-body-timeout "$APP")"
|
||||
"--openresty-global-client-header-timeout: $(fn-openresty-global-client-header-timeout)"
|
||||
"--openresty-computed-client-header-timeout: $(fn-openresty-computed-client-header-timeout "$APP")"
|
||||
"--openresty-global-client-max-body-size: $(fn-openresty-global-client-max-body-size)"
|
||||
"--openresty-computed-client-max-body-size: $(fn-openresty-computed-client-max-body-size "$APP")"
|
||||
"--openresty-global-error-log-path: $(fn-openresty-global-error-log-path)"
|
||||
"--openresty-computed-error-log-path: $(fn-openresty-computed-error-log-path "$APP")"
|
||||
"--openresty-global-hsts: $(fn-plugin-property-get-default "openresty" "--global" "hsts" "")"
|
||||
"--openresty-computed-hsts: $(fn-openresty-hsts-is-enabled "--global")"
|
||||
"--openresty-global-hsts-include-subdomains: $(fn-openresty-global-hsts-include-subdomains)"
|
||||
"--openresty-computed-hsts-include-subdomains: $(fn-openresty-computed-hsts-include-subdomains "$APP")"
|
||||
"--openresty-global-hsts-max-age: $(fn-openresty-global-hsts-max-age)"
|
||||
"--openresty-computed-hsts-max-age: $(fn-openresty-computed-hsts-max-age "$APP")"
|
||||
"--openresty-global-hsts-preload: $(fn-openresty-global-hsts-preload)"
|
||||
"--openresty-computed-hsts-preload: $(fn-openresty-computed-hsts-preload "$APP")"
|
||||
"--openresty-global-image: $(fn-openresty-global-image)"
|
||||
"--openresty-computed-image: $(fn-openresty-computed-image)"
|
||||
"--openresty-global-keepalive-timeout: $(fn-openresty-global-keepalive-timeout)"
|
||||
"--openresty-computed-keepalive-timeout: $(fn-openresty-computed-keepalive-timeout "$APP")"
|
||||
"--openresty-global-letsencrypt-email: $(fn-openresty-global-letsencrypt-email)"
|
||||
"--openresty-computed-letsencrypt-email: $(fn-openresty-computed-letsencrypt-email)"
|
||||
"--openresty-global-letsencrypt-server: $(fn-openresty-global-letsencrypt-server)"
|
||||
"--openresty-computed-letsencrypt-server: $(fn-openresty-computed-letsencrypt-server)"
|
||||
"--openresty-global-lingering-timeout: $(fn-openresty-global-lingering-timeout)"
|
||||
"--openresty-computed-lingering-timeout: $(fn-openresty-computed-lingering-timeout "$APP")"
|
||||
"--openresty-global-log-level: $(fn-openresty-global-log-level)"
|
||||
"--openresty-computed-log-level: $(fn-openresty-computed-log-level)"
|
||||
"--openresty-global-proxy-buffer-size: $(fn-openresty-global-proxy-buffer-size)"
|
||||
"--openresty-computed-proxy-buffer-size: $(fn-openresty-computed-proxy-buffer-size "$APP")"
|
||||
"--openresty-global-proxy-buffering: $(fn-openresty-global-proxy-buffering)"
|
||||
"--openresty-computed-proxy-buffering: $(fn-openresty-computed-proxy-buffering "$APP")"
|
||||
"--openresty-global-proxy-buffers: $(fn-openresty-global-proxy-buffers)"
|
||||
"--openresty-computed-proxy-buffers: $(fn-openresty-computed-proxy-buffers "$APP")"
|
||||
"--openresty-global-proxy-busy-buffers-size: $(fn-openresty-global-proxy-busy-buffers-size)"
|
||||
"--openresty-computed-proxy-busy-buffers-size: $(fn-openresty-computed-proxy-busy-buffers-size "$APP")"
|
||||
"--openresty-global-proxy-connect-timeout: $(fn-openresty-global-proxy-connect-timeout)"
|
||||
"--openresty-computed-proxy-connect-timeout: $(fn-openresty-computed-proxy-connect-timeout "$APP")"
|
||||
"--openresty-global-proxy-read-timeout: $(fn-openresty-global-proxy-read-timeout)"
|
||||
"--openresty-computed-proxy-read-timeout: $(fn-openresty-computed-proxy-read-timeout "$APP")"
|
||||
"--openresty-global-proxy-send-timeout: $(fn-openresty-global-proxy-send-timeout)"
|
||||
"--openresty-computed-proxy-send-timeout: $(fn-openresty-computed-proxy-send-timeout "$APP")"
|
||||
"--openresty-global-send-timeout: $(fn-openresty-global-send-timeout)"
|
||||
"--openresty-computed-send-timeout: $(fn-openresty-computed-send-timeout "$APP")"
|
||||
"--openresty-global-underscore-in-headers: $(fn-openresty-global-underscore-in-headers)"
|
||||
"--openresty-computed-underscore-in-headers: $(fn-openresty-computed-underscore-in-headers "$APP")"
|
||||
"--openresty-global-x-forwarded-for-value: $(fn-openresty-global-x-forwarded-for-value)"
|
||||
"--openresty-computed-x-forwarded-for-value: $(fn-openresty-computed-x-forwarded-for-value "$APP")"
|
||||
"--openresty-global-x-forwarded-port-value: $(fn-openresty-global-x-forwarded-port-value)"
|
||||
"--openresty-computed-x-forwarded-port-value: $(fn-openresty-computed-x-forwarded-port-value "$APP")"
|
||||
"--openresty-global-x-forwarded-proto-value: $(fn-openresty-global-x-forwarded-proto-value)"
|
||||
"--openresty-computed-x-forwarded-proto-value: $(fn-openresty-computed-x-forwarded-proto-value "$APP")"
|
||||
"--openresty-global-x-forwarded-ssl: $(fn-openresty-global-x-forwarded-ssl)"
|
||||
"--openresty-computed-x-forwarded-ssl: $(fn-openresty-computed-x-forwarded-ssl "$APP")"
|
||||
)
|
||||
else
|
||||
verify_app_name "$APP"
|
||||
flag_map=(
|
||||
"--openresty-access-log-format: $(fn-openresty-access-log-format "$APP")"
|
||||
"--openresty-computed-access-log-format: $(fn-openresty-computed-access-log-format "$APP")"
|
||||
"--openresty-global-access-log-format: $(fn-openresty-global-access-log-format)"
|
||||
"--openresty-access-log-path: $(fn-openresty-access-log-path "$APP")"
|
||||
"--openresty-computed-access-log-path: $(fn-openresty-computed-access-log-path "$APP")"
|
||||
"--openresty-global-access-log-path: $(fn-openresty-global-access-log-path)"
|
||||
"--openresty-global-allowed-letsencrypt-domains-func-base64: $(fn-openresty-global-allowed-letsencrypt-domains-func-base64)"
|
||||
"--openresty-computed-allowed-letsencrypt-domains-func-base64: $(fn-openresty-computed-allowed-letsencrypt-domains-func-base64)"
|
||||
"--openresty-bind-address-ipv4: $(fn-openresty-bind-address-ipv4 "$APP")"
|
||||
"--openresty-computed-bind-address-ipv4: $(fn-openresty-computed-bind-address-ipv4 "$APP")"
|
||||
"--openresty-global-bind-address-ipv4: $(fn-openresty-global-bind-address-ipv4)"
|
||||
"--openresty-bind-address-ipv6: $(fn-openresty-bind-address-ipv6 "$APP")"
|
||||
"--openresty-computed-bind-address-ipv6: $(fn-openresty-computed-bind-address-ipv6 "$APP")"
|
||||
"--openresty-global-bind-address-ipv6: $(fn-openresty-global-bind-address-ipv6)"
|
||||
"--openresty-client-body-timeout: $(fn-openresty-client-body-timeout "$APP")"
|
||||
"--openresty-computed-client-body-timeout: $(fn-openresty-computed-client-body-timeout "$APP")"
|
||||
"--openresty-global-client-body-timeout: $(fn-openresty-global-client-body-timeout)"
|
||||
"--openresty-client-header-timeout: $(fn-openresty-client-header-timeout "$APP")"
|
||||
"--openresty-computed-client-header-timeout: $(fn-openresty-computed-client-header-timeout "$APP")"
|
||||
"--openresty-global-client-header-timeout: $(fn-openresty-global-client-header-timeout)"
|
||||
"--openresty-client-max-body-size: $(fn-openresty-client-max-body-size "$APP")"
|
||||
"--openresty-computed-client-max-body-size: $(fn-openresty-computed-client-max-body-size "$APP")"
|
||||
"--openresty-global-client-max-body-size: $(fn-openresty-global-client-max-body-size)"
|
||||
"--openresty-error-log-path: $(fn-openresty-error-log-path "$APP")"
|
||||
"--openresty-computed-error-log-path: $(fn-openresty-computed-error-log-path "$APP")"
|
||||
"--openresty-global-error-log-path: $(fn-openresty-global-error-log-path)"
|
||||
"--openresty-hsts: $(fn-plugin-property-get-default "openresty" "$APP" "hsts" "")"
|
||||
"--openresty-computed-hsts: $(fn-openresty-hsts-is-enabled "$APP")"
|
||||
"--openresty-global-hsts: $(fn-plugin-property-get-default "openresty" "--global" "hsts" "")"
|
||||
"--openresty-hsts-include-subdomains: $(fn-openresty-hsts-include-subdomains "$APP")"
|
||||
"--openresty-computed-hsts-include-subdomains: $(fn-openresty-computed-hsts-include-subdomains "$APP")"
|
||||
"--openresty-global-hsts-include-subdomains: $(fn-openresty-global-hsts-include-subdomains)"
|
||||
"--openresty-hsts-max-age: $(fn-openresty-hsts-max-age "$APP")"
|
||||
"--openresty-computed-hsts-max-age: $(fn-openresty-computed-hsts-max-age "$APP")"
|
||||
"--openresty-global-hsts-max-age: $(fn-openresty-global-hsts-max-age)"
|
||||
"--openresty-hsts-preload: $(fn-openresty-hsts-preload "$APP")"
|
||||
"--openresty-computed-hsts-preload: $(fn-openresty-computed-hsts-preload "$APP")"
|
||||
"--openresty-global-hsts-preload: $(fn-openresty-global-hsts-preload)"
|
||||
"--openresty-global-image: $(fn-openresty-global-image)"
|
||||
"--openresty-computed-image: $(fn-openresty-computed-image)"
|
||||
"--openresty-keepalive-timeout: $(fn-openresty-keepalive-timeout "$APP")"
|
||||
"--openresty-computed-keepalive-timeout: $(fn-openresty-computed-keepalive-timeout "$APP")"
|
||||
"--openresty-global-keepalive-timeout: $(fn-openresty-global-keepalive-timeout)"
|
||||
"--openresty-global-letsencrypt-email: $(fn-openresty-global-letsencrypt-email)"
|
||||
"--openresty-computed-letsencrypt-email: $(fn-openresty-computed-letsencrypt-email)"
|
||||
"--openresty-global-letsencrypt-server: $(fn-openresty-global-letsencrypt-server)"
|
||||
"--openresty-computed-letsencrypt-server: $(fn-openresty-computed-letsencrypt-server)"
|
||||
"--openresty-lingering-timeout: $(fn-openresty-lingering-timeout "$APP")"
|
||||
"--openresty-computed-lingering-timeout: $(fn-openresty-computed-lingering-timeout "$APP")"
|
||||
"--openresty-global-lingering-timeout: $(fn-openresty-global-lingering-timeout)"
|
||||
"--openresty-global-log-level: $(fn-openresty-global-log-level)"
|
||||
"--openresty-computed-log-level: $(fn-openresty-computed-log-level)"
|
||||
"--openresty-proxy-buffer-size: $(fn-openresty-proxy-buffer-size "$APP")"
|
||||
"--openresty-computed-proxy-buffer-size: $(fn-openresty-computed-proxy-buffer-size "$APP")"
|
||||
"--openresty-global-proxy-buffer-size: $(fn-openresty-global-proxy-buffer-size)"
|
||||
"--openresty-proxy-buffering: $(fn-openresty-proxy-buffering "$APP")"
|
||||
"--openresty-computed-proxy-buffering: $(fn-openresty-computed-proxy-buffering "$APP")"
|
||||
"--openresty-global-proxy-buffering: $(fn-openresty-global-proxy-buffering)"
|
||||
"--openresty-proxy-buffers: $(fn-openresty-proxy-buffers "$APP")"
|
||||
"--openresty-computed-proxy-buffers: $(fn-openresty-computed-proxy-buffers "$APP")"
|
||||
"--openresty-global-proxy-buffers: $(fn-openresty-global-proxy-buffers)"
|
||||
"--openresty-proxy-busy-buffers-size: $(fn-openresty-proxy-busy-buffers-size "$APP")"
|
||||
"--openresty-computed-proxy-busy-buffers-size: $(fn-openresty-computed-proxy-busy-buffers-size "$APP")"
|
||||
"--openresty-global-proxy-busy-buffers-size: $(fn-openresty-global-proxy-busy-buffers-size)"
|
||||
"--openresty-proxy-connect-timeout: $(fn-openresty-proxy-connect-timeout "$APP")"
|
||||
"--openresty-computed-proxy-connect-timeout: $(fn-openresty-computed-proxy-connect-timeout "$APP")"
|
||||
"--openresty-global-proxy-connect-timeout: $(fn-openresty-global-proxy-connect-timeout)"
|
||||
"--openresty-proxy-read-timeout: $(fn-openresty-proxy-read-timeout "$APP")"
|
||||
"--openresty-computed-proxy-read-timeout: $(fn-openresty-computed-proxy-read-timeout "$APP")"
|
||||
"--openresty-global-proxy-read-timeout: $(fn-openresty-global-proxy-read-timeout)"
|
||||
"--openresty-proxy-send-timeout: $(fn-openresty-proxy-send-timeout "$APP")"
|
||||
"--openresty-computed-proxy-send-timeout: $(fn-openresty-computed-proxy-send-timeout "$APP")"
|
||||
"--openresty-global-proxy-send-timeout: $(fn-openresty-global-proxy-send-timeout)"
|
||||
"--openresty-send-timeout: $(fn-openresty-send-timeout "$APP")"
|
||||
"--openresty-computed-send-timeout: $(fn-openresty-computed-send-timeout "$APP")"
|
||||
"--openresty-global-send-timeout: $(fn-openresty-global-send-timeout)"
|
||||
"--openresty-underscore-in-headers: $(fn-openresty-underscore-in-headers "$APP")"
|
||||
"--openresty-computed-underscore-in-headers: $(fn-openresty-computed-underscore-in-headers "$APP")"
|
||||
"--openresty-global-underscore-in-headers: $(fn-openresty-global-underscore-in-headers)"
|
||||
"--openresty-x-forwarded-for-value: $(fn-openresty-x-forwarded-for-value "$APP")"
|
||||
"--openresty-computed-x-forwarded-for-value: $(fn-openresty-computed-x-forwarded-for-value "$APP")"
|
||||
"--openresty-global-x-forwarded-for-value: $(fn-openresty-global-x-forwarded-for-value)"
|
||||
"--openresty-x-forwarded-port-value: $(fn-openresty-x-forwarded-port-value "$APP")"
|
||||
"--openresty-computed-x-forwarded-port-value: $(fn-openresty-computed-x-forwarded-port-value "$APP")"
|
||||
"--openresty-global-x-forwarded-port-value: $(fn-openresty-global-x-forwarded-port-value)"
|
||||
"--openresty-x-forwarded-proto-value: $(fn-openresty-x-forwarded-proto-value "$APP")"
|
||||
"--openresty-computed-x-forwarded-proto-value: $(fn-openresty-computed-x-forwarded-proto-value "$APP")"
|
||||
"--openresty-global-x-forwarded-proto-value: $(fn-openresty-global-x-forwarded-proto-value)"
|
||||
"--openresty-x-forwarded-ssl: $(fn-openresty-x-forwarded-ssl "$APP")"
|
||||
"--openresty-computed-x-forwarded-ssl: $(fn-openresty-computed-x-forwarded-ssl "$APP")"
|
||||
"--openresty-global-x-forwarded-ssl: $(fn-openresty-global-x-forwarded-ssl)"
|
||||
)
|
||||
fi
|
||||
|
||||
fn-report-validate-format "$FORMAT" "$INFO_FLAG"
|
||||
|
||||
if [[ "$FORMAT" == "json" ]]; then
|
||||
fn-report-emit-json flag_map "openresty"
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ -z "$INFO_FLAG" ]]; then
|
||||
if [[ "$APP" == "--global" ]]; then
|
||||
dokku_log_info2_quiet "global openresty information"
|
||||
else
|
||||
dokku_log_info2_quiet "${APP} openresty 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-openresty-logs() {
|
||||
declare desc="display openresty logs from command line"
|
||||
declare cmd="openresty:logs"
|
||||
|
||||
Reference in New Issue
Block a user