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

grpc: create new ComputeEngineCredentials via newBuilder. #3651

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1199,11 +1199,20 @@ boolean isDirectPathBoundTokenEnabled() {
CallCredentials createHardBoundTokensCallCredentials(
ComputeEngineCredentials.GoogleAuthTransport googleAuthTransport,
ComputeEngineCredentials.BindingEnforcement bindingEnforcement) {
ComputeEngineCredentials.Builder credsBuilder =
((ComputeEngineCredentials) credentials).toBuilder();
// We only set scopes and HTTP transport factory from the original credentials because
Copy link
Member

@rockspore rockspore Feb 22, 2025

Choose a reason for hiding this comment

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

For future readers, could you explain briefly in the comment why we create it from a newBuilder()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Done.

// only those are used in gRPC CallCredentials to fetch request metadata.
// only those are used in gRPC CallCredentials to fetch request metadata. We create a new
// credential
// via {@code newBuilder} as opposed to {@code toBuilder} because we don't want a reference to
// the
// access token held by {@code credentials}; we want this new credential to fetch a new access
// token
// from MDS using the {@param googleAuthTransport} and {@param bindingEnforcement}.
return MoreCallCredentials.from(
((ComputeEngineCredentials) this.credentials)
.toBuilder()
ComputeEngineCredentials.newBuilder()
.setScopes(credsBuilder.getScopes())
.setHttpTransportFactory(credsBuilder.getHttpTransportFactory())
.setGoogleAuthTransport(googleAuthTransport)
.setBindingEnforcement(bindingEnforcement)
.build());
Expand Down
Loading