From dc90a889d7aad16cdab02eaa9d5bb9a0d67222a7 Mon Sep 17 00:00:00 2001 From: Alex Quick Date: Thu, 19 Jan 2017 00:21:36 -0500 Subject: [PATCH] [config] add config:set --encoded (base64) You can now set b64encoded values. They are stored decoded, this is so dokku over ssh can set odd config values ``` config:set --encoded KEY=BASE_64_VALUE ``` --- plugins/config/src/commands/commands.go | 2 +- plugins/config/src/subcommands/set/set.go | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/plugins/config/src/commands/commands.go b/plugins/config/src/commands/commands.go index d0a04dbf3..edbbadc3c 100644 --- a/plugins/config/src/commands/commands.go +++ b/plugins/config/src/commands/commands.go @@ -21,7 +21,7 @@ Additional commands:` helpContent = ` config:get (|--global) KEY, Display a global or app-specific config value - config:set (|--global) [--no-restart] KEY1=VALUE1 [KEY2=VALUE2 ...], Set one or more config vars + config:set (|--global) [--encoded] [--no-restart] KEY1=VALUE1 [KEY2=VALUE2 ...], Set one or more config vars config:unset (|--global) KEY1 [KEY2 ...], Unset one or more config vars config:export (|--global) [--envfile], Export a global or app environment ` diff --git a/plugins/config/src/subcommands/set/set.go b/plugins/config/src/subcommands/set/set.go index 5e0b38dab..b01be629f 100644 --- a/plugins/config/src/subcommands/set/set.go +++ b/plugins/config/src/subcommands/set/set.go @@ -1,11 +1,11 @@ package main import ( + "encoding/base64" "flag" - - "strings" - + "fmt" "os" + "strings" common "github.com/dokku/dokku/plugins/common" "github.com/dokku/dokku/plugins/config/src/configenv" @@ -15,6 +15,7 @@ import ( func main() { args := flag.NewFlagSet("config:set", flag.ExitOnError) global := args.Bool("global", false, "--global: use the global environment") + encoded := args.Bool("encoded", false, "--encoded: interpret VALUEs as base64") noRestart := args.Bool("no-restart", false, "--no-restart: no restart") args.Parse(os.Args[2:]) shouldRestart := !*global && !*noRestart @@ -43,7 +44,15 @@ func main() { if len(parts) == 1 { common.LogFail("Invalid env pair: " + e) } - env.Set(parts[0], parts[1]) + key, value := parts[0], parts[1] + if *encoded { + decoded, err := base64.StdEncoding.DecodeString(value) + if err != nil { + common.LogFail(fmt.Sprintf("%s for key '%s'", err.Error(), key)) + } + value = string(decoded) + } + env.Set(key, value) changed = true }