Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

credentials/google: introduce a new API NewComputeEngineCredsWithOptions #4767

Merged
merged 10 commits into from Sep 30, 2021
Merged
21 changes: 19 additions & 2 deletions credentials/google/google.go
Expand Up @@ -64,14 +64,31 @@ func NewDefaultCredentials() credentials.Bundle {
//
// This API is experimental.
func NewComputeEngineCredentials() credentials.Bundle {
return NewComputeEngineCredsWithOptions(PerRPCCredsOpts{})
}

type PerRPCCredsOpts struct {
menghanl marked this conversation as resolved.
Show resolved Hide resolved
// The per RPC credentials passed to a bundle
PerRPC credentials.PerRPCCredentials
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PerRPCCreds

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

// NewComputeEngineCredsWithPerRPC returns a credentials bundle that is configured to work
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NewComputeEngineCredsWithOptions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// with google services. This API must only be used when running on GCE.
//
// This API is experimental.
func NewComputeEngineCredsWithOptions(perRPCOpts PerRPCCredsOpts) credentials.Bundle {
perRPC := oauth.NewComputeEngine()
if perRPCOpts.PerRPC != nil {
perRPC = perRPCOpts.PerRPC
}
c := &creds{
newPerRPCCreds: func() credentials.PerRPCCredentials {
return oauth.NewComputeEngine()
return perRPC
},
}
bundle, err := c.NewWithMode(internal.CredsBundleModeFallback)
if err != nil {
logger.Warningf("compute engine creds: failed to create new creds: %v", err)
logger.Warningf("compute engine creds with per rpc: failed to create new creds: %v", err)
}
return bundle
}
Expand Down
5 changes: 3 additions & 2 deletions credentials/google/google_test.go
Expand Up @@ -76,8 +76,9 @@ func overrideNewCredsFuncs() func() {
func TestClientHandshakeBasedOnClusterName(t *testing.T) {
defer overrideNewCredsFuncs()()
for bundleTyp, tc := range map[string]credentials.Bundle{
"defaultCreds": NewDefaultCredentials(),
"computeCreds": NewComputeEngineCredentials(),
"defaultCreds": NewDefaultCredentials(),
"computeCreds": NewComputeEngineCredentials(),
"computeCredsPerRPC": NewComputeEngineCredsWithOptions(PerRPCCredsOpts{}),
} {
tests := []struct {
name string
Expand Down