functions: returns HTTP error in case of route update attempt (#396)

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
This commit is contained in:
C Cirello
2016-12-07 19:54:09 +01:00
committed by GitHub
parent 05cd030bc6
commit 66d446b148
5 changed files with 45 additions and 6 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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"))

21
docs/routes.md Normal file
View File

@@ -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.

View File

@@ -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