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