diff --git a/plugins/caddy-vhosts/command-functions b/plugins/caddy-vhosts/command-functions index e515e2820..c2ec92404 100755 --- a/plugins/caddy-vhosts/command-functions +++ b/plugins/caddy-vhosts/command-functions @@ -5,14 +5,28 @@ source "$PLUGIN_AVAILABLE_PATH/caddy-vhosts/internal-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -cmd-caddy-label() { - declare desc="set/unset/show container proxy labels" - declare cmd="caddy:label" +cmd-caddy-label-add() { + declare desc="adds container label to app for specified proxy" + declare cmd="caddy:label:add" [[ "$1" == "$cmd" ]] && shift 1 - declare APP="$1" - set -- caddy "$@" - cmd-proxy-label "$@" + cmd-proxy-label-add "proxy:label:add" "caddy" "$@" +} + +cmd-caddy-label-remove() { + declare desc="removes container label from app for specified proxy" + declare cmd="caddy:label:remove" + [[ "$1" == "$cmd" ]] && shift 1 + + cmd-proxy-label-remove "proxy:label:remove" "caddy" "$@" +} + +cmd-caddy-label-show() { + declare desc="shows container labels for app for specified proxy" + declare cmd="caddy:label:show" + [[ "$1" == "$cmd" ]] && shift 1 + + cmd-proxy-label-show "proxy:label:show" "caddy" "$@" } cmd-caddy-report() { diff --git a/plugins/caddy-vhosts/commands b/plugins/caddy-vhosts/commands index 03e69b312..76a267f5a 100755 --- a/plugins/caddy-vhosts/commands +++ b/plugins/caddy-vhosts/commands @@ -1,6 +1,7 @@ #!/usr/bin/env bash [[ " caddy:help help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" source "$PLUGIN_AVAILABLE_PATH/caddy-vhosts/help-functions" +source "$PLUGIN_AVAILABLE_PATH/caddy-vhosts/command-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x @@ -9,6 +10,18 @@ case "$1" in cmd-caddy-help "$@" ;; + caddy:label:add) + cmd-caddy-label-add "$@" + ;; + + caddy:label:remove) + cmd-caddy-label-remove "$@" + ;; + + caddy:label:show) + cmd-caddy-label-show "$@" + ;; + *) exit "$DOKKU_NOT_IMPLEMENTED_EXIT" ;; diff --git a/plugins/caddy-vhosts/subcommands/label b/plugins/caddy-vhosts/subcommands/label deleted file mode 100755 index 2a5e0421b..000000000 --- a/plugins/caddy-vhosts/subcommands/label +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash -source "$PLUGIN_AVAILABLE_PATH/caddy-vhosts/command-functions" -set -eo pipefail -[[ $DOKKU_TRACE ]] && set -x - -cmd-caddy-label "$@" diff --git a/plugins/haproxy-vhosts/command-functions b/plugins/haproxy-vhosts/command-functions index f7ce1be91..d7a4633c1 100755 --- a/plugins/haproxy-vhosts/command-functions +++ b/plugins/haproxy-vhosts/command-functions @@ -5,14 +5,28 @@ source "$PLUGIN_AVAILABLE_PATH/haproxy-vhosts/internal-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -cmd-haproxy-label() { - declare desc="set/unset/show container proxy labels" - declare cmd="haproxy:label" +cmd-haproxy-label-add() { + declare desc="adds container label to app for specified proxy" + declare cmd="haproxy:label:add" [[ "$1" == "$cmd" ]] && shift 1 - declare APP="$1" - set -- haproxy "$@" - cmd-proxy-label "$@" + cmd-proxy-label-add "proxy:label:add" "haproxy" "$@" +} + +cmd-haproxy-label-remove() { + declare desc="removes container label from app for specified proxy" + declare cmd="haproxy:label:remove" + [[ "$1" == "$cmd" ]] && shift 1 + + cmd-proxy-label-remove "proxy:label:remove" "haproxy" "$@" +} + +cmd-haproxy-label-show() { + declare desc="shows container labels for app for specified proxy" + declare cmd="haproxy:label:show" + [[ "$1" == "$cmd" ]] && shift 1 + + cmd-proxy-label-show "proxy:label:show" "haproxy" "$@" } cmd-haproxy-report() { diff --git a/plugins/haproxy-vhosts/commands b/plugins/haproxy-vhosts/commands index 945869e42..fc866b7b8 100755 --- a/plugins/haproxy-vhosts/commands +++ b/plugins/haproxy-vhosts/commands @@ -1,6 +1,7 @@ #!/usr/bin/env bash [[ " haproxy:help help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" source "$PLUGIN_AVAILABLE_PATH/haproxy-vhosts/help-functions" +source "$PLUGIN_AVAILABLE_PATH/haproxy-vhosts/command-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x @@ -9,6 +10,18 @@ case "$1" in cmd-haproxy-help "$@" ;; + haproxy:label:add) + cmd-haproxy-label-add "$@" + ;; + + haproxy:label:remove) + cmd-haproxy-label-remove "$@" + ;; + + haproxy:label:show) + cmd-haproxy-label-show "$@" + ;; + *) exit "$DOKKU_NOT_IMPLEMENTED_EXIT" ;; diff --git a/plugins/haproxy-vhosts/subcommands/label b/plugins/haproxy-vhosts/subcommands/label deleted file mode 100755 index d52aa7b16..000000000 --- a/plugins/haproxy-vhosts/subcommands/label +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash -source "$PLUGIN_AVAILABLE_PATH/haproxy-vhosts/command-functions" -set -eo pipefail -[[ $DOKKU_TRACE ]] && set -x - -cmd-haproxy-label "$@" diff --git a/plugins/openresty-vhosts/command-functions b/plugins/openresty-vhosts/command-functions index d9f6401c7..ef887cde4 100755 --- a/plugins/openresty-vhosts/command-functions +++ b/plugins/openresty-vhosts/command-functions @@ -5,14 +5,28 @@ source "$PLUGIN_AVAILABLE_PATH/openresty-vhosts/internal-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -cmd-openresty-label() { - declare desc="set/unset/show container proxy labels" - declare cmd="openresty:label" +cmd-openresty-label-add() { + declare desc="adds container label to app for specified proxy" + declare cmd="openresty:label:add" [[ "$1" == "$cmd" ]] && shift 1 - declare APP="$1" - set -- openresty "$@" - cmd-proxy-label "$@" + cmd-proxy-label-add "proxy:label:add" "openresty" "$@" +} + +cmd-openresty-label-remove() { + declare desc="removes container label from app for specified proxy" + declare cmd="openresty:label:remove" + [[ "$1" == "$cmd" ]] && shift 1 + + cmd-proxy-label-remove "proxy:label:remove" "openresty" "$@" +} + +cmd-openresty-label-show() { + declare desc="shows container labels for app for specified proxy" + declare cmd="openresty:label:show" + [[ "$1" == "$cmd" ]] && shift 1 + + cmd-proxy-label-show "proxy:label:show" "openresty" "$@" } cmd-openresty-report() { diff --git a/plugins/openresty-vhosts/commands b/plugins/openresty-vhosts/commands index b87c8aa14..6b76d4e68 100755 --- a/plugins/openresty-vhosts/commands +++ b/plugins/openresty-vhosts/commands @@ -1,6 +1,7 @@ #!/usr/bin/env bash [[ " openresty:help help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" source "$PLUGIN_AVAILABLE_PATH/openresty-vhosts/help-functions" +source "$PLUGIN_AVAILABLE_PATH/openresty-vhosts/command-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x @@ -9,6 +10,18 @@ case "$1" in cmd-openresty-help "$@" ;; + openresty:label:add) + cmd-openresty-label-add "$@" + ;; + + openresty:label:remove) + cmd-openresty-label-remove "$@" + ;; + + openresty:label:show) + cmd-openresty-label-show "$@" + ;; + *) exit "$DOKKU_NOT_IMPLEMENTED_EXIT" ;; diff --git a/plugins/openresty-vhosts/subcommands/label b/plugins/openresty-vhosts/subcommands/label deleted file mode 100755 index b1a49be45..000000000 --- a/plugins/openresty-vhosts/subcommands/label +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash -source "$PLUGIN_AVAILABLE_PATH/openresty-vhosts/command-functions" -set -eo pipefail -[[ $DOKKU_TRACE ]] && set -x - -cmd-openresty-label "$@" diff --git a/plugins/proxy/command-functions b/plugins/proxy/command-functions index d38158421..2bc6e1170 100755 --- a/plugins/proxy/command-functions +++ b/plugins/proxy/command-functions @@ -11,25 +11,27 @@ cmd-proxy-label-show() { declare PROXY="$1" APP="$2" PASSED_LABEL_NAME="$3" shift 2 + [[ -z "$PROXY" ]] && dokku_log_fail "Error invoking proxy:label command" + verify_app_name "$APP" + if [[ -n "$PASSED_LABEL_NAME" ]]; then fn-proxy-show-label "$PROXY" "$APP" "$PASSED_LABEL_NAME" return fi fn-proxy-display-labels "$PROXY" "$APP" - return 0 } cmd-proxy-label-add() { declare desc="adds container label to app for specified proxy" + declare cmd="proxy:label:add" + [[ "$1" == "$cmd" ]] && shift 1 declare PROXY="$1" APP="$2" PASSED_LABEL_NAME="$3" PASSED_LABEL_VALUE="$4" - if [[ -z "$PASSED_LABEL_NAME" ]]; then - dokku_log_fail "Please specify a container label for the app" - fi - if [[ -z "$PASSED_LABEL_VALUE" ]]; then - dokku_log_fail "Please specify a value for the container label" - fi + [[ -z "$PROXY" ]] && dokku_log_fail "Error invoking proxy:label command" + [[ -z "$PASSED_LABEL_NAME" ]] && dokku_log_fail "Please specify a container label for the app" + [[ -z "$PASSED_LABEL_VALUE" ]] && dokku_log_fail "Please specify a value for the container label" + verify_app_name "$APP" local proxy_labels_file_path="$(fn-proxy-get-labels-file-path "$PROXY" "$APP")" touch "$proxy_labels_file_path" @@ -41,11 +43,13 @@ cmd-proxy-label-add() { cmd-proxy-label-remove() { declare desc="removes container label from app for specified proxy" + declare cmd="proxy:label:remove" + [[ "$1" == "$cmd" ]] && shift 1 declare PROXY="$1" APP="$2" PASSED_LABEL_NAME="$3" - if [[ -z "$PASSED_LABEL_NAME" ]]; then - dokku_log_fail "Please specify a container label for the app" - fi + [[ -z "$PROXY" ]] && dokku_log_fail "Error invoking proxy:label command" + [[ -z "$PASSED_LABEL_NAME" ]] && dokku_log_fail "Please specify a container label for the app" + verify_app_name "$APP" local proxy_labels_file_path="$(fn-proxy-get-labels-file-path "$PROXY" "$APP")" if [[ ! -s "$proxy_labels_file_path" ]]; then @@ -57,28 +61,3 @@ cmd-proxy-label-remove() { local all_proxy_labels="$(echo -e "${all_proxy_labels}" | sed -E "s/^--label ['\"]${escaped_label_name}=.*\$//")" echo -e "${all_proxy_labels}" | sed '/^$/d' | sort -u >"$proxy_labels_file_path" } - -cmd-proxy-label() { - declare desc="manage proxy labels for an app" - declare cmd="proxy:label" - shift 1 # the command comes from the upstream plugin - declare PROXY="$1" ACTION="$2" APP="$3" PASSED_LABEL_NAME="$4" PASSED_LABEL_VALUE="$5" - - [[ -z "$PROXY" ]] && dokku_log_fail "Error invoking proxy:label command" - verify_app_name "$APP" - - if [[ -n "$PASSED_LABEL_NAME" ]] && [[ ! "$PASSED_LABEL_NAME" =~ ^$PROXY ]]; then - dokku_log_fail "Please specify a valid $PROXY label name for the app" - fi - - if [[ "$action" == "show" ]]; then - cmd-proxy-label-show "$PROXY" "$APP" "$PASSED_LABEL_NAME" - return 0 - elif [[ "$ACTION" == "set" ]]; then - cmd-proxy-label-add "$PROXY" "$APP" "$PASSED_LABEL_NAME" "$PASSED_LABEL_VALUE" - elif [[ "$action" == "unset" ]]; then - cmd-proxy-label-remove "$PROXY" "$APP" "$PASSED_LABEL_NAME" - else - dokku_log_fail "Please specify a valid action ('set', 'unset' or 'show')" - fi -} diff --git a/plugins/traefik-vhosts/command-functions b/plugins/traefik-vhosts/command-functions index 5a9eb91ec..32a3d9e75 100755 --- a/plugins/traefik-vhosts/command-functions +++ b/plugins/traefik-vhosts/command-functions @@ -5,14 +5,28 @@ source "$PLUGIN_AVAILABLE_PATH/traefik-vhosts/internal-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -cmd-traefik-label() { - declare desc="set/unset/show container proxy labels" - declare cmd="traefik:label" +cmd-traefik-label-add() { + declare desc="adds container label to app for specified proxy" + declare cmd="traefik:label:add" [[ "$1" == "$cmd" ]] && shift 1 - declare APP="$1" - set -- traefik "$@" - cmd-proxy-label "$@" + cmd-proxy-label-add "proxy:label:add" "traefik" "$@" +} + +cmd-traefik-label-remove() { + declare desc="removes container label from app for specified proxy" + declare cmd="traefik:label:remove" + [[ "$1" == "$cmd" ]] && shift 1 + + cmd-proxy-label-remove "proxy:label:remove" "traefik" "$@" +} + +cmd-traefik-label-show() { + declare desc="shows container labels for app for specified proxy" + declare cmd="traefik:label:show" + [[ "$1" == "$cmd" ]] && shift 1 + + cmd-proxy-label-show "proxy:label:show" "traefik" "$@" } cmd-traefik-report() { diff --git a/plugins/traefik-vhosts/commands b/plugins/traefik-vhosts/commands index dfcc90d93..24a440dff 100755 --- a/plugins/traefik-vhosts/commands +++ b/plugins/traefik-vhosts/commands @@ -1,6 +1,7 @@ #!/usr/bin/env bash [[ " traefik:help help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" source "$PLUGIN_AVAILABLE_PATH/traefik-vhosts/help-functions" +source "$PLUGIN_AVAILABLE_PATH/traefik-vhosts/command-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x @@ -9,6 +10,18 @@ case "$1" in cmd-traefik-help "$@" ;; + traefik:label:add) + cmd-traefik-label-add "$@" + ;; + + traefik:label:remove) + cmd-traefik-label-remove "$@" + ;; + + traefik:label:show) + cmd-traefik-label-show "$@" + ;; + *) exit "$DOKKU_NOT_IMPLEMENTED_EXIT" ;; diff --git a/plugins/traefik-vhosts/subcommands/label b/plugins/traefik-vhosts/subcommands/label deleted file mode 100755 index 719f47b8b..000000000 --- a/plugins/traefik-vhosts/subcommands/label +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash -source "$PLUGIN_AVAILABLE_PATH/traefik-vhosts/command-functions" -set -eo pipefail -[[ $DOKKU_TRACE ]] && set -x - -cmd-traefik-label "$@"