Files
dokku/plugins/openresty-vhosts/command-functions
Jose Diaz-Gonzalez 64b104a2a3 feat: split openresty report into raw/computed/global
Exposes raw, global, and computed report flags for every openresty per-app property and allows those properties to be set with `--global`, so external tooling can distinguish a property that was never set from one left at its built-in default. The computed value resolves the per-app value first, then the global value, then the default. Also corrects `client-header-timeout` which read the `client-body-timeout` key and sets the computed `client-max-body-size` default to `1m`.
2026-05-28 00:03:47 -04:00

358 lines
19 KiB
Bash
Executable File

#!/usr/bin/env bash
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
source "$PLUGIN_AVAILABLE_PATH/proxy/command-functions"
source "$PLUGIN_AVAILABLE_PATH/openresty-vhosts/internal-functions"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
cmd-openresty-labels-add() {
declare desc="adds container label to app for specified proxy"
declare cmd="openresty:labels:add"
[[ "$1" == "$cmd" ]] && shift 1
cmd-proxy-labels-add "proxy:labels:add" "openresty" "$@"
}
cmd-openresty-labels-remove() {
declare desc="removes container label from app for specified proxy"
declare cmd="openresty:labels:remove"
[[ "$1" == "$cmd" ]] && shift 1
cmd-proxy-labels-remove "proxy:labels:remove" "openresty" "$@"
}
cmd-openresty-labels-show() {
declare desc="shows container labels for app for specified proxy"
declare cmd="openresty:labels:show"
[[ "$1" == "$cmd" ]] && shift 1
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"
[[ "$1" == "$cmd" ]] && shift 1
local NUM="100" TAIL=false
local TEMP=$(getopt -o htn: --long help,tail,num: -n 'dokku openresty:logs' -- "$@")
local EXIT_CODE="$?"
if [[ "$EXIT_CODE" != 0 ]]; then
fn-openresty-logs-usage >&2
exit 1
fi
eval set -- "$TEMP"
while true; do
case "$1" in
-t | --tail)
local TAIL=true
shift
;;
-n | --num)
local NUM="$2"
shift 2
;;
--)
shift
break
;;
*) dokku_log_fail "Internal error" ;;
esac
done
fn-openresty-logs "$TAIL" "$NUM"
}
cmd-openresty-show-config() {
declare desc="display openresty config"
declare cmd="openresty:show-config"
[[ "$1" == "$cmd" ]] && shift 1
if ! fn-is-compose-installed; then
dokku_log_fail "Required docker compose plugin is not installed"
fi
local TMP_COMPOSE_FILE=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
trap "rm -rf '$TMP_COMPOSE_FILE' >/dev/null" RETURN INT TERM EXIT
fn-openresty-template-compose-file "$TMP_COMPOSE_FILE"
cat "$TMP_COMPOSE_FILE"
}
cmd-openresty-start() {
declare desc="Starts the openresty server"
declare cmd="openresty:start"
[[ "$1" == "$cmd" ]] && shift 1
if ! fn-is-compose-installed; then
dokku_log_fail "Required docker compose plugin is not installed"
fi
local TMP_COMPOSE_FILE=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
trap "rm -rf '$TMP_COMPOSE_FILE' >/dev/null" RETURN INT TERM EXIT
fn-plugin-property-write "openresty" "--global" "proxy-status" "started"
fn-openresty-template-compose-file "$TMP_COMPOSE_FILE"
if ! "$PLUGIN_CORE_AVAILABLE_PATH/common/common" compose-up "openresty" "$TMP_COMPOSE_FILE"; then
return 1
fi
}
cmd-openresty-stop() {
declare desc="Starts the openresty server"
declare cmd="openresty:stop"
[[ "$1" == "$cmd" ]] && shift 1
if ! fn-is-compose-installed; then
dokku_log_fail "Required docker compose plugin is not installed"
fi
local TMP_COMPOSE_FILE=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
trap "rm -rf '$TMP_COMPOSE_FILE' >/dev/null" RETURN INT TERM EXIT
fn-plugin-property-write "openresty" "--global" "proxy-status" "stopped"
fn-openresty-template-compose-file "$TMP_COMPOSE_FILE"
if ! "$PLUGIN_CORE_AVAILABLE_PATH/common/common" compose-down "openresty" "$TMP_COMPOSE_FILE"; then
return 1
fi
}