http: deprecate errwrap.Wrapf() (#11471)

This commit is contained in:
Lars Lehtonen
2021-04-26 10:33:48 -07:00
committed by GitHub
parent 5223d75035
commit 36be41d2c3
5 changed files with 14 additions and 15 deletions

View File

@@ -382,7 +382,7 @@ func WrapForwardedForHandler(h http.Handler, l *configutil.Listener) http.Handle
h.ServeHTTP(w, r) h.ServeHTTP(w, r)
return return
} }
respondError(w, http.StatusBadRequest, errwrap.Wrapf("error parsing client hostport: {{err}}", err)) respondError(w, http.StatusBadRequest, fmt.Errorf("error parsing client hostport: %w", err))
return return
} }
@@ -393,7 +393,7 @@ func WrapForwardedForHandler(h http.Handler, l *configutil.Listener) http.Handle
h.ServeHTTP(w, r) h.ServeHTTP(w, r)
return return
} }
respondError(w, http.StatusBadRequest, errwrap.Wrapf("error parsing client address: {{err}}", err)) respondError(w, http.StatusBadRequest, fmt.Errorf("error parsing client address: %w", err))
return return
} }
@@ -459,7 +459,7 @@ func wrappingVerificationFunc(ctx context.Context, core *vault.Core, req *logica
valid, err := core.ValidateWrappingToken(ctx, req) valid, err := core.ValidateWrappingToken(ctx, req)
if err != nil { if err != nil {
return errwrap.Wrapf("error validating wrapping token: {{err}}", err) return fmt.Errorf("error validating wrapping token: %w", err)
} }
if !valid { if !valid {
return consts.ErrInvalidWrappingToken return consts.ErrInvalidWrappingToken
@@ -655,7 +655,7 @@ func parseJSONRequest(perfStandby bool, r *http.Request, w http.ResponseWriter,
} }
err := jsonutil.DecodeJSONFromReader(reader, out) err := jsonutil.DecodeJSONFromReader(reader, out)
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
return nil, errwrap.Wrapf("failed to parse JSON input: {{err}}", err) return nil, fmt.Errorf("failed to parse JSON input: %w", err)
} }
if origBody != nil { if origBody != nil {
return ioutil.NopCloser(origBody), err return ioutil.NopCloser(origBody), err

View File

@@ -1,6 +1,7 @@
package http package http
import ( import (
"fmt"
"net/http" "net/http"
"github.com/hashicorp/errwrap" "github.com/hashicorp/errwrap"
@@ -44,7 +45,7 @@ func handleHelp(core *vault.Core, w http.ResponseWriter, r *http.Request) {
respondError(w, http.StatusForbidden, nil) respondError(w, http.StatusForbidden, nil)
return return
} }
respondError(w, http.StatusBadRequest, errwrap.Wrapf("error performing token check: {{err}}", err)) respondError(w, http.StatusBadRequest, fmt.Errorf("error performing token check: %w", err))
return return
} }

View File

@@ -153,7 +153,7 @@ func buildLogicalRequestNoAuth(perfStandby bool, w http.ResponseWriter, r *http.
requestId, err := uuid.GenerateUUID() requestId, err := uuid.GenerateUUID()
if err != nil { if err != nil {
return nil, nil, http.StatusBadRequest, errwrap.Wrapf("failed to generate identifier for the request: {{err}}", err) return nil, nil, http.StatusBadRequest, fmt.Errorf("failed to generate identifier for the request: %w", err)
} }
req := &logical.Request{ req := &logical.Request{
@@ -230,22 +230,22 @@ func buildLogicalRequest(core *vault.Core, w http.ResponseWriter, r *http.Reques
if errwrap.Contains(err, logical.ErrPermissionDenied.Error()) { if errwrap.Contains(err, logical.ErrPermissionDenied.Error()) {
return nil, nil, http.StatusForbidden, nil return nil, nil, http.StatusForbidden, nil
} }
return nil, nil, http.StatusBadRequest, errwrap.Wrapf("error performing token check: {{err}}", err) return nil, nil, http.StatusBadRequest, fmt.Errorf("error performing token check: %w", err)
} }
req, err = requestWrapInfo(r, req) req, err = requestWrapInfo(r, req)
if err != nil { if err != nil {
return nil, nil, http.StatusBadRequest, errwrap.Wrapf("error parsing X-Vault-Wrap-TTL header: {{err}}", err) return nil, nil, http.StatusBadRequest, fmt.Errorf("error parsing X-Vault-Wrap-TTL header: %w", err)
} }
err = parseMFAHeader(req) err = parseMFAHeader(req)
if err != nil { if err != nil {
return nil, nil, http.StatusBadRequest, errwrap.Wrapf("failed to parse X-Vault-MFA header: {{err}}", err) return nil, nil, http.StatusBadRequest, fmt.Errorf("failed to parse X-Vault-MFA header: %w", err)
} }
err = requestPolicyOverride(r, req) err = requestPolicyOverride(r, req)
if err != nil { if err != nil {
return nil, nil, http.StatusBadRequest, errwrap.Wrapf(fmt.Sprintf(`failed to parse %s header: {{err}}`, PolicyOverrideHeaderName), err) return nil, nil, http.StatusBadRequest, fmt.Errorf("failed to parse %s header: %w", PolicyOverrideHeaderName, err)
} }
return req, origBody, 0, nil return req, origBody, 0, nil

View File

@@ -8,7 +8,6 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/vault/sdk/helper/consts" "github.com/hashicorp/vault/sdk/helper/consts"
"github.com/hashicorp/vault/sdk/helper/parseutil" "github.com/hashicorp/vault/sdk/helper/parseutil"
"github.com/hashicorp/vault/sdk/version" "github.com/hashicorp/vault/sdk/version"
@@ -79,14 +78,14 @@ func getSysHealth(core *vault.Core, r *http.Request) (int, *HealthResponse, erro
if standbyOK { if standbyOK {
standbyOK, err = parseutil.ParseBool(standbyOKStr[0]) standbyOK, err = parseutil.ParseBool(standbyOKStr[0])
if err != nil { if err != nil {
return http.StatusBadRequest, nil, errwrap.Wrapf("bad value for standbyok parameter: {{err}}", err) return http.StatusBadRequest, nil, fmt.Errorf("bad value for standbyok parameter: %w", err)
} }
} }
perfStandbyOKStr, perfStandbyOK := r.URL.Query()["perfstandbyok"] perfStandbyOKStr, perfStandbyOK := r.URL.Query()["perfstandbyok"]
if perfStandbyOK { if perfStandbyOK {
perfStandbyOK, err = parseutil.ParseBool(perfStandbyOKStr[0]) perfStandbyOK, err = parseutil.ParseBool(perfStandbyOKStr[0])
if err != nil { if err != nil {
return http.StatusBadRequest, nil, errwrap.Wrapf("bad value for perfstandbyok parameter: {{err}}", err) return http.StatusBadRequest, nil, fmt.Errorf("bad value for perfstandbyok parameter: %w", err)
} }
} }

View File

@@ -8,7 +8,6 @@ import (
"github.com/hashicorp/vault/sdk/logical" "github.com/hashicorp/vault/sdk/logical"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/vault/helper/namespace" "github.com/hashicorp/vault/helper/namespace"
"github.com/hashicorp/vault/vault" "github.com/hashicorp/vault/vault"
"github.com/hashicorp/vault/vault/quotas" "github.com/hashicorp/vault/vault/quotas"
@@ -69,7 +68,7 @@ func rateLimitQuotaWrapping(handler http.Handler, core *vault.Core) http.Handler
} }
if !quotaResp.Allowed { if !quotaResp.Allowed {
quotaErr := errwrap.Wrapf(fmt.Sprintf("request path %q: {{err}}", path), quotas.ErrRateLimitQuotaExceeded) quotaErr := fmt.Errorf("request path %q: %w", path, quotas.ErrRateLimitQuotaExceeded)
respondError(w, http.StatusTooManyRequests, quotaErr) respondError(w, http.StatusTooManyRequests, quotaErr)
if core.Logger().IsTrace() { if core.Logger().IsTrace() {