mirror of https://github.com/hashicorp/consul
agent: use strconv.ParseBool for parsing maintenance enable flag
parent
d89af51eb6
commit
9c69dc05fb
|
@ -5,6 +5,7 @@ import (
|
||||||
"github.com/hashicorp/consul/consul/structs"
|
"github.com/hashicorp/consul/consul/structs"
|
||||||
"github.com/hashicorp/serf/serf"
|
"github.com/hashicorp/serf/serf"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -210,20 +211,14 @@ func (s *HTTPServer) AgentServiceMaintenance(resp http.ResponseWriter, req *http
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var enable bool
|
|
||||||
raw := params.Get("enable")
|
raw := params.Get("enable")
|
||||||
switch raw {
|
enable, err := strconv.ParseBool(raw)
|
||||||
case "true":
|
if err != nil {
|
||||||
enable = true
|
|
||||||
case "false":
|
|
||||||
enable = false
|
|
||||||
default:
|
|
||||||
resp.WriteHeader(400)
|
resp.WriteHeader(400)
|
||||||
resp.Write([]byte(fmt.Sprintf("Invalid value for enable: %q", raw)))
|
resp.Write([]byte(fmt.Sprintf("Invalid value for enable: %q", raw)))
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
|
||||||
if enable {
|
if enable {
|
||||||
if err = s.agent.EnableServiceMaintenance(serviceID); err != nil {
|
if err = s.agent.EnableServiceMaintenance(serviceID); err != nil {
|
||||||
resp.WriteHeader(404)
|
resp.WriteHeader(404)
|
||||||
|
@ -253,14 +248,9 @@ func (s *HTTPServer) AgentNodeMaintenance(resp http.ResponseWriter, req *http.Re
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var enable bool
|
|
||||||
raw := params.Get("enable")
|
raw := params.Get("enable")
|
||||||
switch raw {
|
enable, err := strconv.ParseBool(raw)
|
||||||
case "true":
|
if err != nil {
|
||||||
enable = true
|
|
||||||
case "false":
|
|
||||||
enable = false
|
|
||||||
default:
|
|
||||||
resp.WriteHeader(400)
|
resp.WriteHeader(400)
|
||||||
resp.Write([]byte(fmt.Sprintf("Invalid value for enable: %q", raw)))
|
resp.Write([]byte(fmt.Sprintf("Invalid value for enable: %q", raw)))
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
Loading…
Reference in New Issue