diff --git a/README.md b/README.md index 4ad4c08..12e14e9 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ mysql:expose [port] Expose a mysql service on custom port if provided mysql:import < Import a dump into the mysql service database mysql:info Print the connection information mysql:link Link the mysql service to the app +mysql:linked Check if the mysql service is linked to an app mysql:list List all mysql services mysql:logs [-t] Print the most recent log(s) for this service mysql:promote Promote service as DATABASE_URL in diff --git a/common-functions b/common-functions index 413c050..af050da 100755 --- a/common-functions +++ b/common-functions @@ -288,6 +288,20 @@ service_info() { fi } +service_is_linked() { + declare desc="Links a service to an application" + declare SERVICE="$1" APP="$2" + update_plugin_scheme_for_app "$APP" + local SERVICE_URL=$(service_url "$SERVICE") + local EXISTING_CONFIG=$(config_all "$APP") + local LINK=$(echo "$EXISTING_CONFIG" | grep "$SERVICE_URL" | cut -d: -f1) || true + if [[ -z $LINK ]]; then + dokku_log_warn "Service $SERVICE is not linked to $APP" + exit 1 + fi + dokku_log_info1 "Service $SERVICE is linked to $APP" +} + service_link() { declare desc="Links a service to an application" declare SERVICE="$1" APP="$2" diff --git a/subcommands/linked b/subcommands/linked new file mode 100755 index 0000000..f5a1789 --- /dev/null +++ b/subcommands/linked @@ -0,0 +1,24 @@ +#!/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-linked-cmd() { + #E here we check if the lolipop $PLUGIN_COMMAND_PREFIX service is linked to the 'playground' app. + #E dokku $PLUGIN_COMMAND_PREFIX:linked lolipop playground + #A service, service to run command against + #A app, app to run command against + declare desc="check if the $PLUGIN_SERVICE service is linked to an app" + local cmd="$PLUGIN_COMMAND_PREFIX:linked" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare SERVICE="$1" APP="$2" + APP=${APP:="$DOKKU_APP_NAME"} + + [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service" + [[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on" + verify_app_name "$APP" + verify_service_name "$SERVICE" + service_is_linked "$SERVICE" "$APP" +} + +service-linked-cmd "$@"