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
Changes from 7 commits
10790dc
2436373
6270425
33ebd02
72552c8
e314a44
514cda1
7e645f9
af130ed
18f6f5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,14 +64,25 @@ func NewDefaultCredentials() credentials.Bundle { | |
// | ||
// This API is experimental. | ||
func NewComputeEngineCredentials() credentials.Bundle { | ||
return NewComputeEngineCredsWithPerRPC(nil) | ||
} | ||
|
||
// NewComputeEngineCredsWithPerRPC 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 NewComputeEngineCredsWithPerRPC(perRPC credentials.PerRPCCredentials) credentials.Bundle { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let make this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
c := &creds{ | ||
newPerRPCCreds: func() credentials.PerRPCCredentials { | ||
if perRPC != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And as mentioned in another comment, please move this if check out of the closure (you can make two closures, based on the value of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
return perRPC | ||
} | ||
return oauth.NewComputeEngine() | ||
}, | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make this a little more efficient: c := &creds{newPerRPCCreds: perRPC}
if c.newPerRPCCreds == nil {
c.newPerRPCCreds = oauth.NewComputeEngine
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, wait, this doesn't work, exactly, because of the func returning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The creds struct has both It's so that no per-RPC is shared by two bundles? (Just discussing, not suggesting changes to this PR) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, actually, transport creds are not shared. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
But why is it not okay to reuse There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can clean that up later. The comment here would be to avoid checking a conditional inside the closure; instead check outside of the closure and create the |
||
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 | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NewComputeEngineCredsWithOptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done