Change "rotate_worker_token" to "rotateWorkerToken"

This renames the `rotate_xxx` flags to camelBack, for
consistency with other API query-params, such as
`detachKeys`, `noOverwriteDirNonDir`, and `fromImage`.

Also makes this flag accept a wider range of boolean
values ("0", "1", "true", "false"), and throw an error
if an invalid value is passed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit bd81df1278)
Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
Sebastiaan van Stijn 2016-07-22 14:06:03 +02:00 committed by Tibor Vass
parent 986a968044
commit b7a38b19b3
3 changed files with 19 additions and 7 deletions

View file

@ -67,11 +67,23 @@ func (sr *swarmRouter) updateCluster(ctx context.Context, w http.ResponseWriter,
}
var flags types.UpdateFlags
if r.URL.Query().Get("rotate_worker_token") == "true" {
flags.RotateWorkerToken = true
if value := r.URL.Query().Get("rotateWorkerToken"); value != "" {
rot, err := strconv.ParseBool(value)
if err != nil {
return fmt.Errorf("invalid value for rotateWorkerToken: %s", value)
}
flags.RotateWorkerToken = rot
}
if r.URL.Query().Get("rotate_manager_token") == "true" {
flags.RotateManagerToken = true
if value := r.URL.Query().Get("rotateManagerToken"); value != "" {
rot, err := strconv.ParseBool(value)
if err != nil {
return fmt.Errorf("invalid value for rotateManagerToken: %s", value)
}
flags.RotateManagerToken = rot
}
if err := sr.backend.Update(version, swarm, flags); err != nil {

View file

@ -3751,8 +3751,8 @@ Update a Swarm
- **version** The version number of the swarm object being updated. This is
required to avoid conflicting writes.
- **rotate_worker_token** - Set to `true` to rotate the worker join token.
- **rotate_manager_token** - Set to `true` to rotate the manager join token.
- **rotateWorkerToken** - Set to `true` (or `1`) to rotate the worker join token.
- **rotateManagerToken** - Set to `true` (or `1`) to rotate the manager join token.
**Status codes**:

View file

@ -270,7 +270,7 @@ func (d *SwarmDaemon) rotateTokens(c *check.C) {
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
c.Assert(json.Unmarshal(out, &sw), checker.IsNil)
url := fmt.Sprintf("/swarm/update?version=%d&rotate_worker_token=true&rotate_manager_token=true", sw.Version.Index)
url := fmt.Sprintf("/swarm/update?version=%d&rotateWorkerToken=true&rotateManagerToken=true", sw.Version.Index)
status, out, err = d.SockRequest("POST", url, sw.Spec)
c.Assert(err, checker.IsNil)
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))