mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
functions: application updates no longer accept name in the body (#391)
* functions: application updates no longer accept name in the body AppUpdate was initially conceived as an upsert endpoint for apps. It turns out that it created an inconsistency regarding updates: updates with names divergent with URL would not actually change application's name. This commit atempts to address the issue by returning an HTTP error when trying to update an application name. In swagger.yml, application names are already `readOnly:true`. Thus there is no change from expected behavior. Fixes #380 * functions: use specific error value for name change
This commit is contained in:
@@ -13,11 +13,12 @@ var (
|
||||
ErrAppsGet = errors.New("Could not get app from datastore")
|
||||
ErrAppsList = errors.New("Could not list apps from datastore")
|
||||
ErrAppsMissingNew = errors.New("Missing new application")
|
||||
ErrAppsNameImmutable = errors.New("Could not update app - name is immutable")
|
||||
ErrAppsNotFound = errors.New("App not found")
|
||||
ErrAppsNothingToUpdate = errors.New("Nothing to update")
|
||||
ErrAppsRemoving = errors.New("Could not remove app from datastore")
|
||||
ErrDeleteAppsWithRoutes = errors.New("Cannot remove apps with routes")
|
||||
ErrAppsUpdate = errors.New("Could not update app")
|
||||
ErrDeleteAppsWithRoutes = errors.New("Cannot remove apps with routes")
|
||||
ErrUsableImage = errors.New("Image not found")
|
||||
)
|
||||
|
||||
|
||||
@@ -220,6 +220,13 @@ func TestAppUpdate(t *testing.T) {
|
||||
Name: "myapp",
|
||||
}},
|
||||
}, "/v1/apps/myapp", `{ "app": { "config": { "test": "1" } } }`, http.StatusOK, nil},
|
||||
|
||||
// Addresses #380
|
||||
{&datastore.Mock{
|
||||
Apps: []*models.App{{
|
||||
Name: "myapp",
|
||||
}},
|
||||
}, "/v1/apps/myapp", `{ "app": { "name": "othername" } }`, http.StatusForbidden, nil},
|
||||
} {
|
||||
rnr, cancel := testRunner(t)
|
||||
router := testRouter(test.mock, &mqs.Mock{}, rnr, tasks)
|
||||
|
||||
@@ -28,6 +28,12 @@ func handleAppUpdate(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if wapp.App.Name != "" {
|
||||
log.Debug(models.ErrAppsNameImmutable)
|
||||
c.JSON(http.StatusForbidden, simpleError(models.ErrAppsNameImmutable))
|
||||
return
|
||||
}
|
||||
|
||||
wapp.App.Name = c.Param("app")
|
||||
|
||||
err = Api.FireAfterAppUpdate(ctx, wapp.App)
|
||||
|
||||
@@ -28,3 +28,8 @@ curl -H "Content-Type: application/json" -X POST -d '{
|
||||
}
|
||||
}' http://localhost:8080/v1/apps
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
App names are immutable. When doing `PUT` calls, keep in mind that although you
|
||||
are able to update an app's configuration set, you cannot really rename it.
|
||||
@@ -116,7 +116,7 @@ paths:
|
||||
schema:
|
||||
$ref: '#/definitions/Error'
|
||||
put:
|
||||
summary: "Create/update a app."
|
||||
summary: "Updates an app."
|
||||
description: "You can set app level settings here. "
|
||||
tags:
|
||||
- Apps
|
||||
|
||||
Reference in New Issue
Block a user