From aa156b2834a4e1068ee07e74c1ef2a8913fa5fca Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 10 Mar 2020 18:19:04 -0400 Subject: [PATCH] feat: add missing config-get triggers --- docs/development/plugin-triggers.md | 30 +++++++++++++++++++++ plugins/20_events/config-get | 1 + plugins/20_events/config-get-global | 1 + plugins/config/.gitignore | 1 + plugins/config/Makefile | 3 ++- plugins/config/src/triggers/triggers.go | 35 +++++++++++++++++++++++++ plugins/config/triggers.go | 21 +++++++++++++++ 7 files changed, 91 insertions(+), 1 deletion(-) create mode 120000 plugins/20_events/config-get create mode 120000 plugins/20_events/config-get-global create mode 100644 plugins/config/src/triggers/triggers.go create mode 100644 plugins/config/triggers.go diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index af37aac05..6e588f35c 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -201,6 +201,36 @@ help_content esac ``` +### `config-get` + +- Description: Fetches the app config value for a key +- Invoked by: +- Arguments: `$APP $KEY` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +# TODO +``` + +### `config-get-global` + +- Description: Fetches the global config value for a key +- Invoked by: +- Arguments: `$KEY` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +# TODO +``` + ### `core-post-deploy` > To avoid issues with community plugins, this plugin trigger should be used *only* for core plugins. Please avoid using this trigger in your own plugins. diff --git a/plugins/20_events/config-get b/plugins/20_events/config-get new file mode 120000 index 000000000..5178a749f --- /dev/null +++ b/plugins/20_events/config-get @@ -0,0 +1 @@ +hook \ No newline at end of file diff --git a/plugins/20_events/config-get-global b/plugins/20_events/config-get-global new file mode 120000 index 000000000..5178a749f --- /dev/null +++ b/plugins/20_events/config-get-global @@ -0,0 +1 @@ +hook \ No newline at end of file diff --git a/plugins/config/.gitignore b/plugins/config/.gitignore index cc45caec7..b1c3ae87c 100644 --- a/plugins/config/.gitignore +++ b/plugins/config/.gitignore @@ -2,3 +2,4 @@ /subcommands/* /triggers/* /triggers +/config-* diff --git a/plugins/config/Makefile b/plugins/config/Makefile index fcc94b7d9..2a0a3943b 100644 --- a/plugins/config/Makefile +++ b/plugins/config/Makefile @@ -1,5 +1,6 @@ SUBCOMMANDS = subcommands/export subcommands/get subcommands/set subcommands/unset subcommands/keys subcommands/bundle -BUILD = commands subcommands +TRIGGERS = triggers/config-get triggers/config-get-global +BUILD = commands subcommands triggers PLUGIN_NAME = config include ../../common.mk diff --git a/plugins/config/src/triggers/triggers.go b/plugins/config/src/triggers/triggers.go new file mode 100644 index 000000000..0ad9f4446 --- /dev/null +++ b/plugins/config/src/triggers/triggers.go @@ -0,0 +1,35 @@ +package main + +import ( + "flag" + "fmt" + "os" + "strings" + + "github.com/dokku/dokku/plugins/common" + "github.com/dokku/dokku/plugins/config" +) + +// main entrypoint to all triggers +func main() { + parts := strings.Split(os.Args[0], "/") + trigger := parts[len(parts)-1] + flag.Parse() + + var err error + switch trigger { + case "config-get": + appName := flag.Arg(0) + key := flag.Arg(1) + config.TriggerConfigGet(appName, key) + case "config-get-global": + key := flag.Arg(0) + config.TriggerConfigGetGlobal(key) + default: + common.LogFail(fmt.Sprintf("Invalid plugin trigger call: %s", trigger)) + } + + if err != nil { + common.LogFail(err.Error()) + } +} diff --git a/plugins/config/triggers.go b/plugins/config/triggers.go new file mode 100644 index 000000000..f664f9d8f --- /dev/null +++ b/plugins/config/triggers.go @@ -0,0 +1,21 @@ +package config + +import "fmt" + +func TriggerConfigGet(appName string, key string) error { + value, ok := Get(appName, key) + if ok { + fmt.Println(value) + } + + return nil +} + +func TriggerConfigGetGlobal(key string) error { + value, ok := Get("--global", key) + if ok { + fmt.Println(value) + } + + return nil +}