mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Merge branch 'fnpatch' into 'master'
fixes fn set/unset for routes & apps Closes #80 See merge request !83
This commit is contained in:
49
fn/apps.go
49
fn/apps.go
@@ -7,7 +7,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
"github.com/funcy/functions_go"
|
|
||||||
fnclient "github.com/funcy/functions_go/client"
|
fnclient "github.com/funcy/functions_go/client"
|
||||||
apiapps "github.com/funcy/functions_go/client/apps"
|
apiapps "github.com/funcy/functions_go/client/apps"
|
||||||
"github.com/funcy/functions_go/models"
|
"github.com/funcy/functions_go/models"
|
||||||
@@ -165,7 +164,7 @@ func (a *appsCmd) create(c *cli.Context) error {
|
|||||||
func (a *appsCmd) update(c *cli.Context) error {
|
func (a *appsCmd) update(c *cli.Context) error {
|
||||||
appName := c.Args().First()
|
appName := c.Args().First()
|
||||||
|
|
||||||
patchedApp := &functions.App{
|
patchedApp := &models.App{
|
||||||
Config: extractEnvConfig(c.StringSlice("config")),
|
Config: extractEnvConfig(c.StringSlice("config")),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +182,7 @@ func (a *appsCmd) configSet(c *cli.Context) error {
|
|||||||
key := c.Args().Get(1)
|
key := c.Args().Get(1)
|
||||||
value := c.Args().Get(2)
|
value := c.Args().Get(2)
|
||||||
|
|
||||||
app := &functions.App{
|
app := &models.App{
|
||||||
Config: make(map[string]string),
|
Config: make(map[string]string),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,11 +200,11 @@ func (a *appsCmd) configUnset(c *cli.Context) error {
|
|||||||
appName := c.Args().Get(0)
|
appName := c.Args().Get(0)
|
||||||
key := c.Args().Get(1)
|
key := c.Args().Get(1)
|
||||||
|
|
||||||
app := &functions.App{
|
app := &models.App{
|
||||||
Config: make(map[string]string),
|
Config: make(map[string]string),
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Config["-"+key] = ""
|
app.Config[key] = ""
|
||||||
|
|
||||||
if err := a.patchApp(appName, app); err != nil {
|
if err := a.patchApp(appName, app); err != nil {
|
||||||
return fmt.Errorf("error updating app configuration: %v", err)
|
return fmt.Errorf("error updating app configuration: %v", err)
|
||||||
@@ -215,45 +214,11 @@ func (a *appsCmd) configUnset(c *cli.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *appsCmd) patchApp(appName string, app *functions.App) error {
|
func (a *appsCmd) patchApp(appName string, app *models.App) error {
|
||||||
resp, err := a.client.Apps.GetAppsApp(&apiapps.GetAppsAppParams{
|
_, err := a.client.Apps.PatchAppsApp(&apiapps.PatchAppsAppParams{
|
||||||
Context: context.Background(),
|
Context: context.Background(),
|
||||||
App: appName,
|
App: appName,
|
||||||
})
|
Body: &models.AppWrapper{App: app},
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
switch err.(type) {
|
|
||||||
case *apiapps.GetAppsAppNotFound:
|
|
||||||
return fmt.Errorf("error: %v", err.(*apiapps.GetAppsAppNotFound).Payload.Error.Message)
|
|
||||||
case *apiapps.GetAppsAppDefault:
|
|
||||||
return fmt.Errorf("unexpected error: %v", err.(*apiapps.GetAppsAppDefault).Payload.Error.Message)
|
|
||||||
}
|
|
||||||
return fmt.Errorf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.Payload.App.Config == nil {
|
|
||||||
resp.Payload.App.Config = map[string]string{}
|
|
||||||
}
|
|
||||||
|
|
||||||
resp.Payload.App.Name = ""
|
|
||||||
if app != nil {
|
|
||||||
if app.Config != nil {
|
|
||||||
for k, v := range app.Config {
|
|
||||||
if string(k[0]) == "-" {
|
|
||||||
delete(resp.Payload.App.Config, string(k[1:]))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
resp.Payload.App.Config[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
body := &models.AppWrapper{App: resp.Payload.App}
|
|
||||||
|
|
||||||
_, err = a.client.Apps.PatchAppsApp(&apiapps.PatchAppsAppParams{
|
|
||||||
Context: context.Background(),
|
|
||||||
App: appName,
|
|
||||||
Body: body,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
72
fn/routes.go
72
fn/routes.go
@@ -299,7 +299,7 @@ func routeWithFuncFile(c *cli.Context, ff *funcfile, rt *fnmodels.Route) error {
|
|||||||
if rt.Path == "" && ff.Path != "" {
|
if rt.Path == "" && ff.Path != "" {
|
||||||
rt.Path = ff.Path
|
rt.Path = ff.Path
|
||||||
}
|
}
|
||||||
if rt.Type == nil && ff.Type != nil && *ff.Type != "" {
|
if rt.Type == "" && ff.Type != nil && *ff.Type != "" {
|
||||||
rt.Type = *ff.Type
|
rt.Type = *ff.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,75 +359,11 @@ func (a *routesCmd) postRoute(c *cli.Context, appName string, rt *fnmodels.Route
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *routesCmd) patchRoute(c *cli.Context, appName, routePath string, r *fnmodels.Route) error {
|
func (a *routesCmd) patchRoute(c *cli.Context, appName, routePath string, r *fnmodels.Route) error {
|
||||||
// TODO: this getting the old version and merging should be on the server side, not here on the client.
|
_, err := a.client.Routes.PatchAppsAppRoutesRoute(&apiroutes.PatchAppsAppRoutesRouteParams{
|
||||||
resp, err := a.client.Routes.GetAppsAppRoutesRoute(&apiroutes.GetAppsAppRoutesRouteParams{
|
|
||||||
Context: context.Background(),
|
Context: context.Background(),
|
||||||
App: appName,
|
App: appName,
|
||||||
Route: routePath,
|
Route: routePath,
|
||||||
})
|
Body: &fnmodels.RouteWrapper{Route: r},
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
switch err.(type) {
|
|
||||||
case *apiroutes.GetAppsAppRoutesRouteNotFound:
|
|
||||||
// return fmt.Errorf("error: %s", err.(*apiroutes.GetAppsAppRoutesRouteNotFound).Payload.Error.Message)
|
|
||||||
// then insert it
|
|
||||||
return a.postRoute(c, appName, r)
|
|
||||||
case *apiroutes.GetAppsAppRoutesDefault:
|
|
||||||
return fmt.Errorf("unexpected error: %s", err.(*apiroutes.GetAppsAppRoutesDefault).Payload.Error.Message)
|
|
||||||
}
|
|
||||||
return fmt.Errorf("unexpected error: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.Payload.Route.Config == nil {
|
|
||||||
resp.Payload.Route.Config = map[string]string{}
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.Payload.Route.Headers == nil {
|
|
||||||
resp.Payload.Route.Headers = map[string][]string{}
|
|
||||||
}
|
|
||||||
|
|
||||||
resp.Payload.Route.Path = ""
|
|
||||||
if r != nil {
|
|
||||||
if r.Config != nil {
|
|
||||||
for k, v := range r.Config {
|
|
||||||
if string(k[0]) == "-" {
|
|
||||||
delete(resp.Payload.Route.Config, string(k[1:]))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
resp.Payload.Route.Config[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if r.Headers != nil {
|
|
||||||
for k, v := range r.Headers {
|
|
||||||
if string(k[0]) == "-" {
|
|
||||||
delete(resp.Payload.Route.Headers, k)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
resp.Payload.Route.Headers[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if r.Image != "" {
|
|
||||||
resp.Payload.Route.Image = r.Image
|
|
||||||
}
|
|
||||||
if r.Format != "" {
|
|
||||||
resp.Payload.Route.Format = r.Format
|
|
||||||
}
|
|
||||||
if r.Type != "" {
|
|
||||||
resp.Payload.Route.Type = r.Type
|
|
||||||
}
|
|
||||||
if r.Memory > 0 {
|
|
||||||
resp.Payload.Route.Memory = r.Memory
|
|
||||||
}
|
|
||||||
if r.Timeout != nil {
|
|
||||||
resp.Payload.Route.Timeout = r.Timeout
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = a.client.Routes.PatchAppsAppRoutesRoute(&apiroutes.PatchAppsAppRoutesRouteParams{
|
|
||||||
Context: context.Background(),
|
|
||||||
App: appName,
|
|
||||||
Route: routePath,
|
|
||||||
Body: resp.Payload,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -496,7 +432,7 @@ func (a *routesCmd) configUnset(c *cli.Context) error {
|
|||||||
Config: make(map[string]string),
|
Config: make(map[string]string),
|
||||||
}
|
}
|
||||||
|
|
||||||
patchRoute.Config["-"+key] = ""
|
patchRoute.Config[key] = ""
|
||||||
|
|
||||||
err := a.patchRoute(c, appName, route, &patchRoute)
|
err := a.patchRoute(c, appName, route, &patchRoute)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user