api: ensure all request body decode error return a 400 status code. (#15252)
This commit is contained in:
parent
b28494ec9a
commit
3225cf77b6
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:bug
|
||||||
|
api: Ensure all request body decode errors return a 400 status code
|
||||||
|
```
|
|
@ -73,7 +73,7 @@ func (s *HTTPServer) aclPolicyUpdate(resp http.ResponseWriter, req *http.Request
|
||||||
// Parse the policy
|
// Parse the policy
|
||||||
var policy structs.ACLPolicy
|
var policy structs.ACLPolicy
|
||||||
if err := decodeBody(req, &policy); err != nil {
|
if err := decodeBody(req, &policy); err != nil {
|
||||||
return nil, CodedError(500, err.Error())
|
return nil, CodedError(http.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the policy name matches
|
// Ensure the policy name matches
|
||||||
|
@ -244,7 +244,7 @@ func (s *HTTPServer) aclTokenUpdate(resp http.ResponseWriter, req *http.Request,
|
||||||
// Parse the token
|
// Parse the token
|
||||||
var token structs.ACLToken
|
var token structs.ACLToken
|
||||||
if err := decodeBody(req, &token); err != nil {
|
if err := decodeBody(req, &token); err != nil {
|
||||||
return nil, CodedError(500, err.Error())
|
return nil, CodedError(http.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the token accessor matches
|
// Ensure the token accessor matches
|
||||||
|
@ -311,7 +311,7 @@ func (s *HTTPServer) ExchangeOneTimeToken(resp http.ResponseWriter, req *http.Re
|
||||||
|
|
||||||
var args structs.OneTimeTokenExchangeRequest
|
var args structs.OneTimeTokenExchangeRequest
|
||||||
if err := decodeBody(req, &args); err != nil {
|
if err := decodeBody(req, &args); err != nil {
|
||||||
return nil, CodedError(500, err.Error())
|
return nil, CodedError(http.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
s.parseWriteRequest(req, &args.WriteRequest)
|
s.parseWriteRequest(req, &args.WriteRequest)
|
||||||
|
|
|
@ -509,17 +509,17 @@ func (s *HTTPServer) KeyringOperationRequest(resp http.ResponseWriter, req *http
|
||||||
sresp, err = kmgr.ListKeys()
|
sresp, err = kmgr.ListKeys()
|
||||||
case "install":
|
case "install":
|
||||||
if err := decodeBody(req, &args); err != nil {
|
if err := decodeBody(req, &args); err != nil {
|
||||||
return nil, CodedError(500, err.Error())
|
return nil, CodedError(http.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
sresp, err = kmgr.InstallKey(args.Key)
|
sresp, err = kmgr.InstallKey(args.Key)
|
||||||
case "use":
|
case "use":
|
||||||
if err := decodeBody(req, &args); err != nil {
|
if err := decodeBody(req, &args); err != nil {
|
||||||
return nil, CodedError(500, err.Error())
|
return nil, CodedError(http.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
sresp, err = kmgr.UseKey(args.Key)
|
sresp, err = kmgr.UseKey(args.Key)
|
||||||
case "remove":
|
case "remove":
|
||||||
if err := decodeBody(req, &args); err != nil {
|
if err := decodeBody(req, &args); err != nil {
|
||||||
return nil, CodedError(500, err.Error())
|
return nil, CodedError(http.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
sresp, err = kmgr.RemoveKey(args.Key)
|
sresp, err = kmgr.RemoveKey(args.Key)
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -80,7 +80,7 @@ func (s *HTTPServer) namespaceUpdate(resp http.ResponseWriter, req *http.Request
|
||||||
// Parse the namespace
|
// Parse the namespace
|
||||||
var namespace structs.Namespace
|
var namespace structs.Namespace
|
||||||
if err := decodeBody(req, &namespace); err != nil {
|
if err := decodeBody(req, &namespace); err != nil {
|
||||||
return nil, CodedError(500, err.Error())
|
return nil, CodedError(http.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the namespace name matches
|
// Ensure the namespace name matches
|
||||||
|
|
Loading…
Reference in New Issue