From 5958a9cbdd22043f0fea5d2a7c751f4236820aca Mon Sep 17 00:00:00 2001 From: schmidtw Date: Thu, 24 Aug 2023 21:18:24 -0700 Subject: [PATCH] Replace emperrer in favor of the std error package. --- go.mod | 2 -- go.sum | 2 -- hashTokenFactory/hashTokenFactory.go | 13 +++++++------ 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index cc0d463..72bc4f0 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ go 1.19 require ( github.com/go-kit/kit v0.12.0 - github.com/goph/emperror v0.17.3-0.20190703203600-60a8d9faa17b github.com/prometheus/client_golang v1.16.0 github.com/stretchr/testify v1.8.4 github.com/xmidt-org/bascule v0.11.6 @@ -32,7 +31,6 @@ require ( github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect - github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_model v0.4.0 // indirect github.com/prometheus/common v0.42.0 // indirect diff --git a/go.sum b/go.sum index 8b1f9db..5f8254a 100644 --- a/go.sum +++ b/go.sum @@ -995,7 +995,6 @@ github.com/googleapis/gnostic v0.2.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTV github.com/googleapis/go-type-adapters v1.0.0/go.mod h1:zHW75FOG2aur7gAO2B+MLby+cLsWGBF62rFAi7WjWO4= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= github.com/goph/emperror v0.17.1/go.mod h1:+ZbQ+fUNO/6FNiUo0ujtMjhgad9Xa6fQL9KhH4LNHic= -github.com/goph/emperror v0.17.3-0.20190703203600-60a8d9faa17b h1:3/cwc6wu5QADzKEW2HP7+kZpKgm7OHysQ3ULVVQzQhs= github.com/goph/emperror v0.17.3-0.20190703203600-60a8d9faa17b/go.mod h1:+ZbQ+fUNO/6FNiUo0ujtMjhgad9Xa6fQL9KhH4LNHic= github.com/gophercloud/gophercloud v0.0.0-20180828235145-f29afc2cceca/go.mod h1:3WdhXV3rUYy9p6AUW8d94kr+HS62Y4VL9mBnFxsD8q4= github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= @@ -1374,7 +1373,6 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pkg/errors v0.8.1-0.20181008045315-2233dee583dc/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA= github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= diff --git a/hashTokenFactory/hashTokenFactory.go b/hashTokenFactory/hashTokenFactory.go index 1049c4f..95cf41c 100644 --- a/hashTokenFactory/hashTokenFactory.go +++ b/hashTokenFactory/hashTokenFactory.go @@ -9,12 +9,11 @@ import ( "crypto/hmac" "encoding/hex" "errors" + "fmt" "hash" "io" "net/http" - "github.com/goph/emperror" - "github.com/xmidt-org/bascule" ) @@ -58,7 +57,7 @@ func (htf H) ParseAndValidate(ctx context.Context, req *http.Request, _ bascule. msgBytes, err := io.ReadAll(req.Body) req.Body.Close() if err != nil { - return nil, codeError{http.StatusBadRequest, emperror.Wrap(err, "Could not read request body")} + return nil, codeError{http.StatusBadRequest, fmt.Errorf("%w: could not read request body", err)} } // Restore the io.ReadCloser to its original state @@ -66,18 +65,20 @@ func (htf H) ParseAndValidate(ctx context.Context, req *http.Request, _ bascule. secretGiven, err := hex.DecodeString(value) if err != nil { - return nil, codeError{http.StatusBadRequest, emperror.Wrap(err, "Could not decode signature")} + return nil, codeError{http.StatusBadRequest, fmt.Errorf("%w: could not decode signature", err)} } secret, err := htf.secretGetter.GetSecret() if err != nil { - return nil, codeError{http.StatusInternalServerError, emperror.Wrap(err, "Could not get secret")} + return nil, codeError{http.StatusInternalServerError, fmt.Errorf("%w: could not get secret", err)} } + h := hmac.New(htf.newFunc, []byte(secret)) h.Write(msgBytes) sig := h.Sum(nil) if !hmac.Equal(sig, secretGiven) { - return nil, codeError{http.StatusForbidden, emperror.With(errors.New("Invalid secret"), "secretGiven", secretGiven, "hashCalculated", sig, "body", msgBytes)} + err = fmt.Errorf("invalid secret: secretGiven: '%s', hashCalculated: '%s', body: '%s'", secretGiven, sig, msgBytes) + return nil, codeError{code: http.StatusForbidden, err: err} } return bascule.NewToken(htf.hashType, value, bascule.NewAttributes(map[string]interface{}{})), nil