Skip to content

Commit

Permalink
google: remove code duplication, note appenginevm case
Browse files Browse the repository at this point in the history
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 <bradfitz@golang.org>
  • Loading branch information
rakyll committed Mar 2, 2017
1 parent 810daf0 commit 8cf5815
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
4 changes: 2 additions & 2 deletions google/appengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion google/appengine_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions google/appengineflex_hook.go
Original file line number Diff line number Diff line change
@@ -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.
}
15 changes: 0 additions & 15 deletions google/appenginevm_hook.go

This file was deleted.

2 changes: 1 addition & 1 deletion google/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...),
Expand Down

0 comments on commit 8cf5815

Please sign in to comment.