Merge pull request #2508 from OmarShehata/master
Add default functions for all commands
This commit is contained in:
@@ -2,6 +2,39 @@
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
|
||||
certs_info_cmd() {
|
||||
# This is here because it's used in both the info and the default
|
||||
declare desc="prints SSL certificate info for app"
|
||||
local cmd="certs:info"
|
||||
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
|
||||
verify_app_name "$2"
|
||||
local APP="$2"; local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls"
|
||||
|
||||
if [[ -n "$APP_SSL_PATH" ]]; then
|
||||
dokku_log_info1 "Fetching SSL Endpoint info for $APP..."
|
||||
dokku_log_info1 "Certificate details:"
|
||||
dokku_log_info2 "Common Name(s): "
|
||||
|
||||
for domain in $(get_ssl_hostnames "$APP" | xargs); do
|
||||
dokku_log_info2 " $domain"
|
||||
done
|
||||
|
||||
dokku_log_info2 "Expires At: $(openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Not After :" | awk -F " : " '{ print $2 }')"
|
||||
dokku_log_info2 "Issuer: $(openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Issuer:" | xargs | sed -e "s/Issuer: //g")"
|
||||
dokku_log_info2 "Starts At: $(openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Not Before:" | awk -F ": " '{ print $2 }')"
|
||||
dokku_log_info2 "Subject: $(openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -subject | sed -e "s:subject= ::g"| sed -e "s:^/::g" | sed -e "s:/:; :g")"
|
||||
local SSL_VERIFY_OUTPUT="$(openssl verify -verbose -purpose sslserver "$APP_SSL_PATH/server.crt" | awk -F ':' '{ print $2 }' | tail -1 | xargs || true)"
|
||||
if [[ "$SSL_VERIFY_OUTPUT" == "OK" ]]; then
|
||||
local SSL_SELF_SIGNED="verified by a certificate authority."
|
||||
else
|
||||
local SSL_SELF_SIGNED="self signed."
|
||||
fi
|
||||
dokku_log_info2 "SSL certificate is $SSL_SELF_SIGNED"
|
||||
else
|
||||
dokku_log_info1 "$APP does not have an SSL endpoint"
|
||||
fi
|
||||
}
|
||||
|
||||
is_ssl_enabled() {
|
||||
declare desc="returns 0 if ssl is enabled for given app"
|
||||
local APP=$1; verify_app_name "$APP"
|
||||
|
||||
12
plugins/certs/subcommands/default
Normal file
12
plugins/certs/subcommands/default
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/certs/functions"
|
||||
|
||||
certs_main_cmd() {
|
||||
declare desc="an alias for certs:info"
|
||||
local cmd="certs"
|
||||
certs_info_cmd "$@"
|
||||
}
|
||||
|
||||
certs_main_cmd "$@"
|
||||
@@ -3,36 +3,4 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/certs/functions"
|
||||
|
||||
certs_info_cmd() {
|
||||
declare desc="prints SSL certificate info for app"
|
||||
local cmd="certs:info"
|
||||
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
|
||||
verify_app_name "$2"
|
||||
local APP="$2"; local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls"
|
||||
|
||||
if [[ -n "$APP_SSL_PATH" ]]; then
|
||||
dokku_log_info1 "Fetching SSL Endpoint info for $APP..."
|
||||
dokku_log_info1 "Certificate details:"
|
||||
dokku_log_info2 "Common Name(s): "
|
||||
|
||||
for domain in $(get_ssl_hostnames "$APP" | xargs); do
|
||||
dokku_log_info2 " $domain"
|
||||
done
|
||||
|
||||
dokku_log_info2 "Expires At: $(openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Not After :" | awk -F " : " '{ print $2 }')"
|
||||
dokku_log_info2 "Issuer: $(openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Issuer:" | xargs | sed -e "s/Issuer: //g")"
|
||||
dokku_log_info2 "Starts At: $(openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Not Before:" | awk -F ": " '{ print $2 }')"
|
||||
dokku_log_info2 "Subject: $(openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -subject | sed -e "s:subject= ::g"| sed -e "s:^/::g" | sed -e "s:/:; :g")"
|
||||
local SSL_VERIFY_OUTPUT="$(openssl verify -verbose -purpose sslserver "$APP_SSL_PATH/server.crt" | awk -F ':' '{ print $2 }' | tail -1 | xargs || true)"
|
||||
if [[ "$SSL_VERIFY_OUTPUT" == "OK" ]]; then
|
||||
local SSL_SELF_SIGNED="verified by a certificate authority."
|
||||
else
|
||||
local SSL_SELF_SIGNED="self signed."
|
||||
fi
|
||||
dokku_log_info2 "SSL certificate is $SSL_SELF_SIGNED"
|
||||
else
|
||||
dokku_log_info1 "$APP does not have an SSL endpoint"
|
||||
fi
|
||||
}
|
||||
|
||||
certs_info_cmd "$@"
|
||||
|
||||
@@ -1,26 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
[[ " help nginx:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions"
|
||||
|
||||
case "$1" in
|
||||
help | nginx:help)
|
||||
help_content_func () {
|
||||
declare desc="return nginx plugin help content"
|
||||
cat<<help_content
|
||||
nginx, Interact with Dokku's Nginx proxy
|
||||
nginx:build-config <app>, (Re)builds nginx config for given app
|
||||
nginx:access-logs <app> [-t], Show the nginx access logs for an application (-t follows)
|
||||
nginx:error-logs <app> [-t], Show the nginx error logs for an application (-t follows)
|
||||
help_content
|
||||
}
|
||||
|
||||
|
||||
if [[ $1 = "nginx:help" ]] ; then
|
||||
echo -e 'Usage: dokku nginx[:COMMAND]'
|
||||
echo ''
|
||||
echo 'Interact with Dokku'"'"'s Nginx proxy.'
|
||||
echo ''
|
||||
echo 'Additional commands:'
|
||||
help_content_func | sort | column -c2 -t -s,
|
||||
help_formatted
|
||||
else
|
||||
help_content_func
|
||||
fi
|
||||
|
||||
@@ -6,6 +6,25 @@ source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/domains/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
|
||||
|
||||
help_formatted (){
|
||||
echo -e 'Usage: dokku nginx[:COMMAND]'
|
||||
echo ''
|
||||
echo 'Interact with Dokku'"'"'s Nginx proxy.'
|
||||
echo ''
|
||||
echo 'Additional commands:'
|
||||
help_content_func | sort | column -c2 -t -s,
|
||||
}
|
||||
|
||||
help_content_func () {
|
||||
declare desc="return nginx plugin help content"
|
||||
cat<<help_content
|
||||
nginx, Interact with Dokku's Nginx proxy
|
||||
nginx:build-config <app>, (Re)builds nginx config for given app
|
||||
nginx:access-logs <app> [-t], Show the nginx access logs for an application (-t follows)
|
||||
nginx:error-logs <app> [-t], Show the nginx error logs for an application (-t follows)
|
||||
help_content
|
||||
}
|
||||
|
||||
validate_nginx() {
|
||||
declare desc="validate entire nginx config"
|
||||
set +e
|
||||
|
||||
13
plugins/nginx-vhosts/subcommands/default
Normal file
13
plugins/nginx-vhosts/subcommands/default
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions"
|
||||
|
||||
nginx_main_cmd() {
|
||||
declare desc="display nginx plugin help content"
|
||||
local cmd="nginx"
|
||||
help_formatted
|
||||
}
|
||||
|
||||
nginx_main_cmd "$@"
|
||||
@@ -2,6 +2,13 @@
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
|
||||
list_ssh_keys() {
|
||||
declare desc="List ssh key hashes"
|
||||
local cmd="ssh-keys:list"
|
||||
verify_ssh_key_file
|
||||
sshcommand list dokku
|
||||
}
|
||||
|
||||
verify_ssh_key_file() {
|
||||
declare desc="Test that public key is valid"
|
||||
[[ -s ${DOKKU_ROOT}/.ssh/authorized_keys ]] || dokku_log_fail "No public keys found."
|
||||
|
||||
12
plugins/ssh-keys/subcommands/default
Normal file
12
plugins/ssh-keys/subcommands/default
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/ssh-keys/functions"
|
||||
|
||||
ssh_keys_main_cmd() {
|
||||
declare desc="an alias for ssh-keys:list"
|
||||
local cmd="ssh-keys"
|
||||
list_ssh_keys
|
||||
}
|
||||
|
||||
ssh_keys_main_cmd "$@"
|
||||
@@ -3,11 +3,4 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/ssh-keys/functions"
|
||||
|
||||
list_ssh_keys() {
|
||||
declare desc="List ssh key hashes"
|
||||
local cmd="ssh-keys:list"
|
||||
verify_ssh_key_file
|
||||
sshcommand list dokku
|
||||
}
|
||||
|
||||
list_ssh_keys "$@"
|
||||
|
||||
@@ -2,6 +2,16 @@
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
|
||||
storage_list_cmd() {
|
||||
declare desc="List all bound mounts"
|
||||
local cmd="storage:list"
|
||||
local passed_phases="deploy"
|
||||
[[ ! $2 ]] && dokku_log_fail "storage:list requires an app to list."
|
||||
verify_app_name "$2" && local APP="$2"
|
||||
echo "$APP volume bind-mounts:"
|
||||
get_bind_mounts "$(get_phase_file_path "$passed_phases")"
|
||||
}
|
||||
|
||||
verify_paths() {
|
||||
declare desc="verifies storage paths"
|
||||
echo "$1" | grep -qe '^/.*\:/' || dokku_log_fail "Storage path must be two valid paths divided by colon."
|
||||
|
||||
13
plugins/storage/subcommands/default
Normal file
13
plugins/storage/subcommands/default
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/storage/functions"
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/docker-options/functions"
|
||||
|
||||
storage_main_cmd() {
|
||||
declare desc="an alias for storage:list"
|
||||
local cmd="storage"
|
||||
storage_list_cmd "$@"
|
||||
}
|
||||
|
||||
storage_main_cmd "$@"
|
||||
@@ -4,14 +4,5 @@ source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/storage/functions"
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/docker-options/functions"
|
||||
|
||||
storage_list_cmd() {
|
||||
declare desc="List all bound mounts"
|
||||
local cmd="storage:list"
|
||||
local passed_phases="deploy"
|
||||
[[ ! $2 ]] && dokku_log_fail "storage:list requires an app to list."
|
||||
verify_app_name "$2" && local APP="$2"
|
||||
echo "$APP volume bind-mounts:"
|
||||
get_bind_mounts "$(get_phase_file_path "$passed_phases")"
|
||||
}
|
||||
|
||||
storage_list_cmd "$@"
|
||||
|
||||
Reference in New Issue
Block a user