Skip to content

Commit

Permalink
fn: fix update operations
Browse files Browse the repository at this point in the history
- No longer delete-than-add for configuration updates
- Path cleaning before most of routes operations
  • Loading branch information
ucirello committed Nov 21, 2016
1 parent aa32d1b commit 2d9b76e
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 32 deletions.
3 changes: 2 additions & 1 deletion api/server/routes_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server
import (
"context"
"net/http"
"path"

"github.com/gin-gonic/gin"
"github.com/iron-io/functions/api/models"
Expand All @@ -14,7 +15,7 @@ func handleRouteDelete(c *gin.Context) {
log := common.Logger(ctx)

appName := c.Param("app")
routePath := c.Param("route")
routePath := path.Clean(c.Param("route"))

route, err := Api.Datastore.GetRoute(appName, routePath)
if err != nil || route == nil {
Expand Down
3 changes: 2 additions & 1 deletion api/server/routes_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server
import (
"context"
"net/http"
"path"

"github.com/Sirupsen/logrus"
"github.com/gin-gonic/gin"
Expand All @@ -15,7 +16,7 @@ func handleRouteGet(c *gin.Context) {
log := common.Logger(ctx)

appName := c.Param("app")
routePath := c.Param("route")
routePath := path.Clean(c.Param("route"))

route, err := Api.Datastore.GetRoute(appName, routePath)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion api/server/routes_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server
import (
"context"
"net/http"
"path"

"github.com/gin-gonic/gin"
"github.com/iron-io/functions/api/models"
Expand Down Expand Up @@ -30,7 +31,7 @@ func handleRouteUpdate(c *gin.Context) {
}

wroute.Route.AppName = c.Param("app")
wroute.Route.Path = c.Param("route")
wroute.Route.Path = path.Clean(c.Param("route"))

if wroute.Route.Image != "" {
err = Api.Runner.EnsureImageExists(ctx, &runner.Config{
Expand Down
41 changes: 40 additions & 1 deletion docs/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ swagger: '2.0'
info:
title: IronFunctions
description: The open source serverless platform.
version: "0.1.0"
version: "0.1.16"
# the domain of the service
host: "127.0.0.1:8080"
# array of all schemes that your API supports
Expand Down Expand Up @@ -184,6 +184,45 @@ paths:
$ref: '#/definitions/Error'

/apps/{app}/routes/{route}:
put:
summary: Update a Route
description: Update a route
tags:
- Routes
parameters:
- name: app
in: path
description: name of the app.
required: true
type: string
- name: route
in: path
description: route path.
required: true
type: string
- name: body
in: body
description: One route to post.
required: true
schema:
$ref: '#/definitions/RouteWrapper'
responses:
201:
description: Route updated
schema:
$ref: '#/definitions/RouteWrapper'
400:
description: One or more of the routes were invalid due to parameters being missing or invalid.
schema:
$ref: '#/definitions/Error'
500:
description: Could not accept routes due to internal error.
schema:
$ref: '#/definitions/Error'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
get:
summary: Gets route by name
description: Gets a route by name.
Expand Down
10 changes: 5 additions & 5 deletions fn/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func apps() cli.Command {
}

func (a *appsCmd) list(c *cli.Context) error {
if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand All @@ -110,7 +110,7 @@ func (a *appsCmd) create(c *cli.Context) error {
return errors.New("error: app creating takes one argument, an app name")
}

if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand All @@ -132,7 +132,7 @@ func (a *appsCmd) configList(c *cli.Context) error {
return errors.New("error: app description takes one argument, an app name")
}

if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand Down Expand Up @@ -172,7 +172,7 @@ func (a *appsCmd) configSet(c *cli.Context) error {
return errors.New("error: application configuration setting takes three arguments: an app name, a key and a value")
}

if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand Down Expand Up @@ -206,7 +206,7 @@ func (a *appsCmd) configUnset(c *cli.Context) error {
return errors.New("error: application configuration setting takes three arguments: an app name, a key and a value")
}

if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand Down
6 changes: 3 additions & 3 deletions fn/glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions fn/glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import:
subpackages:
- bump
- storage
- package: github.com/iron-io/functions_go
version: 7f5bf75abece5380e916b594e17a552be365276d
- package: github.com/iron-io/iron_go3
subpackages:
- config
Expand All @@ -20,3 +18,5 @@ import:
subpackages:
- ssh/terminal
- package: gopkg.in/yaml.v2
- package: github.com/iron-io/functions_go
version: 190cb886f033aac6d41e657eb91649b27cb52736
2 changes: 1 addition & 1 deletion fn/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (p publishcmd) dockerpush(ff *funcfile) error {
}

func (p *publishcmd) route(path string, ff *funcfile) error {
if err := resetBasePath(&p.Configuration); err != nil {
if err := resetBasePath(p.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand Down
26 changes: 9 additions & 17 deletions fn/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (a *routesCmd) list(c *cli.Context) error {
return errors.New("error: routes listing takes one argument, an app name")
}

if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand Down Expand Up @@ -167,7 +167,7 @@ func (a *routesCmd) call(c *cli.Context) error {
return errors.New("error: routes listing takes three arguments: an app name and a route")
}

if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand Down Expand Up @@ -222,7 +222,7 @@ func (a *routesCmd) create(c *cli.Context) error {
return errors.New("error: routes creation takes three arguments: an app name, a route path and an image")
}

if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand Down Expand Up @@ -269,7 +269,7 @@ func (a *routesCmd) delete(c *cli.Context) error {
return errors.New("error: routes listing takes three arguments: an app name and a path")
}

if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand All @@ -294,7 +294,7 @@ func (a *routesCmd) configList(c *cli.Context) error {
return errors.New("error: route configuration description takes two arguments: an app name and a route")
}

if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand Down Expand Up @@ -339,7 +339,7 @@ func (a *routesCmd) configSet(c *cli.Context) error {
return errors.New("error: route configuration setting takes four arguments: an app name, a route, a key and a value")
}

if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand All @@ -366,11 +366,7 @@ func (a *routesCmd) configSet(c *cli.Context) error {
config[key] = value
wrapper.Route.Config = config

if _, err := a.AppsAppRoutesRouteDelete(appName, route); err != nil {
return fmt.Errorf("error deleting to force update route: %v", err)
}

if _, _, err := a.AppsAppRoutesPost(appName, *wrapper); err != nil {
if _, _, err := a.AppsAppRoutesRoutePut(appName, route, *wrapper); err != nil {
return fmt.Errorf("error updating route configuration: %v", err)
}

Expand All @@ -383,7 +379,7 @@ func (a *routesCmd) configUnset(c *cli.Context) error {
return errors.New("error: route configuration setting takes four arguments: an app name, a route and a key")
}

if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand Down Expand Up @@ -413,11 +409,7 @@ func (a *routesCmd) configUnset(c *cli.Context) error {
delete(config, key)
wrapper.Route.Config = config

if _, err := a.AppsAppRoutesRouteDelete(appName, route); err != nil {
return fmt.Errorf("error deleting to force update route: %v", err)
}

if _, _, err := a.AppsAppRoutesPost(appName, *wrapper); err != nil {
if _, _, err := a.AppsAppRoutesRoutePut(appName, route, *wrapper); err != nil {
return fmt.Errorf("error updating route configuration: %v", err)
}

Expand Down

0 comments on commit 2d9b76e

Please # to comment.