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:
C Cirello
2016-12-07 19:54:21 +01:00
committed by GitHub
parent 66d446b148
commit 3b16b7f1d8
5 changed files with 22 additions and 3 deletions

View File

@@ -13,11 +13,12 @@ var (
ErrAppsGet = errors.New("Could not get app from datastore") ErrAppsGet = errors.New("Could not get app from datastore")
ErrAppsList = errors.New("Could not list apps from datastore") ErrAppsList = errors.New("Could not list apps from datastore")
ErrAppsMissingNew = errors.New("Missing new application") ErrAppsMissingNew = errors.New("Missing new application")
ErrAppsNameImmutable = errors.New("Could not update app - name is immutable")
ErrAppsNotFound = errors.New("App not found") ErrAppsNotFound = errors.New("App not found")
ErrAppsNothingToUpdate = errors.New("Nothing to update") ErrAppsNothingToUpdate = errors.New("Nothing to update")
ErrAppsRemoving = errors.New("Could not remove app from datastore") ErrAppsRemoving = errors.New("Could not remove app from datastore")
ErrDeleteAppsWithRoutes = errors.New("Cannot remove apps with routes")
ErrAppsUpdate = errors.New("Could not update app") ErrAppsUpdate = errors.New("Could not update app")
ErrDeleteAppsWithRoutes = errors.New("Cannot remove apps with routes")
ErrUsableImage = errors.New("Image not found") ErrUsableImage = errors.New("Image not found")
) )

View File

@@ -220,6 +220,13 @@ func TestAppUpdate(t *testing.T) {
Name: "myapp", Name: "myapp",
}}, }},
}, "/v1/apps/myapp", `{ "app": { "config": { "test": "1" } } }`, http.StatusOK, nil}, }, "/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) rnr, cancel := testRunner(t)
router := testRouter(test.mock, &mqs.Mock{}, rnr, tasks) router := testRouter(test.mock, &mqs.Mock{}, rnr, tasks)

View File

@@ -28,6 +28,12 @@ func handleAppUpdate(c *gin.Context) {
return return
} }
if wapp.App.Name != "" {
log.Debug(models.ErrAppsNameImmutable)
c.JSON(http.StatusForbidden, simpleError(models.ErrAppsNameImmutable))
return
}
wapp.App.Name = c.Param("app") wapp.App.Name = c.Param("app")
err = Api.FireAfterAppUpdate(ctx, wapp.App) err = Api.FireAfterAppUpdate(ctx, wapp.App)

View File

@@ -27,4 +27,9 @@ curl -H "Content-Type: application/json" -X POST -d '{
} }
} }
}' http://localhost:8080/v1/apps }' 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.

View File

@@ -116,7 +116,7 @@ paths:
schema: schema:
$ref: '#/definitions/Error' $ref: '#/definitions/Error'
put: put:
summary: "Create/update a app." summary: "Updates an app."
description: "You can set app level settings here. " description: "You can set app level settings here. "
tags: tags:
- Apps - Apps