Skip to content

Commit

Permalink
remove github.com/pkg/errors
Browse files Browse the repository at this point in the history
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
  • Loading branch information
Iceber authored and ashutosh-narkar committed Jan 11, 2023
1 parent f543e60 commit 2131da3
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 49 deletions.
3 changes: 1 addition & 2 deletions ast/location/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package location

import (
"bytes"
"errors"
"fmt"

"github.com/pkg/errors"
)

// Location records a position in source code
Expand Down
2 changes: 1 addition & 1 deletion ast/term.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package ast
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"math"
Expand All @@ -20,7 +21,6 @@ import (
"sync"

"github.com/OneOfOne/xxhash"
"github.com/pkg/errors"

"github.com/open-policy-agent/opa/ast/location"
"github.com/open-policy-agent/opa/util"
Expand Down
3 changes: 1 addition & 2 deletions bundle/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"bytes"
"compress/gzip"
"encoding/json"
"errors"
"fmt"
"io"

Expand All @@ -18,8 +19,6 @@ import (
"strings"
"testing"

"github.com/pkg/errors"

"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/internal/file/archive"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
package cmd

import (
"errors"
"fmt"
"os"

"github.com/open-policy-agent/opa/dependencies"
"github.com/open-policy-agent/opa/internal/presentation"

"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/open-policy-agent/opa/ast"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ require (
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0-rc2
github.com/peterh/liner v0.0.0-20170211195444-bf27d3ba8e1d
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.14.0
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0
github.com/sirupsen/logrus v1.9.0
Expand Down Expand Up @@ -81,6 +80,7 @@ require (
github.com/moby/locker v1.0.1 // indirect
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
Expand Down
4 changes: 1 addition & 3 deletions internal/jwx/jwk/key_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package jwk
import (
"encoding/json"
"fmt"

"github.com/pkg/errors"
)

// KeyUsageType is used to denote what this key should be used for
Expand Down Expand Up @@ -46,7 +44,7 @@ func (keyOperationList *KeyOperationList) Accept(v interface{}) error {
*keyOperationList = x
return nil
default:
return errors.Errorf(`invalid value %T`, v)
return fmt.Errorf(`invalid value %T`, v)
}
}

Expand Down
8 changes: 4 additions & 4 deletions internal/jwx/jws/sign/hmac.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"crypto/hmac"
"crypto/sha256"
"crypto/sha512"
"errors"
"fmt"
"hash"

"github.com/open-policy-agent/opa/internal/jwx/jwa"

"github.com/pkg/errors"
)

var hmacSignFuncs = map[jwa.SignatureAlgorithm]hmacSignFunc{}
Expand All @@ -29,7 +29,7 @@ func init() {
func newHMAC(alg jwa.SignatureAlgorithm) (*HMACSigner, error) {
signer, ok := hmacSignFuncs[alg]
if !ok {
return nil, errors.Errorf(`unsupported algorithm while trying to create HMAC signer: %s`, alg)
return nil, fmt.Errorf(`unsupported algorithm while trying to create HMAC signer: %s`, alg)
}

return &HMACSigner{
Expand All @@ -55,7 +55,7 @@ func (s HMACSigner) Algorithm() jwa.SignatureAlgorithm {
func (s HMACSigner) Sign(payload []byte, key interface{}) ([]byte, error) {
hmackey, ok := key.([]byte)
if !ok {
return nil, errors.Errorf(`invalid key type %T. []byte is required`, key)
return nil, fmt.Errorf(`invalid key type %T. []byte is required`, key)
}

if len(hmackey) == 0 {
Expand Down
8 changes: 4 additions & 4 deletions internal/jwx/jws/sign/rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"crypto"
"crypto/rand"
"crypto/rsa"
"errors"
"fmt"

"github.com/open-policy-agent/opa/internal/jwx/jwa"

"github.com/pkg/errors"
)

var rsaSignFuncs = map[jwa.SignatureAlgorithm]rsaSignFunc{}
Expand Down Expand Up @@ -69,7 +69,7 @@ func makeSignPSS(hash crypto.Hash) rsaSignFunc {
func newRSA(alg jwa.SignatureAlgorithm) (*RSASigner, error) {
signfn, ok := rsaSignFuncs[alg]
if !ok {
return nil, errors.Errorf(`unsupported algorithm while trying to create RSA signer: %s`, alg)
return nil, fmt.Errorf(`unsupported algorithm while trying to create RSA signer: %s`, alg)
}
return &RSASigner{
alg: alg,
Expand All @@ -90,7 +90,7 @@ func (s RSASigner) Sign(payload []byte, key interface{}) ([]byte, error) {
}
rsakey, ok := key.(*rsa.PrivateKey)
if !ok {
return nil, errors.Errorf(`invalid key type %T. *rsa.PrivateKey is required`, key)
return nil, fmt.Errorf(`invalid key type %T. *rsa.PrivateKey is required`, key)
}

return s.sign(payload, rsakey)
Expand Down
6 changes: 2 additions & 4 deletions internal/jwx/jws/sign/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"encoding/pem"
"fmt"

"github.com/pkg/errors"

"github.com/open-policy-agent/opa/internal/jwx/jwa"
)

Expand All @@ -20,7 +18,7 @@ func New(alg jwa.SignatureAlgorithm) (Signer, error) {
case jwa.HS256, jwa.HS384, jwa.HS512:
return newHMAC(alg)
default:
return nil, errors.Errorf(`unsupported signature algorithm %s`, alg)
return nil, fmt.Errorf(`unsupported signature algorithm %s`, alg)
}
}

Expand Down Expand Up @@ -62,6 +60,6 @@ func GetSigningKey(key string, alg jwa.SignatureAlgorithm) (interface{}, error)
case jwa.HS256, jwa.HS384, jwa.HS512:
return []byte(key), nil
default:
return nil, errors.Errorf("unsupported signature algorithm: %s", alg)
return nil, fmt.Errorf("unsupported signature algorithm: %s", alg)
}
}
8 changes: 4 additions & 4 deletions internal/jwx/jws/verify/ecdsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package verify
import (
"crypto"
"crypto/ecdsa"
"errors"
"fmt"
"math/big"

"github.com/pkg/errors"

"github.com/open-policy-agent/opa/internal/jwx/jwa"
)

Expand Down Expand Up @@ -45,7 +45,7 @@ func makeECDSAVerifyFunc(hash crypto.Hash) ecdsaVerifyFunc {
func newECDSA(alg jwa.SignatureAlgorithm) (*ECDSAVerifier, error) {
verifyfn, ok := ecdsaVerifyFuncs[alg]
if !ok {
return nil, errors.Errorf(`unsupported algorithm while trying to create ECDSA verifier: %s`, alg)
return nil, fmt.Errorf(`unsupported algorithm while trying to create ECDSA verifier: %s`, alg)
}

return &ECDSAVerifier{
Expand All @@ -60,7 +60,7 @@ func (v ECDSAVerifier) Verify(payload []byte, signature []byte, key interface{})
}
ecdsakey, ok := key.(*ecdsa.PublicKey)
if !ok {
return errors.Errorf(`invalid key type %T. *ecdsa.PublicKey is required`, key)
return fmt.Errorf(`invalid key type %T. *ecdsa.PublicKey is required`, key)
}

return v.verify(payload, signature, ecdsakey)
Expand Down
2 changes: 1 addition & 1 deletion internal/jwx/jws/verify/hmac.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package verify

import (
"crypto/hmac"
"errors"
"fmt"

"github.com/open-policy-agent/opa/internal/jwx/jwa"
"github.com/open-policy-agent/opa/internal/jwx/jws/sign"
"github.com/pkg/errors"
)

func newHMAC(alg jwa.SignatureAlgorithm) (*HMACVerifier, error) {
Expand Down
8 changes: 4 additions & 4 deletions internal/jwx/jws/verify/rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package verify
import (
"crypto"
"crypto/rsa"
"errors"
"fmt"

"github.com/open-policy-agent/opa/internal/jwx/jwa"

"github.com/pkg/errors"
)

var rsaVerifyFuncs = map[jwa.SignatureAlgorithm]rsaVerifyFunc{}
Expand Down Expand Up @@ -66,7 +66,7 @@ func makeVerifyPSS(hash crypto.Hash) rsaVerifyFunc {
func newRSA(alg jwa.SignatureAlgorithm) (*RSAVerifier, error) {
verifyfn, ok := rsaVerifyFuncs[alg]
if !ok {
return nil, errors.Errorf(`unsupported algorithm while trying to create RSA verifier: %s`, alg)
return nil, fmt.Errorf(`unsupported algorithm while trying to create RSA verifier: %s`, alg)
}

return &RSAVerifier{
Expand All @@ -81,7 +81,7 @@ func (v RSAVerifier) Verify(payload, signature []byte, key interface{}) error {
}
rsaKey, ok := key.(*rsa.PublicKey)
if !ok {
return errors.Errorf(`invalid key type %T. *rsa.PublicKey is required`, key)
return fmt.Errorf(`invalid key type %T. *rsa.PublicKey is required`, key)
}

return v.verify(payload, signature, rsaKey)
Expand Down
6 changes: 2 additions & 4 deletions internal/jwx/jws/verify/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"encoding/pem"
"fmt"

"github.com/pkg/errors"

"github.com/open-policy-agent/opa/internal/jwx/jwa"
)

Expand All @@ -23,7 +21,7 @@ func New(alg jwa.SignatureAlgorithm) (Verifier, error) {
case jwa.HS256, jwa.HS384, jwa.HS512:
return newHMAC(alg)
default:
return nil, errors.Errorf(`unsupported signature algorithm: %s`, alg)
return nil, fmt.Errorf(`unsupported signature algorithm: %s`, alg)
}
}

Expand Down Expand Up @@ -52,6 +50,6 @@ func GetSigningKey(key string, alg jwa.SignatureAlgorithm) (interface{}, error)
case jwa.HS256, jwa.HS384, jwa.HS512:
return []byte(key), nil
default:
return nil, errors.Errorf("unsupported signature algorithm: %s", alg)
return nil, fmt.Errorf("unsupported signature algorithm: %s", alg)
}
}
28 changes: 15 additions & 13 deletions plugins/bundle/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ package bundle

import (
"encoding/json"
"errors"
"strconv"
"time"

"github.com/pkg/errors"

"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/download"
"github.com/open-policy-agent/opa/metrics"
Expand Down Expand Up @@ -63,29 +62,32 @@ func (s *Status) SetBundleSize(size int) {
// SetError updates the status object to reflect a failure to download or
// activate. If err is nil, the error status is cleared.
func (s *Status) SetError(err error) {

if err == nil {
var (
astErrors ast.Errors
httpError download.HTTPError
)
switch {
case err == nil:
s.Code = ""
s.HTTPCode = ""
s.Message = ""
s.Errors = nil
return
}

switch cause := errors.Cause(err).(type) {
case ast.Errors:
case errors.As(err, &astErrors):
s.Code = errCode
s.HTTPCode = ""
s.Message = types.MsgCompileModuleError
s.Errors = make([]error, len(cause))
for i := range cause {
s.Errors[i] = cause[i]
s.Errors = make([]error, len(astErrors))
for i := range astErrors {
s.Errors[i] = astErrors[i]
}
case download.HTTPError:

case errors.As(err, &httpError):
s.Code = errCode
s.HTTPCode = json.Number(strconv.Itoa(cause.StatusCode))
s.HTTPCode = json.Number(strconv.Itoa(httpError.StatusCode))
s.Message = err.Error()
s.Errors = nil

default:
s.Code = errCode
s.HTTPCode = ""
Expand Down
2 changes: 1 addition & 1 deletion server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/http/httptest"
Expand All @@ -21,7 +22,6 @@ import (
"time"

"github.com/gorilla/mux"
"github.com/pkg/errors"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/otel/propagation"

Expand Down

0 comments on commit 2131da3

Please sign in to comment.