From 71ebf1e476a6164dc0c0c7a4964345d829c1f292 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 4 Sep 2015 00:00:07 -0400 Subject: [PATCH] Add certs:update alias for certs:add --- plugins/certs/commands | 85 +++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 38 deletions(-) diff --git a/plugins/certs/commands b/plugins/certs/commands index c42468d7a..320f39221 100755 --- a/plugins/certs/commands +++ b/plugins/certs/commands @@ -3,43 +3,47 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$(dirname $0)/../common/functions" source "$(dirname $0)/functions" +certs_set() { + [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 + verify_app_name "$2" + [[ -t 0 ]] && echo "Tar archive containing server.crt and server.key expected on stdin" && exit 1 + APP="$2" + + TEMP_DIR=$(mktemp -d) + cd $TEMP_DIR + tar xvf - <&0 + + CRT_FILE_SEARCH=$(find . -type f -name "*.crt") + CRT_FILE_COUNT=$(printf "%s" "$CRT_FILE_SEARCH" | grep -c '^') + if [[ $CRT_FILE_COUNT -lt 1 ]]; then + echo "Tar archive is missing .crt file" && exit 1 + elif [[ $CRT_FILE_COUNT -gt 1 ]]; then + echo "Tar archive contains more than one .crt file" && exit 1 + else + CRT_FILE=$CRT_FILE_SEARCH + fi + + KEY_FILE_SEARCH=$(find . -type f -name "*.key") + KEY_FILE_COUNT=$(printf "%s" "$KEY_FILE_SEARCH" | grep -c '^') + if [[ $KEY_FILE_COUNT -lt 1 ]]; then + echo "Tar archive is missing .key file" && exit 1 + elif [[ $KEY_FILE_COUNT -gt 1 ]]; then + echo "Tar archive contains more than one .key file" && exit 1 + else + KEY_FILE=$KEY_FILE_SEARCH + fi + + mkdir -p "$DOKKU_ROOT/$APP/tls" + mv "$CRT_FILE" "$DOKKU_ROOT/$APP/tls/server.crt" + mv "$KEY_FILE" "$DOKKU_ROOT/$APP/tls/server.key" + cd $DOKKU_ROOT + rm -rf $TEMP_DIR + dokku nginx:build-config $APP +} + case "$1" in certs:add) - [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - verify_app_name "$2" - [[ -t 0 ]] && echo "Tar archive containing server.crt and server.key expected on stdin" && exit 1 - APP="$2" - - TEMP_DIR=$(mktemp -d) - cd $TEMP_DIR - tar xvf - <&0 - - CRT_FILE_SEARCH=$(find . -type f -name "*.crt") - CRT_FILE_COUNT=$(printf "%s" "$CRT_FILE_SEARCH" | grep -c '^') - if [[ $CRT_FILE_COUNT -lt 1 ]]; then - echo "Tar archive is missing .crt file" && exit 1 - elif [[ $CRT_FILE_COUNT -gt 1 ]]; then - echo "Tar archive contains more than one .crt file" && exit 1 - else - CRT_FILE=$CRT_FILE_SEARCH - fi - - KEY_FILE_SEARCH=$(find . -type f -name "*.key") - KEY_FILE_COUNT=$(printf "%s" "$KEY_FILE_SEARCH" | grep -c '^') - if [[ $KEY_FILE_COUNT -lt 1 ]]; then - echo "Tar archive is missing .key file" && exit 1 - elif [[ $KEY_FILE_COUNT -gt 1 ]]; then - echo "Tar archive contains more than one .key file" && exit 1 - else - KEY_FILE=$KEY_FILE_SEARCH - fi - - mkdir -p "$DOKKU_ROOT/$APP/tls" - mv "$CRT_FILE" "$DOKKU_ROOT/$APP/tls/server.crt" - mv "$KEY_FILE" "$DOKKU_ROOT/$APP/tls/server.key" - cd $DOKKU_ROOT - rm -rf $TEMP_DIR - dokku nginx:build-config $APP + certs_set "$@" ;; certs:generate) @@ -69,7 +73,7 @@ case "$1" in else dokku_log_info1 "$APP has an SSL endpoint already defined" fi - ;; + ;; certs:info) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 @@ -111,7 +115,7 @@ case "$1" in else dokku_log_info1 "$APP does not have an SSL endpoint" fi - ;; + ;; certs:remove) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 @@ -125,7 +129,11 @@ case "$1" in else dokku_log_info1 "An app-specific SSL endpoint is not defined" fi - ;; + ;; + + certs:update) + certs_set "$@" + ;; help | certs:help) cat && cat< DOMAIN, Generate a key and certificate signing request (and self-signed certificate) certs:info , Show certificate information for an ssl endpoint. certs:remove , Remove an SSL Endpoint from an app. + certs:update , Update an SSL Endpoint on an app. Imports a tarball from stdin; should contain server.crt and server.key EOF ;;