Skip to content

Commit 6678c62

Browse files
authored
Remove golang.org/x/oauth2 core dependency (#329)
* Remove golang.org/x/oauth2 core dependency * Adjust tests * Lint fixes
1 parent 6d564ff commit 6678c62

File tree

7 files changed

+23
-55
lines changed

7 files changed

+23
-55
lines changed

core/auth/auth.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package auth
22

33
import (
4-
"context"
54
"encoding/json"
65
"fmt"
76
"net/http"
@@ -130,7 +129,7 @@ func TokenAuth(cfg *config.Configuration) (http.RoundTripper, error) {
130129
}
131130

132131
client := &clients.TokenFlow{}
133-
if err := client.Init(context.Background(), &tokenCfg); err != nil {
132+
if err := client.Init(&tokenCfg); err != nil {
134133
return nil, fmt.Errorf("error initializing client: %w", err)
135134
}
136135

core/clients/clients_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ func TestDo(t *testing.T) {
7575
t.Error(err)
7676
return
7777
}
78-
req := &http.Request{
79-
URL: u,
78+
req, err := http.NewRequest(http.MethodGet, u.String(), http.NoBody)
79+
if err != nil {
80+
t.Error(err)
81+
return
8082
}
8183
c := &http.Client{}
8284
if tt.name == "fail 2 - timeout error" && server != nil {

core/clients/no_auth_flow_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ func TestNoAuthFlow_Do(t *testing.T) {
8686
t.Error(err)
8787
return
8888
}
89-
req := &http.Request{
90-
URL: u,
89+
req, err := http.NewRequest(http.MethodGet, u.String(), http.NoBody)
90+
if err != nil {
91+
t.Error(err)
92+
return
9193
}
9294
got, err := c.RoundTrip(req)
9395
if err == nil {

core/clients/token_flow.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package clients
22

33
import (
4-
"context"
54
"fmt"
65
"net/http"
7-
8-
"golang.org/x/oauth2"
96
)
107

118
const (
@@ -35,9 +32,9 @@ func (c *TokenFlow) GetConfig() TokenFlowConfig {
3532
return *c.config
3633
}
3734

38-
func (c *TokenFlow) Init(ctx context.Context, cfg *TokenFlowConfig) error {
35+
func (c *TokenFlow) Init(cfg *TokenFlowConfig) error {
3936
c.config = cfg
40-
c.configureHTTPClient(ctx)
37+
c.configureHTTPClient()
4138
if c.config.ClientRetry == nil {
4239
c.config.ClientRetry = NewRetryConfig()
4340
}
@@ -56,13 +53,10 @@ func (c *TokenFlow) Clone() interface{} {
5653
}
5754

5855
// configureHTTPClient configures the HTTP client
59-
func (c *TokenFlow) configureHTTPClient(ctx context.Context) {
60-
sts := oauth2.StaticTokenSource(
61-
&oauth2.Token{AccessToken: c.config.ServiceAccountToken},
62-
)
63-
o2nc := oauth2.NewClient(ctx, sts)
64-
o2nc.Timeout = DefaultClientTimeout
65-
c.client = o2nc
56+
func (c *TokenFlow) configureHTTPClient() {
57+
client := &http.Client{}
58+
client.Timeout = DefaultClientTimeout
59+
c.client = client
6660
}
6761

6862
// validate the client is configured well
@@ -78,5 +72,6 @@ func (c *TokenFlow) RoundTrip(req *http.Request) (*http.Response, error) {
7872
if c.client == nil {
7973
return nil, fmt.Errorf("please run Init()")
8074
}
75+
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.config.ServiceAccountToken))
8176
return Do(c.client, req, c.config.ClientRetry)
8277
}

core/clients/token_flow_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package clients
22

33
import (
4-
"context"
54
"fmt"
65
"io"
76
"net/http"
@@ -14,18 +13,17 @@ import (
1413

1514
func TestTokenFlow_Init(t *testing.T) {
1615
type args struct {
17-
ctx context.Context
1816
cfg *TokenFlowConfig
1917
}
2018
tests := []struct {
2119
name string
2220
args args
2321
wantErr bool
2422
}{
25-
{"ok", args{context.Background(), &TokenFlowConfig{
23+
{"ok", args{&TokenFlowConfig{
2624
ServiceAccountToken: "efg",
2725
}}, false},
28-
{"error 1", args{context.Background(), &TokenFlowConfig{
26+
{"error 1", args{&TokenFlowConfig{
2927
ServiceAccountToken: "",
3028
}}, true},
3129
}
@@ -38,7 +36,7 @@ func TestTokenFlow_Init(t *testing.T) {
3836
if err != nil {
3937
t.Fatalf("Setting service account token: %s", err)
4038
}
41-
if err := c.Init(tt.args.ctx, tt.args.cfg); (err != nil) != tt.wantErr {
39+
if err := c.Init(tt.args.cfg); (err != nil) != tt.wantErr {
4240
t.Errorf("TokenFlow.Init() error = %v, wantErr %v", err, tt.wantErr)
4341
}
4442
err = os.Setenv(ServiceAccountToken, b)
@@ -86,8 +84,10 @@ func TestTokenFlow_Do(t *testing.T) {
8684
t.Error(err)
8785
return
8886
}
89-
req := &http.Request{
90-
URL: u,
87+
req, err := http.NewRequest(http.MethodGet, u.String(), http.NoBody)
88+
if err != nil {
89+
t.Error(err)
90+
return
9191
}
9292
got, err := c.RoundTrip(req)
9393
if err == nil {

core/go.mod

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,4 @@ require (
77
github.com/golang-jwt/jwt/v5 v5.2.0
88
github.com/google/go-cmp v0.6.0
99
github.com/google/uuid v1.6.0
10-
golang.org/x/oauth2 v0.17.0
11-
)
12-
13-
require (
14-
github.com/golang/protobuf v1.5.3 // indirect
15-
golang.org/x/net v0.21.0 // indirect
16-
google.golang.org/appengine v1.6.7 // indirect
17-
google.golang.org/protobuf v1.31.0 // indirect
1810
)

core/go.sum

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,7 @@ github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqy
22
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
33
github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw=
44
github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
5-
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
6-
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
7-
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
8-
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
9-
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
105
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
116
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
127
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
138
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
14-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
15-
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
16-
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
17-
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
18-
golang.org/x/oauth2 v0.17.0 h1:6m3ZPmLEFdVxKKWnKq4VqZ60gutO35zm+zrAHVmHyDQ=
19-
golang.org/x/oauth2 v0.17.0/go.mod h1:OzPDGQiuQMguemayvdylqddI7qcD9lnSDb+1FiwQ5HA=
20-
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
21-
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
22-
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
23-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
24-
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
25-
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
26-
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
27-
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
28-
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
29-
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
30-
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=

0 commit comments

Comments
 (0)