mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
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:
@@ -4,7 +4,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
"github.com/iron-io/functions_go"
|
"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)
|
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{
|
body := functions.AppWrapper{App: functions.App{
|
||||||
Name: appName,
|
Name: c.Args().Get(0),
|
||||||
Config: configs,
|
Config: extractEnvConfig(c.StringSlice("config")),
|
||||||
}}
|
}}
|
||||||
wrapper, _, err := a.AppsPost(body)
|
wrapper, _, err := a.AppsPost(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -253,3 +254,12 @@ func (c commoncmd) dockerbuild(path, image string) error {
|
|||||||
|
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ func (p *publishcmd) route(path string, ff *funcfile) error {
|
|||||||
Image: ff.Image,
|
Image: ff.Image,
|
||||||
Memory: ff.Memory,
|
Memory: ff.Memory,
|
||||||
Type_: ff.Type,
|
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
|
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) {
|
func extractAppNameRoute(path string) (appName, route string) {
|
||||||
|
|
||||||
// The idea here is to extract the root-most directory name
|
// The idea here is to extract the root-most directory name
|
||||||
|
|||||||
@@ -194,14 +194,10 @@ func (a *routesCmd) create(c *cli.Context) error {
|
|||||||
Image: image,
|
Image: image,
|
||||||
Memory: c.Int64("memory"),
|
Memory: c.Int64("memory"),
|
||||||
Type_: c.String("type"),
|
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)
|
wrapper, _, err := a.AppsAppRoutesPost(appName, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error creating route: %v", err)
|
return fmt.Errorf("error creating route: %v", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user