mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-30 02:02:43 +00:00
If standbyok/perfstandbyok are provided to sys/health, honor the values (#7749)
Don't just use the presence of it to indicate behavior. Fixes #7323 Also, fixes a bug where if an error was returned along with a status code, the status code was being ignored.
This commit is contained in:
committed by
Brian Kassouf
parent
f611e58c2a
commit
eb1f426285
@@ -8,7 +8,9 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/errwrap"
|
||||
"github.com/hashicorp/vault/sdk/helper/consts"
|
||||
"github.com/hashicorp/vault/sdk/helper/parseutil"
|
||||
"github.com/hashicorp/vault/sdk/version"
|
||||
"github.com/hashicorp/vault/vault"
|
||||
)
|
||||
@@ -43,7 +45,7 @@ func handleSysHealthGet(core *vault.Core, w http.ResponseWriter, r *http.Request
|
||||
code, body, err := getSysHealth(core, r)
|
||||
if err != nil {
|
||||
core.Logger().Error("error checking health", "error", err)
|
||||
respondError(w, http.StatusInternalServerError, nil)
|
||||
respondError(w, code, nil)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -62,9 +64,6 @@ func handleSysHealthGet(core *vault.Core, w http.ResponseWriter, r *http.Request
|
||||
|
||||
func handleSysHealthHead(core *vault.Core, w http.ResponseWriter, r *http.Request) {
|
||||
code, body, err := getSysHealth(core, r)
|
||||
if err != nil {
|
||||
code = http.StatusInternalServerError
|
||||
}
|
||||
|
||||
if body != nil {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
@@ -73,9 +72,23 @@ func handleSysHealthHead(core *vault.Core, w http.ResponseWriter, r *http.Reques
|
||||
}
|
||||
|
||||
func getSysHealth(core *vault.Core, r *http.Request) (int, *HealthResponse, error) {
|
||||
var err error
|
||||
|
||||
// Check if being a standby is allowed for the purpose of a 200 OK
|
||||
_, standbyOK := r.URL.Query()["standbyok"]
|
||||
_, perfStandbyOK := r.URL.Query()["perfstandbyok"]
|
||||
standbyOKStr, standbyOK := r.URL.Query()["standbyok"]
|
||||
if standbyOK {
|
||||
standbyOK, err = parseutil.ParseBool(standbyOKStr[0])
|
||||
if err != nil {
|
||||
return http.StatusBadRequest, nil, errwrap.Wrapf("bad value for standbyok parameter: {{err}}", err)
|
||||
}
|
||||
}
|
||||
perfStandbyOKStr, perfStandbyOK := r.URL.Query()["perfstandbyok"]
|
||||
if perfStandbyOK {
|
||||
perfStandbyOK, err = parseutil.ParseBool(perfStandbyOKStr[0])
|
||||
if err != nil {
|
||||
return http.StatusBadRequest, nil, errwrap.Wrapf("bad value for perfstandbyok parameter: {{err}}", err)
|
||||
}
|
||||
}
|
||||
|
||||
uninitCode := http.StatusNotImplemented
|
||||
if code, found, ok := fetchStatusCode(r, "uninitcode"); !ok {
|
||||
|
||||
Reference in New Issue
Block a user