Skip to content

Commit

Permalink
functions: application updates no longer accept name in the body
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ucirello committed Dec 5, 2016
1 parent f7f1015 commit 671883c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
7 changes: 7 additions & 0 deletions api/server/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,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},
} {
router := testRouter(test.mock, &mqs.Mock{}, testRunner(t), tasks)

Expand Down
6 changes: 6 additions & 0 deletions api/server/apps_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ func handleAppUpdate(c *gin.Context) {
return
}

if wapp.App.Name != "" {
log.Debug(models.ErrAppsUpdate)
c.JSON(http.StatusForbidden, simpleError(models.ErrAppsUpdate))
return
}

wapp.App.Name = c.Param("app")

err = Api.FireAfterAppUpdate(ctx, wapp.App)
Expand Down
7 changes: 6 additions & 1 deletion docs/apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ 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.
2 changes: 1 addition & 1 deletion docs/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 671883c

Please # to comment.