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
20 changes: 20 additions & 0 deletions credentials/google/google.go
Expand Up @@ -76,6 +76,26 @@ func NewComputeEngineCredentials() credentials.Bundle {
return bundle
Copy link
Contributor

Choose a reason for hiding this comment

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

Change NewComputeEngineCredentials to call the new function

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 NewComputeEngineCredsWithPerRPC(cc credentials.PerRPCCredentials) credentials.Bundle {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename cc to perRPC

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

c := &creds{
newPerRPCCreds: func() credentials.PerRPCCredentials {
if cc != nil {
return cc
}
return oauth.NewComputeEngine()
},
}
bundle, err := c.NewWithMode(internal.CredsBundleModeFallback)
if err != nil {
logger.Warningf("compute engine creds with per rpc: failed to create new creds: %v", err)
}
return bundle
}

// creds implements credentials.Bundle.
type creds struct {
// Supported modes are defined in internal/internal.go.
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": NewComputeEngineCredsWithPerRPC(nil),
} {
tests := []struct {
name string
Expand Down