Skip to content

Commit

Permalink
Merge pull request #118 from xmidt-org/remove-emperrer
Browse files Browse the repository at this point in the history
Replace emperrer in favor of the std error package.
  • Loading branch information
schmidtw authored Aug 25, 2023
2 parents 6d6a224 + 5958a9c commit eeffe9c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
13 changes: 7 additions & 6 deletions hashTokenFactory/hashTokenFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import (
"crypto/hmac"
"encoding/hex"
"errors"
"fmt"
"hash"
"io"
"net/http"

"github.com/goph/emperror"

"github.com/xmidt-org/bascule"
)

Expand Down Expand Up @@ -58,26 +57,28 @@ 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
req.Body = io.NopCloser(bytes.NewBuffer(msgBytes))

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
Expand Down

0 comments on commit eeffe9c

Please sign in to comment.