Skip to content

Commit 246f1e0

Browse files
committed
chore(deps): replace k8s.io/apimachinery/pkg/util/errors with errors.Join
Drop use of k8s.io/apimachinery/pkg/util/errors.NewAggregate and replace to with errors.Join which is available in stdlib since Go 1.20. This allows to drop one dependency (which itself brings its own contraints in its go.mod) and use more standard behavior.
1 parent 1225d61 commit 246f1e0

File tree

7 files changed

+12
-14
lines changed

7 files changed

+12
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
## Important Notes
66

7+
Use of [`k8s.io/apimachinery/pkg/util/errors.NewAggregate`](https://pkg.go.dev/k8s.io/apimachinery/pkg/util/errors#NewAggregate)
8+
is removed and replaced by standard [`errors.Join`](https://pkg.go.dev/errors#Join) (available since Go 1.20) which allows
9+
standard unwrapping of errors.
10+
711
## Breaking Changes
812

913
## Changes since v7.9.0

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ require (
3939
golang.org/x/sync v0.12.0
4040
google.golang.org/api v0.228.0
4141
gopkg.in/natefinch/lumberjack.v2 v2.2.1
42-
k8s.io/apimachinery v0.32.3
4342
)
4443

4544
require (

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,5 +263,3 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
263263
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
264264
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
265265
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
266-
k8s.io/apimachinery v0.32.3 h1:JmDuDarhDmA/Li7j3aPrwhpNBA94Nvk5zLeOge9HH1U=
267-
k8s.io/apimachinery v0.32.3/go.mod h1:GpHVgxoKlTxClKcteaeuF1Ul/lDVb74KpZcxcmLDElE=

pkg/middleware/jwt_session.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
middlewareapi "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/middleware"
1111
sessionsapi "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/sessions"
1212
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/logger"
13-
k8serrors "k8s.io/apimachinery/pkg/util/errors"
1413
)
1514

1615
const jwtRegexFormat = `^ey[a-zA-Z0-9_-]*\.ey[a-zA-Z0-9_-]*\.[a-zA-Z0-9_-]+$`
@@ -89,7 +88,7 @@ func (j *jwtSessionLoader) getJwtSession(req *http.Request) (*sessionsapi.Sessio
8988
return session, nil
9089
}
9190

92-
return nil, k8serrors.NewAggregate(errs)
91+
return nil, errors.Join(errs...)
9392
}
9493

9594
// findTokenFromHeader finds a valid JWT token from the Authorization header of a given request.

pkg/middleware/jwt_session_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
sessionsapi "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/sessions"
2020
. "github.com/onsi/ginkgo/v2"
2121
. "github.com/onsi/gomega"
22-
k8serrors "k8s.io/apimachinery/pkg/util/errors"
2322
)
2423

2524
type noOpKeySet struct {
@@ -302,10 +301,10 @@ Nnc3a3lGVWFCNUMxQnNJcnJMTWxka1dFaHluYmI4Ongtb2F1dGgtYmFzaWM=`
302301
}),
303302
Entry("Bearer <nonVerifiedToken>", getJWTSessionTableInput{
304303
authorizationHeader: fmt.Sprintf("Bearer %s", nonVerifiedToken),
305-
expectedErr: k8serrors.NewAggregate([]error{
304+
expectedErr: errors.Join(
306305
errors.New("unable to verify bearer token"),
307306
errors.New("oidc: malformed jwt: oidc: malformed jwt payload: illegal base64 data at input byte 8"),
308-
}),
307+
),
309308
expectedSession: nil,
310309
}),
311310
Entry("Bearer <verifiedToken>", getJWTSessionTableInput{
@@ -315,10 +314,10 @@ Nnc3a3lGVWFCNUMxQnNJcnJMTWxka1dFaHluYmI4Ongtb2F1dGgtYmFzaWM=`
315314
}),
316315
Entry("Basic Base64(<nonVerifiedToken>:) (No password)", getJWTSessionTableInput{
317316
authorizationHeader: "Basic ZXlKZm9vYmFyLmV5SmZvb2Jhci4xMjM0NWFzZGY6",
318-
expectedErr: k8serrors.NewAggregate([]error{
317+
expectedErr: errors.Join(
319318
errors.New("unable to verify bearer token"),
320319
errors.New("oidc: malformed jwt: oidc: malformed jwt payload: illegal base64 data at input byte 8"),
321-
}),
320+
),
322321
expectedSession: nil,
323322
}),
324323
Entry("Basic Base64(<verifiedToken>:x-oauth-basic) (Sentinel password)", getJWTSessionTableInput{

pkg/providers/oidc/provider_verifier.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"os"
1111

1212
"github.com/coreos/go-oidc/v3/oidc"
13-
k8serrors "k8s.io/apimachinery/pkg/util/errors"
1413
)
1514

1615
// ProviderVerifier represents the OIDC discovery and verification process
@@ -75,7 +74,7 @@ func (p ProviderVerifierOptions) validate() error {
7574
}
7675

7776
if len(errs) > 0 {
78-
return k8serrors.NewAggregate(errs)
77+
return errors.Join(errs...)
7978
}
8079
return nil
8180
}

providers/providers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package providers
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"net/url"
78

89
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
910
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/sessions"
1011
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/logger"
1112
internaloidc "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/providers/oidc"
12-
k8serrors "k8s.io/apimachinery/pkg/util/errors"
1313
)
1414

1515
const (
@@ -135,7 +135,7 @@ func newProviderDataFromConfig(providerConfig options.Provider) (*ProviderData,
135135
errs = append(errs, p.compileLoginParams(providerConfig.LoginURLParameters)...)
136136

137137
if len(errs) > 0 {
138-
return nil, k8serrors.NewAggregate(errs)
138+
return nil, errors.Join(errs...)
139139
}
140140

141141
// Make the OIDC options available to all providers that support it

0 commit comments

Comments
 (0)