[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
```
This commit is contained in:
Alex Quick
2017-01-19 00:21:36 -05:00
parent 14757ca925
commit dc90a889d7
2 changed files with 14 additions and 5 deletions

View File

@@ -21,7 +21,7 @@ Additional commands:`
helpContent = ` helpContent = `
config:get (<app>|--global) KEY, Display a global or app-specific config value config:get (<app>|--global) KEY, Display a global or app-specific config value
config:set (<app>|--global) [--no-restart] KEY1=VALUE1 [KEY2=VALUE2 ...], Set one or more config vars config:set (<app>|--global) [--encoded] [--no-restart] KEY1=VALUE1 [KEY2=VALUE2 ...], Set one or more config vars
config:unset (<app>|--global) KEY1 [KEY2 ...], Unset one or more config vars config:unset (<app>|--global) KEY1 [KEY2 ...], Unset one or more config vars
config:export (<app>|--global) [--envfile], Export a global or app environment config:export (<app>|--global) [--envfile], Export a global or app environment
` `

View File

@@ -1,11 +1,11 @@
package main package main
import ( import (
"encoding/base64"
"flag" "flag"
"fmt"
"strings"
"os" "os"
"strings"
common "github.com/dokku/dokku/plugins/common" common "github.com/dokku/dokku/plugins/common"
"github.com/dokku/dokku/plugins/config/src/configenv" "github.com/dokku/dokku/plugins/config/src/configenv"
@@ -15,6 +15,7 @@ import (
func main() { func main() {
args := flag.NewFlagSet("config:set", flag.ExitOnError) args := flag.NewFlagSet("config:set", flag.ExitOnError)
global := args.Bool("global", false, "--global: use the global environment") 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") noRestart := args.Bool("no-restart", false, "--no-restart: no restart")
args.Parse(os.Args[2:]) args.Parse(os.Args[2:])
shouldRestart := !*global && !*noRestart shouldRestart := !*global && !*noRestart
@@ -43,7 +44,15 @@ func main() {
if len(parts) == 1 { if len(parts) == 1 {
common.LogFail("Invalid env pair: " + e) 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 changed = true
} }