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
alts: Make GoogleDefaultChannelCredentials take a CallCredentials #8548
Changes from 10 commits
6a8ad79
189dfce
a3f4724
5f5abaf
2893db7
5153201
0d1fd71
b229d4f
8cb0153
045743f
0d6658e
6b7d3ca
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 |
---|---|---|
|
@@ -44,30 +44,54 @@ private GoogleDefaultChannelCredentials() {} | |
* as fallback. | ||
*/ | ||
public static ChannelCredentials create() { | ||
ChannelCredentials nettyCredentials = | ||
InternalNettyChannelCredentials.create(createClientFactory()); | ||
CallCredentials callCredentials; | ||
try { | ||
callCredentials = MoreCallCredentials.from(GoogleCredentials.getApplicationDefault()); | ||
} catch (IOException e) { | ||
callCredentials = new FailingCallCredentials( | ||
Status.UNAUTHENTICATED | ||
.withDescription("Failed to get Google default credentials") | ||
.withCause(e)); | ||
} | ||
return CompositeChannelCredentials.create(nettyCredentials, callCredentials); | ||
return newBuilder().build(); | ||
} | ||
|
||
public static Builder newBuilder() { | ||
return new Builder(); | ||
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. Declare 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 |
||
} | ||
|
||
private static InternalProtocolNegotiator.ClientFactory createClientFactory() { | ||
SslContext sslContext; | ||
try { | ||
sslContext = GrpcSslContexts.forClient().build(); | ||
} catch (SSLException e) { | ||
throw new RuntimeException(e); | ||
/** Builder for {@link GoogleDefaultChannelCredentials} instances. */ | ||
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. nit: add 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 |
||
public static final class Builder { | ||
private CallCredentials callCredentials; | ||
|
||
/** Construct GoogleDefaultChannelCredentials with a given call credential. */ | ||
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. nit: s/Construct/Constructs/ 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 |
||
public Builder callCredentials(CallCredentials callCreds) { | ||
callCredentials = callCreds; | ||
return this; | ||
} | ||
|
||
/** Build a GoogleDefaultChannelCredentials instance. */ | ||
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. nit: s/Build/Builds/ 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 |
||
public ChannelCredentials build() { | ||
ChannelCredentials nettyCredentials = | ||
InternalNettyChannelCredentials.create(createClientFactory()); | ||
if (callCredentials != null) { | ||
return CompositeChannelCredentials.create(nettyCredentials, callCredentials); | ||
} | ||
CallCredentials callCreds; | ||
try { | ||
callCreds = MoreCallCredentials.from(GoogleCredentials.getApplicationDefault()); | ||
} catch (IOException e) { | ||
callCreds = | ||
new FailingCallCredentials( | ||
Status.UNAUTHENTICATED | ||
.withDescription("Failed to get Google default credentials") | ||
.withCause(e)); | ||
} | ||
return CompositeChannelCredentials.create(nettyCredentials, callCreds); | ||
} | ||
|
||
private static InternalProtocolNegotiator.ClientFactory createClientFactory() { | ||
SslContext sslContext; | ||
try { | ||
sslContext = GrpcSslContexts.forClient().build(); | ||
} catch (SSLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
return new GoogleDefaultProtocolNegotiatorFactory( | ||
/* targetServiceAccounts= */ ImmutableList.<String>of(), | ||
SharedResourcePool.forResource(HandshakerServiceChannel.SHARED_HANDSHAKER_CHANNEL), | ||
sslContext); | ||
} | ||
return new GoogleDefaultProtocolNegotiatorFactory( | ||
/* targetServiceAccounts= */ ImmutableList.<String>of(), | ||
SharedResourcePool.forResource(HandshakerServiceChannel.SHARED_HANDSHAKER_CHANNEL), | ||
sslContext); | ||
} | ||
} |
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.
nit: Add javadoc and
@since 1.42.0
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