mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Add fn publish fallback option to extract appname and path (#351)
* Add fn publish fallback option to extract appname and path * Add todo for fn publish hack
This commit is contained in:
committed by
C Cirello
parent
cee09cbb83
commit
c085f5c098
@@ -5,7 +5,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
functions "github.com/iron-io/functions_go"
|
||||
"github.com/urfave/cli"
|
||||
@@ -92,13 +92,17 @@ func (p *publishcmd) route(path string, ff *funcfile) error {
|
||||
return fmt.Errorf("error setting endpoint: %v", err)
|
||||
}
|
||||
|
||||
an, r := extractAppNameRoute(path)
|
||||
// TODO: This is just a nasty hack and should be cleaned up all the way
|
||||
pathsSplit := strings.Split(ff.FullName(), "/")
|
||||
|
||||
if ff.App == nil {
|
||||
ff.App = &an
|
||||
ff.App = &pathsSplit[0]
|
||||
}
|
||||
if ff.Route == nil {
|
||||
ff.Route = &r
|
||||
path := "/" + strings.Split(pathsSplit[1], ":")[0]
|
||||
ff.Route = &path
|
||||
}
|
||||
|
||||
if ff.Memory == nil {
|
||||
ff.Memory = new(int64)
|
||||
}
|
||||
@@ -108,11 +112,12 @@ func (p *publishcmd) route(path string, ff *funcfile) error {
|
||||
|
||||
body := functions.RouteWrapper{
|
||||
Route: functions.Route{
|
||||
Path: *ff.Route,
|
||||
Image: ff.FullName(),
|
||||
Memory: *ff.Memory,
|
||||
Type_: *ff.Type,
|
||||
Config: expandEnvConfig(ff.Config),
|
||||
Path: *ff.Route,
|
||||
Image: ff.FullName(),
|
||||
AppName: *ff.App,
|
||||
Memory: *ff.Memory,
|
||||
Type_: *ff.Type,
|
||||
Config: expandEnvConfig(ff.Config),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -136,20 +141,6 @@ func expandEnvConfig(configs map[string]string) map[string]string {
|
||||
return configs
|
||||
}
|
||||
|
||||
func extractAppNameRoute(path string) (appName, route string) {
|
||||
|
||||
// The idea here is to extract the root-most directory name
|
||||
// as application name, it turns out that stdlib tools are great to
|
||||
// extract the deepest one. Thus, we revert the string and use the
|
||||
// stdlib as it is - and revert back to its normal content. Not fastest
|
||||
// ever, but it is simple.
|
||||
|
||||
rpath := reverse(path)
|
||||
rroute, rappName := filepath.Split(rpath)
|
||||
route = filepath.Dir(reverse(rroute))
|
||||
return reverse(rappName), route
|
||||
}
|
||||
|
||||
func reverse(s string) string {
|
||||
r := []rune(s)
|
||||
for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
|
||||
|
||||
Reference in New Issue
Block a user