Skip to content

Commit 09eb2b2

Browse files
committed
Add support for new setAllowHardBoundTokens field.
1 parent c334a0c commit 09eb2b2

File tree

6 files changed

+51
-0
lines changed

6 files changed

+51
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import java.nio.charset.StandardCharsets;
6565
import java.security.GeneralSecurityException;
6666
import java.security.KeyStore;
67+
import java.util.ArrayList;
6768
import java.util.HashMap;
6869
import java.util.List;
6970
import java.util.Map;
@@ -126,6 +127,7 @@ public final class InstantiatingGrpcChannelProvider implements TransportChannelP
126127
@Nullable private final Boolean allowNonDefaultServiceAccount;
127128
@VisibleForTesting final ImmutableMap<String, ?> directPathServiceConfig;
128129
@Nullable private final MtlsProvider mtlsProvider;
130+
@Nullable private final ArrayList<String> allowedValues;
129131
@VisibleForTesting final Map<String, String> headersWithDuplicatesRemoved = new HashMap<>();
130132

131133
@Nullable
@@ -136,6 +138,7 @@ private InstantiatingGrpcChannelProvider(Builder builder) {
136138
this.executor = builder.executor;
137139
this.headerProvider = builder.headerProvider;
138140
this.endpoint = builder.endpoint;
141+
this.allowedValues = builder.allowedValues;
139142
this.mtlsProvider = builder.mtlsProvider;
140143
this.envProvider = builder.envProvider;
141144
this.interceptorProvider = builder.interceptorProvider;
@@ -225,6 +228,11 @@ public TransportChannelProvider withEndpoint(String endpoint) {
225228
return toBuilder().setEndpoint(endpoint).build();
226229
}
227230

231+
@Override
232+
public TransportChannelProvider setAllowHardBoundTokens(ArrayList<String> allowedValues) {
233+
return toBuilder().setAllowHardBoundTokens(allowedValues).build();
234+
}
235+
228236
/** @deprecated Please modify pool settings via {@link #toBuilder()} */
229237
@Deprecated
230238
@Override
@@ -620,6 +628,7 @@ public static final class Builder {
620628
@Nullable private Boolean attemptDirectPathXds;
621629
@Nullable private Boolean allowNonDefaultServiceAccount;
622630
@Nullable private ImmutableMap<String, ?> directPathServiceConfig;
631+
@Nullable private ArrayList<String> allowedValues;
623632

624633
private Builder() {
625634
processorCount = Runtime.getRuntime().availableProcessors();
@@ -700,6 +709,11 @@ public Builder setEndpoint(String endpoint) {
700709
return this;
701710
}
702711

712+
public Builder setAllowHardBoundTokens(ArrayList<String> allowedValues) {
713+
this.allowedValues = allowedValues;
714+
return this;
715+
}
716+
703717
@VisibleForTesting
704718
Builder setMtlsProvider(MtlsProvider mtlsProvider) {
705719
this.mtlsProvider = mtlsProvider;

gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/testing/LocalChannelProvider.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import io.grpc.MethodDescriptor;
4848
import io.grpc.inprocess.InProcessChannelBuilder;
4949
import java.io.IOException;
50+
import java.util.ArrayList;
5051
import java.util.List;
5152
import java.util.Map;
5253
import java.util.concurrent.CopyOnWriteArrayList;
@@ -106,6 +107,12 @@ public TransportChannelProvider withEndpoint(String endpoint) {
106107
throw new UnsupportedOperationException("LocalChannelProvider doesn't need an endpoint");
107108
}
108109

110+
@Override
111+
public TransportChannelProvider setAllowHardBoundTokens(ArrayList<String> allowedValues) {
112+
throw new UnsupportedOperationException(
113+
"LocalChannelProvider doesn't support hard-bound tokens");
114+
}
115+
109116
@Override
110117
@BetaApi("The surface for customizing pool size is not stable yet and may change in the future.")
111118
public boolean acceptsPoolSize() {

gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/InstantiatingHttpJsonChannelProvider.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.io.IOException;
4343
import java.security.GeneralSecurityException;
4444
import java.security.KeyStore;
45+
import java.util.ArrayList;
4546
import java.util.Map;
4647
import java.util.concurrent.Executor;
4748
import java.util.concurrent.ScheduledExecutorService;
@@ -139,6 +140,12 @@ public TransportChannelProvider withPoolSize(int size) {
139140
"InstantiatingHttpJsonChannelProvider doesn't allow pool size customization");
140141
}
141142

143+
@Override
144+
public TransportChannelProvider setAllowHardBoundTokens(ArrayList<String> allowedValues) {
145+
throw new UnsupportedOperationException(
146+
"InstantiatingHttpJsonChannelProvider doesn't support hard-bound tokens");
147+
}
148+
142149
@Override
143150
public String getTransportName() {
144151
return HttpJsonTransportChannel.getHttpJsonTransportName();

gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedTransportChannelProvider.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.google.auth.Credentials;
3434
import com.google.common.base.Preconditions;
3535
import java.io.IOException;
36+
import java.util.ArrayList;
3637
import java.util.Map;
3738
import java.util.concurrent.Executor;
3839
import java.util.concurrent.ScheduledExecutorService;
@@ -68,6 +69,12 @@ public FixedTransportChannelProvider withExecutor(Executor executor) {
6869
"FixedTransportChannelProvider doesn't need an executor");
6970
}
7071

72+
@Override
73+
public TransportChannelProvider setAllowHardBoundTokens(ArrayList<String> allowedValues) {
74+
throw new UnsupportedOperationException(
75+
"FixedTransportChannelProvider doesn't support hard-bound tokens");
76+
}
77+
7178
@Override
7279
public boolean needsHeaders() {
7380
return false;

gax-java/gax/src/main/java/com/google/api/gax/rpc/TransportChannelProvider.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.google.api.core.InternalExtensionOnly;
3434
import com.google.auth.Credentials;
3535
import java.io.IOException;
36+
import java.util.ArrayList;
3637
import java.util.Map;
3738
import java.util.concurrent.Executor;
3839
import java.util.concurrent.ScheduledExecutorService;
@@ -97,6 +98,9 @@ public interface TransportChannelProvider {
9798
*/
9899
TransportChannelProvider withEndpoint(String endpoint);
99100

101+
/** Sets the allowed hard bound token types. */
102+
TransportChannelProvider setAllowHardBoundTokens(ArrayList<String> allowedValues);
103+
100104
/**
101105
* Reports whether this provider allows pool size customization.
102106
*

gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import com.google.common.truth.Truth;
6464
import java.io.IOException;
6565
import java.net.URI;
66+
import java.util.ArrayList;
6667
import java.util.Collections;
6768
import java.util.List;
6869
import java.util.Map;
@@ -200,6 +201,17 @@ public boolean acceptsPoolSize() {
200201
return false;
201202
}
202203

204+
@Override
205+
public TransportChannelProvider setAllowHardBoundTokens(ArrayList<String> allowedValues) {
206+
return new FakeTransportProvider(
207+
this.transport,
208+
this.executor,
209+
this.shouldAutoClose,
210+
this.headers,
211+
this.credentials,
212+
this.endpoint);
213+
}
214+
203215
@Override
204216
public TransportChannelProvider withPoolSize(int size) {
205217
throw new UnsupportedOperationException(

0 commit comments

Comments
 (0)