Skip to content

Commit 3a6776a

Browse files
liggitthickford
authored andcommitted
appengine: drop obsolete code for AppEngine envs <=Go 1.11
This library no longer builds on Go versions prior to Go 1.17, so no longer needs to support compilation specific to AppEngine environments on Go versions prior to Go 1.11 Related to golang#615 Change-Id: Ia9579ea2091cb86ee96065affb920370c4ba33ea Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/570595 Reviewed-by: Matt Hickford <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Cody Oss <[email protected]> Run-TryBot: Matt Hickford <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 85231f9 commit 3a6776a

File tree

8 files changed

+14
-172
lines changed

8 files changed

+14
-172
lines changed

go.mod

+1-7
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ go 1.18
55
require (
66
cloud.google.com/go/compute/metadata v0.2.3
77
github.com/google/go-cmp v0.5.9
8-
google.golang.org/appengine v1.6.7
98
)
109

11-
require (
12-
cloud.google.com/go/compute v1.20.1 // indirect
13-
github.com/golang/protobuf v1.5.3 // indirect
14-
golang.org/x/net v0.22.0 // indirect
15-
google.golang.org/protobuf v1.31.0 // indirect
16-
)
10+
require cloud.google.com/go/compute v1.20.1 // indirect

go.sum

-20
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,5 @@ cloud.google.com/go/compute v1.20.1 h1:6aKEtlUiwEpJzM001l0yFkpXmUVXaN8W+fbkb2AZN
22
cloud.google.com/go/compute v1.20.1/go.mod h1:4tCnrn48xsqlwSAiLf1HXMQk8CONslYbdiEZc9FEIbM=
33
cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=
44
cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
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.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
116
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
12-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
13-
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
14-
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
15-
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
16-
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
17-
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
18-
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
19-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
20-
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
21-
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
22-
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
23-
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
24-
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
25-
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
26-
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=

google/appengine.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,24 @@ package google
66

77
import (
88
"context"
9-
"time"
9+
"log"
10+
"sync"
1011

1112
"golang.org/x/oauth2"
1213
)
1314

14-
// Set at init time by appengine_gen1.go. If nil, we're not on App Engine standard first generation (<= Go 1.9) or App Engine flexible.
15-
var appengineTokenFunc func(c context.Context, scopes ...string) (token string, expiry time.Time, err error)
16-
17-
// Set at init time by appengine_gen1.go. If nil, we're not on App Engine standard first generation (<= Go 1.9) or App Engine flexible.
18-
var appengineAppIDFunc func(c context.Context) string
15+
var logOnce sync.Once // only spam about deprecation once
1916

2017
// AppEngineTokenSource returns a token source that fetches tokens from either
2118
// the current application's service account or from the metadata server,
2219
// depending on the App Engine environment. See below for environment-specific
2320
// details. If you are implementing a 3-legged OAuth 2.0 flow on App Engine that
2421
// involves user accounts, see oauth2.Config instead.
2522
//
26-
// First generation App Engine runtimes (<= Go 1.9):
27-
// AppEngineTokenSource returns a token source that fetches tokens issued to the
23+
// The current version of this library requires at least Go 1.17 to build,
24+
// so first generation App Engine runtimes (<= Go 1.9) are unsupported.
25+
// Previously, on first generation App Engine runtimes, AppEngineTokenSource
26+
// returned a token source that fetches tokens issued to the
2827
// current App Engine application's service account. The provided context must have
2928
// come from appengine.NewContext.
3029
//
@@ -34,5 +33,8 @@ var appengineAppIDFunc func(c context.Context) string
3433
// context and scopes are not used. Please use DefaultTokenSource (or ComputeTokenSource,
3534
// which DefaultTokenSource will use in this case) instead.
3635
func AppEngineTokenSource(ctx context.Context, scope ...string) oauth2.TokenSource {
37-
return appEngineTokenSource(ctx, scope...)
36+
logOnce.Do(func() {
37+
log.Print("google: AppEngineTokenSource is deprecated on App Engine standard second generation runtimes (>= Go 1.11) and App Engine flexible. Please use DefaultTokenSource or ComputeTokenSource.")
38+
})
39+
return ComputeTokenSource("")
3840
}

google/appengine_gen1.go

-77
This file was deleted.

google/appengine_gen2_flex.go

-27
This file was deleted.

google/default.go

+2-14
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,7 @@ func DefaultTokenSource(ctx context.Context, scope ...string) (oauth2.TokenSourc
199199
// 2. A JSON file in a location known to the gcloud command-line tool.
200200
// On Windows, this is %APPDATA%/gcloud/application_default_credentials.json.
201201
// On other systems, $HOME/.config/gcloud/application_default_credentials.json.
202-
// 3. On Google App Engine standard first generation runtimes (<= Go 1.9) it uses
203-
// the appengine.AccessToken function.
204-
// 4. On Google Compute Engine, Google App Engine standard second generation runtimes
202+
// 3. On Google Compute Engine, Google App Engine standard second generation runtimes
205203
// (>= Go 1.11), and Google App Engine flexible environment, it fetches
206204
// credentials from the metadata server.
207205
func FindDefaultCredentialsWithParams(ctx context.Context, params CredentialsParams) (*Credentials, error) {
@@ -224,17 +222,7 @@ func FindDefaultCredentialsWithParams(ctx context.Context, params CredentialsPar
224222
return CredentialsFromJSONWithParams(ctx, b, params)
225223
}
226224

227-
// Third, if we're on a Google App Engine standard first generation runtime (<= Go 1.9)
228-
// use those credentials. App Engine standard second generation runtimes (>= Go 1.11)
229-
// and App Engine flexible use ComputeTokenSource and the metadata server.
230-
if appengineTokenFunc != nil {
231-
return &Credentials{
232-
ProjectID: appengineAppIDFunc(ctx),
233-
TokenSource: AppEngineTokenSource(ctx, params.Scopes...),
234-
}, nil
235-
}
236-
237-
// Fourth, if we're on Google Compute Engine, an App Engine standard second generation runtime,
225+
// Third, if we're on Google Compute Engine, an App Engine standard second generation runtime,
238226
// or App Engine flexible, use the metadata server.
239227
if metadata.OnGCE() {
240228
id, _ := metadata.ProjectID()

internal/client_appengine.go

-13
This file was deleted.

internal/transport.go

-5
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,11 @@ var HTTPClient ContextKey
1818
// because nobody else can create a ContextKey, being unexported.
1919
type ContextKey struct{}
2020

21-
var appengineClientHook func(context.Context) *http.Client
22-
2321
func ContextClient(ctx context.Context) *http.Client {
2422
if ctx != nil {
2523
if hc, ok := ctx.Value(HTTPClient).(*http.Client); ok {
2624
return hc
2725
}
2826
}
29-
if appengineClientHook != nil {
30-
return appengineClientHook(ctx)
31-
}
3227
return http.DefaultClient
3328
}

0 commit comments

Comments
 (0)