Skip to content

Commit ae471b3

Browse files
committed
remove call credentials from call options if DirectPath
1 parent 1eda55f commit ae471b3

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public final class GrpcCallContext implements ApiCallContext {
9696
private final ImmutableMap<String, List<String>> extraHeaders;
9797
private final ApiCallContextOptions options;
9898
private final EndpointContext endpointContext;
99+
private final boolean isDirectPath;
99100

100101
/** Returns an empty instance with a null channel and default {@link CallOptions}. */
101102
public static GrpcCallContext createDefault() {
@@ -144,6 +145,36 @@ private GrpcCallContext(
144145
@Nullable RetrySettings retrySettings,
145146
@Nullable Set<StatusCode.Code> retryableCodes,
146147
@Nullable EndpointContext endpointContext) {
148+
this(
149+
channel,
150+
credentials,
151+
callOptions,
152+
timeout,
153+
streamWaitTimeout,
154+
streamIdleTimeout,
155+
channelAffinity,
156+
extraHeaders,
157+
options,
158+
retrySettings,
159+
retryableCodes,
160+
endpointContext,
161+
false);
162+
}
163+
164+
private GrpcCallContext(
165+
Channel channel,
166+
@Nullable Credentials credentials,
167+
CallOptions callOptions,
168+
@Nullable java.time.Duration timeout,
169+
@Nullable java.time.Duration streamWaitTimeout,
170+
@Nullable java.time.Duration streamIdleTimeout,
171+
@Nullable Integer channelAffinity,
172+
ImmutableMap<String, List<String>> extraHeaders,
173+
ApiCallContextOptions options,
174+
@Nullable RetrySettings retrySettings,
175+
@Nullable Set<StatusCode.Code> retryableCodes,
176+
@Nullable EndpointContext endpointContext,
177+
boolean isDirectPath) {
147178
this.channel = channel;
148179
this.credentials = credentials;
149180
this.callOptions = Preconditions.checkNotNull(callOptions);
@@ -159,6 +190,7 @@ private GrpcCallContext(
159190
// a valid EndpointContext with user configurations after the client has been initialized.
160191
this.endpointContext =
161192
endpointContext == null ? EndpointContext.getDefaultInstance() : endpointContext;
193+
this.isDirectPath = isDirectPath;
162194
}
163195

164196
/**
@@ -210,7 +242,20 @@ public GrpcCallContext withTransportChannel(TransportChannel inputChannel) {
210242
"Expected GrpcTransportChannel, got " + inputChannel.getClass().getName());
211243
}
212244
GrpcTransportChannel transportChannel = (GrpcTransportChannel) inputChannel;
213-
return withChannel(transportChannel.getChannel());
245+
return new GrpcCallContext(
246+
transportChannel.getChannel(),
247+
credentials,
248+
callOptions,
249+
timeout,
250+
streamWaitTimeout,
251+
streamIdleTimeout,
252+
channelAffinity,
253+
extraHeaders,
254+
options,
255+
retrySettings,
256+
retryableCodes,
257+
endpointContext,
258+
transportChannel.isDirectPath());
214259
}
215260

216261
@Override
@@ -535,7 +580,9 @@ public Channel getChannel() {
535580

536581
/** The {@link CallOptions} set on this context. */
537582
public CallOptions getCallOptions() {
538-
return callOptions;
583+
if (!isDirectPath) return callOptions;
584+
// Remove the CallCredentials attached to the callOptions if it's DirectPath.
585+
return callOptions.withCallCredentials(null);
539586
}
540587

541588
/** This method is obsolete. Use {@link #getStreamWaitTimeoutDuration()} instead. */

0 commit comments

Comments
 (0)