From 57554f62888d83a547665053b3143e52a64676ea Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 21 Jul 2018 16:32:00 -0400 Subject: [PATCH] feat: add command to list linked services for a given app --- README.md | 1 + common-functions | 16 ++++++++++++++++ subcommands/app-links | 21 +++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100755 subcommands/app-links diff --git a/README.md b/README.md index 24a4050..931fa94 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git postgres ## commands ``` +postgres:app-links List all postgres service links for a given app postgres:backup (--use-iam) Create a backup of the postgres service to an existing s3 bucket postgres:backup-auth () () () Sets up authentication for backups on the postgres service postgres:backup-deauth Removes backup authentication for the postgres service diff --git a/common-functions b/common-functions index 5b6b73b..5ff4442 100755 --- a/common-functions +++ b/common-functions @@ -118,6 +118,22 @@ service_alternative_alias() { echo "$ALIAS" } +service_app_links() { + declare desc="Outputs all service links for a given app" + declare APP="$1" + local SERVICE LINKED_APP + + pushd "$PLUGIN_DATA_ROOT" > /dev/null + for SERVICE in *; do + [[ -f "$SERVICE/LINKS" ]] || continue + for LINKED_APP in $(<"$SERVICE/LINKS"); do + if [[ "$LINKED_APP" == "$APP" ]] ; then + echo "$SERVICE" + fi + done + done +} + service_backup() { declare desc="Creates a backup of a service to an existing s3 bucket" declare SERVICE="$1" BUCKET_NAME="$2" USE_IAM_OPTIONAL_FLAG="$3" diff --git a/subcommands/app-links b/subcommands/app-links new file mode 100755 index 0000000..f315b59 --- /dev/null +++ b/subcommands/app-links @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_BASE_PATH/common/functions" +source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" + +service-app-links-cmd() { + #E list all $PLUGIN_COMMAND_PREFIX services that are linked to the 'playground' app. + #E dokku $PLUGIN_COMMAND_PREFIX:app-links playground + #A app, app to run command against + declare desc="list all $PLUGIN_SERVICE service links for a given app" + local cmd="$PLUGIN_COMMAND_PREFIX:app-links" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare APP="$1" + APP=${APP:="$DOKKU_APP_NAME"} + + [[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on" + verify_app_name "$APP" + service_app_links "$APP" +} + +service-app-links-cmd "$@"