summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rwxr-xr-xplugins/config/plugin.go24
1 files changed, 23 insertions, 1 deletions
diff --git a/plugins/config/plugin.go b/plugins/config/plugin.go
index ddb7fe88..a01a32b3 100755
--- a/plugins/config/plugin.go
+++ b/plugins/config/plugin.go
@@ -3,6 +3,7 @@ package config
import (
"bytes"
"fmt"
+ "os"
"strings"
"github.com/spf13/viper"
@@ -49,6 +50,12 @@ func (v *Viper) Init() error {
return errors.E(op, err)
}
+ // automatically inject ENV variables using ${ENV} pattern
+ for _, key := range v.viper.AllKeys() {
+ val := v.viper.Get(key)
+ v.viper.Set(key, parseEnv(val))
+ }
+
// override config Flags
if len(v.Flags) > 0 {
for _, f := range v.Flags {
@@ -61,7 +68,7 @@ func (v *Viper) Init() error {
}
}
- return v.viper.ReadInConfig()
+ return nil
}
// Overwrite overwrites existing config with provided values
@@ -125,3 +132,18 @@ func parseValue(value string) string {
return value
}
+
+func parseEnv(value interface{}) interface{} {
+ str, ok := value.(string)
+ if !ok || len(str) <= 3 {
+ return value
+ }
+
+ if str[0:2] == "${" && str[len(str)-1:] == "}" {
+ if v, ok := os.LookupEnv(str[2 : len(str)-1]); ok {
+ return v
+ }
+ }
+
+ return str
+}