From 3b16b7f1d8ec86cab4689661deb4ae5da66486e4 Mon Sep 17 00:00:00 2001 From: C Cirello Date: Wed, 7 Dec 2016 19:54:21 +0100 Subject: [PATCH] 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 --- api/models/app.go | 3 ++- api/server/apps_test.go | 7 +++++++ api/server/apps_update.go | 6 ++++++ docs/apps.md | 7 ++++++- docs/swagger.yml | 2 +- 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/api/models/app.go b/api/models/app.go index 25c552c1b..03505275e 100644 --- a/api/models/app.go +++ b/api/models/app.go @@ -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") ) diff --git a/api/server/apps_test.go b/api/server/apps_test.go index a46f979f7..e83b2eecc 100644 --- a/api/server/apps_test.go +++ b/api/server/apps_test.go @@ -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) diff --git a/api/server/apps_update.go b/api/server/apps_update.go index bb3925d84..2910d3c29 100644 --- a/api/server/apps_update.go +++ b/api/server/apps_update.go @@ -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) diff --git a/docs/apps.md b/docs/apps.md index f9fb020f4..fdc8b3901 100644 --- a/docs/apps.md +++ b/docs/apps.md @@ -27,4 +27,9 @@ curl -H "Content-Type: application/json" -X POST -d '{ } } }' http://localhost:8080/v1/apps -``` \ No newline at end of file +``` + +## 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. \ No newline at end of file diff --git a/docs/swagger.yml b/docs/swagger.yml index 460f161dd..16d7653b4 100644 --- a/docs/swagger.yml +++ b/docs/swagger.yml @@ -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