From 8f671b43aeec2f932e7a4969abfd39e1e8f9c23b Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 30 Aug 2020 13:37:47 -0400 Subject: [PATCH] feat: add helper functions for getting global config --- plugins/common/common.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/plugins/common/common.go b/plugins/common/common.go index c4d072c0f..5f91c1cae 100644 --- a/plugins/common/common.go +++ b/plugins/common/common.go @@ -910,3 +910,31 @@ func pruneUnusedImages(appName string) { pruneCmd.Command.Stderr = &stderr pruneCmd.Execute() } + +func ConfigGet(appName string, key string, defaultValue string) (string, error) { + b, err := PlugnTriggerOutput("config-get", []string{appName, key}...) + if err != nil { + return defaultValue, err + } + + value := defaultValue + if string(b[:]) != "" { + value = string(b[:]) + } + + return value, nil +} + +func ConfigGetGlobal(key string, defaultValue string) (string, error) { + b, err := PlugnTriggerOutput("config-get-global", []string{key}...) + if err != nil { + return defaultValue, err + } + + value := defaultValue + if string(b[:]) != "" { + value = string(b[:]) + } + + return value, nil +}