Skip to content

Commit

Permalink
DirectPath: make ComputeEngineCredentials support non-default service…
Browse files Browse the repository at this point in the history
… account
  • Loading branch information
mohanli-ml committed Sep 14, 2021
1 parent 10790dc commit 2436373
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
23 changes: 21 additions & 2 deletions credentials/google/google.go
Expand Up @@ -59,10 +59,29 @@ func NewDefaultCredentials() credentials.Bundle {
}

// NewComputeEngineCredentials returns a credentials bundle that is configured to work
// with google services. This API must only be used when running on GCE. Authentication configured
// by this API represents the GCE VM's default service account.
//
// [Deprecated]: use NewDirectPathCredentials instead.
// This API is experimental.
func NewComputeEngineCredentials() credentials.Bundle {
c := &creds{
newPerRPCCreds: func() credentials.PerRPCCredentials {
return oauth.NewComputeEngine()
},
}
bundle, err := c.NewWithMode(internal.CredsBundleModeFallback)
if err != nil {
logger.Warningf("compute engine creds: failed to create new creds: %v", err)
}
return bundle
}

// NewDirectPathCredentials returns a credentials bundle that is configured to work
// with google services. This API must only be used when running on GCE.
//
// This API is experimental.
func NewComputeEngineCredentials(cc credentials.PerRPCCredentials) credentials.Bundle {
func NewDirectPathCredentials(cc credentials.PerRPCCredentials) credentials.Bundle {
c := &creds{
newPerRPCCreds: func() credentials.PerRPCCredentials {
if cc != nil {
Expand All @@ -73,7 +92,7 @@ func NewComputeEngineCredentials(cc credentials.PerRPCCredentials) credentials.B
}
bundle, err := c.NewWithMode(internal.CredsBundleModeFallback)
if err != nil {
logger.Warningf("compute engine creds: failed to create new creds: %v", err)
logger.Warningf("direct path creds: failed to create new creds: %v", err)
}
return bundle
}
Expand Down
1 change: 1 addition & 0 deletions credentials/google/google_test.go
Expand Up @@ -78,6 +78,7 @@ func TestClientHandshakeBasedOnClusterName(t *testing.T) {
for bundleTyp, tc := range map[string]credentials.Bundle{
"defaultCreds": NewDefaultCredentials(),
"computeCreds": NewComputeEngineCredentials(),
"directpathCreds": NewDirectPathCredentials(nil),
} {
tests := []struct {
name string
Expand Down

0 comments on commit 2436373

Please sign in to comment.