Skip to content

Commit

Permalink
functions: returns HTTP error in case of route update attempt (#396)
Browse files Browse the repository at this point in the history
Ensure that attempts to update route's path are properly handled
with a HTTP error. Moreover, updates swagger file to make it
explicit that routes are immutable.

Fixes #381
  • Loading branch information
ccirello authored Dec 7, 2016
1 parent 05cd030 commit 66d446b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
11 changes: 6 additions & 5 deletions api/models/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ const (
)

var (
ErrInvalidPayload = errors.New("Invalid payload")
ErrRoutesAlreadyExists = errors.New("Route already exists")
ErrRoutesCreate = errors.New("Could not create route")
ErrRoutesUpdate = errors.New("Could not update route")
ErrRoutesRemoving = errors.New("Could not remove route from datastore")
ErrRoutesGet = errors.New("Could not get route from datastore")
ErrRoutesList = errors.New("Could not list routes from datastore")
ErrRoutesAlreadyExists = errors.New("Route already exists")
ErrRoutesNotFound = errors.New("Route not found")
ErrRoutesMissingNew = errors.New("Missing new route")
ErrInvalidPayload = errors.New("Invalid payload")
ErrRoutesNotFound = errors.New("Route not found")
ErrRoutesPathImmutable = errors.New("Could not update route - path is immutable")
ErrRoutesRemoving = errors.New("Could not remove route from datastore")
ErrRoutesUpdate = errors.New("Could not update route")
)

type Routes []*Route
Expand Down
12 changes: 11 additions & 1 deletion api/server/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,17 @@ func TestRouteUpdate(t *testing.T) {
Path: "/myroute/do",
},
},
}, "/v1/apps/a/routes/myroute/do", `{ "route": { "image": "iron/hello", "path": "/myroute" } }`, http.StatusOK, nil},
}, "/v1/apps/a/routes/myroute/do", `{ "route": { "image": "iron/hello" } }`, http.StatusOK, nil},

// Addresses #381
{&datastore.Mock{
Routes: []*models.Route{
{
AppName: "a",
Path: "/myroute/do",
},
},
}, "/v1/apps/a/routes/myroute/do", `{ "route": { "path": "/otherpath" } }`, http.StatusForbidden, nil},
} {
rnr, cancel := testRunner(t)
router := testRouter(test.ds, &mqs.Mock{}, rnr, tasks)
Expand Down
6 changes: 6 additions & 0 deletions api/server/routes_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ func handleRouteUpdate(c *gin.Context) {
return
}

if wroute.Route.Path != "" {
log.Debug(models.ErrRoutesPathImmutable)
c.JSON(http.StatusForbidden, simpleError(models.ErrRoutesPathImmutable))
return
}

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

Expand Down
21 changes: 21 additions & 0 deletions docs/routes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Routes

Each application has several functions represented through routes.

## Route level configuration

When creating or updating an app, you can pass in a map of config variables.

`config` is a map of values passed to the route runtime in the form of
environment variables.

Note: Route level configuration overrides app level configuration.

```sh
fn routes create --config k1=v1 --config k2=v2 myapp /path image
```

## Notes

Route paths are immutable. If you need to change them, the appropriate approach
is to add a new route with the modified path.
1 change: 1 addition & 0 deletions docs/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ definitions:
path:
type: string
description: URL path that will be matched to this route
readOnly: true
image:
description: Name of Docker image to use in this route. You should include the image tag, which should be a version number, to be more accurate. Can be overridden on a per route basis with route.image.
type: string
Expand Down

0 comments on commit 66d446b

Please # to comment.