From 8cf58155e4a90a3a73149652cc36528e892c58cf Mon Sep 17 00:00:00 2001 From: Jaana Burcu Dogan Date: Tue, 21 Feb 2017 22:40:33 -0800 Subject: [PATCH] google: remove code duplication, note appenginevm case Before AppEngine classic allowed "google.golang.org/appengine" imports, we used to maintain two hook files to choose either from "appengine" or "google.golang.org/appengine" namespaces. Now, both environments allow importing from "google.golang.org/appengine". Therefore, there is no need to set hooks in two separate files. Also note that Flex prefers to use metadata server, so we still need to be able to differentiate between these environments. Change-Id: I7478ebdfa1b062d466aaf2aca938f93d42b4c58a Reviewed-on: https://go-review.googlesource.com/37378 Reviewed-by: Brad Fitzpatrick --- google/appengine.go | 4 ++-- google/appengine_hook.go | 2 +- google/appengineflex_hook.go | 11 +++++++++++ google/appenginevm_hook.go | 15 --------------- google/default.go | 2 +- 5 files changed, 15 insertions(+), 19 deletions(-) create mode 100644 google/appengineflex_hook.go delete mode 100644 google/appenginevm_hook.go diff --git a/google/appengine.go b/google/appengine.go index 4243f4c..50d918b 100644 --- a/google/appengine.go +++ b/google/appengine.go @@ -14,8 +14,8 @@ import ( "golang.org/x/oauth2" ) -// Set at init time by appenginevm_hook.go. If true, we are on App Engine Managed VMs. -var appengineVM bool +// appengineFlex is set at init time by appengineflex_hook.go. If true, we are on App Engine Flex. +var appengineFlex bool // Set at init time by appengine_hook.go. If nil, we're not on App Engine. var appengineTokenFunc func(c context.Context, scopes ...string) (token string, expiry time.Time, err error) diff --git a/google/appengine_hook.go b/google/appengine_hook.go index 6f66411..56669ea 100644 --- a/google/appengine_hook.go +++ b/google/appengine_hook.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build appengine +// +build appengine appenginevm package google diff --git a/google/appengineflex_hook.go b/google/appengineflex_hook.go new file mode 100644 index 0000000..5d0231a --- /dev/null +++ b/google/appengineflex_hook.go @@ -0,0 +1,11 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build appenginevm + +package google + +func init() { + appengineFlex = true // Flex doesn't support appengine.AccessToken; depend on metadata server. +} diff --git a/google/appenginevm_hook.go b/google/appenginevm_hook.go deleted file mode 100644 index 1074780..0000000 --- a/google/appenginevm_hook.go +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2015 The oauth2 Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build appenginevm - -package google - -import "google.golang.org/appengine" - -func init() { - appengineVM = true - appengineTokenFunc = appengine.AccessToken - appengineAppIDFunc = appengine.AppID -} diff --git a/google/default.go b/google/default.go index b45e796..004ed4e 100644 --- a/google/default.go +++ b/google/default.go @@ -81,7 +81,7 @@ func FindDefaultCredentials(ctx context.Context, scope ...string) (*DefaultCrede } // Third, if we're on Google App Engine use those credentials. - if appengineTokenFunc != nil && !appengineVM { + if appengineTokenFunc != nil && !appengineFlex { return &DefaultCredentials{ ProjectID: appengineAppIDFunc(ctx), TokenSource: AppEngineTokenSource(ctx, scope...),