fnctl: env var expansion for app/route configuration (#249)

* fnctl: env var expansion for app/route configuration

* fnctl: env var expansion for app configuration

* fnctl: code grooming
This commit is contained in:
C Cirello
2016-11-10 19:55:25 +01:00
committed by GitHub
parent 4e41cac6e2
commit 15af6131b5
4 changed files with 22 additions and 16 deletions

View File

@@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"os"
"strings"
"text/tabwriter"
"github.com/iron-io/functions_go"
@@ -76,15 +75,9 @@ func (a *appsCmd) create(c *cli.Context) error {
return fmt.Errorf("error setting endpoint: %v", err)
}
appName := c.Args().Get(0)
configs := make(map[string]string)
for _, v := range c.StringSlice("config") {
kv := strings.SplitN(v, "=", 2)
configs[kv[0]] = kv[1]
}
body := functions.AppWrapper{App: functions.App{
Name: appName,
Config: configs,
Name: c.Args().Get(0),
Config: extractEnvConfig(c.StringSlice("config")),
}}
wrapper, _, err := a.AppsPost(body)
if err != nil {

View File

@@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"
"text/tabwriter"
"time"
@@ -253,3 +254,12 @@ func (c commoncmd) dockerbuild(path, image string) error {
return nil
}
func extractEnvConfig(configs []string) map[string]string {
c := make(map[string]string)
for _, v := range configs {
kv := strings.SplitN(v, "=", 2)
c[kv[0]] = os.ExpandEnv(kv[1])
}
return c
}

View File

@@ -112,7 +112,7 @@ func (p *publishcmd) route(path string, ff *funcfile) error {
Image: ff.Image,
Memory: ff.Memory,
Type_: ff.Type,
Config: ff.Config,
Config: expandEnvConfig(ff.Config),
},
}
@@ -129,6 +129,13 @@ func (p *publishcmd) route(path string, ff *funcfile) error {
return nil
}
func expandEnvConfig(configs map[string]string) map[string]string {
for k, v := range configs {
configs[k] = os.ExpandEnv(v)
}
return configs
}
func extractAppNameRoute(path string) (appName, route string) {
// The idea here is to extract the root-most directory name

View File

@@ -194,14 +194,10 @@ func (a *routesCmd) create(c *cli.Context) error {
Image: image,
Memory: c.Int64("memory"),
Type_: c.String("type"),
Config: extractEnvConfig(c.StringSlice("config")),
},
}
configs := make(map[string]string)
for _, v := range c.StringSlice("config") {
kv := strings.SplitN(v, "=", 2)
configs[kv[0]] = kv[1]
}
body.Route.Config = configs
wrapper, _, err := a.AppsAppRoutesPost(appName, body)
if err != nil {
return fmt.Errorf("error creating route: %v", err)