From 09eb2b229774e0c3ea5cefa1d36301484e07c1b5 Mon Sep 17 00:00:00 2001 From: Riya Mehta Date: Fri, 13 Dec 2024 21:21:17 -0800 Subject: [PATCH] Add support for new setAllowHardBoundTokens field. --- .../gax/grpc/InstantiatingGrpcChannelProvider.java | 14 ++++++++++++++ .../api/gax/grpc/testing/LocalChannelProvider.java | 7 +++++++ .../InstantiatingHttpJsonChannelProvider.java | 7 +++++++ .../api/gax/rpc/FixedTransportChannelProvider.java | 7 +++++++ .../api/gax/rpc/TransportChannelProvider.java | 4 ++++ .../com/google/api/gax/rpc/ClientContextTest.java | 12 ++++++++++++ 6 files changed, 51 insertions(+) diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java index ae4d7f9e51..7ee7b0c517 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java @@ -64,6 +64,7 @@ import java.nio.charset.StandardCharsets; import java.security.GeneralSecurityException; import java.security.KeyStore; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -126,6 +127,7 @@ public final class InstantiatingGrpcChannelProvider implements TransportChannelP @Nullable private final Boolean allowNonDefaultServiceAccount; @VisibleForTesting final ImmutableMap directPathServiceConfig; @Nullable private final MtlsProvider mtlsProvider; + @Nullable private final ArrayList allowedValues; @VisibleForTesting final Map headersWithDuplicatesRemoved = new HashMap<>(); @Nullable @@ -136,6 +138,7 @@ private InstantiatingGrpcChannelProvider(Builder builder) { this.executor = builder.executor; this.headerProvider = builder.headerProvider; this.endpoint = builder.endpoint; + this.allowedValues = builder.allowedValues; this.mtlsProvider = builder.mtlsProvider; this.envProvider = builder.envProvider; this.interceptorProvider = builder.interceptorProvider; @@ -225,6 +228,11 @@ public TransportChannelProvider withEndpoint(String endpoint) { return toBuilder().setEndpoint(endpoint).build(); } + @Override + public TransportChannelProvider setAllowHardBoundTokens(ArrayList allowedValues) { + return toBuilder().setAllowHardBoundTokens(allowedValues).build(); + } + /** @deprecated Please modify pool settings via {@link #toBuilder()} */ @Deprecated @Override @@ -620,6 +628,7 @@ public static final class Builder { @Nullable private Boolean attemptDirectPathXds; @Nullable private Boolean allowNonDefaultServiceAccount; @Nullable private ImmutableMap directPathServiceConfig; + @Nullable private ArrayList allowedValues; private Builder() { processorCount = Runtime.getRuntime().availableProcessors(); @@ -700,6 +709,11 @@ public Builder setEndpoint(String endpoint) { return this; } + public Builder setAllowHardBoundTokens(ArrayList allowedValues) { + this.allowedValues = allowedValues; + return this; + } + @VisibleForTesting Builder setMtlsProvider(MtlsProvider mtlsProvider) { this.mtlsProvider = mtlsProvider; diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/testing/LocalChannelProvider.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/testing/LocalChannelProvider.java index 5e538a06c2..19ed557069 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/testing/LocalChannelProvider.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/testing/LocalChannelProvider.java @@ -47,6 +47,7 @@ import io.grpc.MethodDescriptor; import io.grpc.inprocess.InProcessChannelBuilder; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; @@ -106,6 +107,12 @@ public TransportChannelProvider withEndpoint(String endpoint) { throw new UnsupportedOperationException("LocalChannelProvider doesn't need an endpoint"); } + @Override + public TransportChannelProvider setAllowHardBoundTokens(ArrayList allowedValues) { + throw new UnsupportedOperationException( + "LocalChannelProvider doesn't support hard-bound tokens"); + } + @Override @BetaApi("The surface for customizing pool size is not stable yet and may change in the future.") public boolean acceptsPoolSize() { diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/InstantiatingHttpJsonChannelProvider.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/InstantiatingHttpJsonChannelProvider.java index f92bdf299c..9096867e51 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/InstantiatingHttpJsonChannelProvider.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/InstantiatingHttpJsonChannelProvider.java @@ -42,6 +42,7 @@ import java.io.IOException; import java.security.GeneralSecurityException; import java.security.KeyStore; +import java.util.ArrayList; import java.util.Map; import java.util.concurrent.Executor; import java.util.concurrent.ScheduledExecutorService; @@ -139,6 +140,12 @@ public TransportChannelProvider withPoolSize(int size) { "InstantiatingHttpJsonChannelProvider doesn't allow pool size customization"); } + @Override + public TransportChannelProvider setAllowHardBoundTokens(ArrayList allowedValues) { + throw new UnsupportedOperationException( + "InstantiatingHttpJsonChannelProvider doesn't support hard-bound tokens"); + } + @Override public String getTransportName() { return HttpJsonTransportChannel.getHttpJsonTransportName(); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedTransportChannelProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedTransportChannelProvider.java index 0bf6205dd9..d7f0f78af7 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedTransportChannelProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedTransportChannelProvider.java @@ -33,6 +33,7 @@ import com.google.auth.Credentials; import com.google.common.base.Preconditions; import java.io.IOException; +import java.util.ArrayList; import java.util.Map; import java.util.concurrent.Executor; import java.util.concurrent.ScheduledExecutorService; @@ -68,6 +69,12 @@ public FixedTransportChannelProvider withExecutor(Executor executor) { "FixedTransportChannelProvider doesn't need an executor"); } + @Override + public TransportChannelProvider setAllowHardBoundTokens(ArrayList allowedValues) { + throw new UnsupportedOperationException( + "FixedTransportChannelProvider doesn't support hard-bound tokens"); + } + @Override public boolean needsHeaders() { return false; diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/TransportChannelProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/TransportChannelProvider.java index 21f3c31f63..5181b46b48 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/TransportChannelProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/TransportChannelProvider.java @@ -33,6 +33,7 @@ import com.google.api.core.InternalExtensionOnly; import com.google.auth.Credentials; import java.io.IOException; +import java.util.ArrayList; import java.util.Map; import java.util.concurrent.Executor; import java.util.concurrent.ScheduledExecutorService; @@ -97,6 +98,9 @@ public interface TransportChannelProvider { */ TransportChannelProvider withEndpoint(String endpoint); + /** Sets the allowed hard bound token types. */ + TransportChannelProvider setAllowHardBoundTokens(ArrayList allowedValues); + /** * Reports whether this provider allows pool size customization. * diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java index 826864a49c..daf91c7e91 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java @@ -63,6 +63,7 @@ import com.google.common.truth.Truth; import java.io.IOException; import java.net.URI; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; @@ -200,6 +201,17 @@ public boolean acceptsPoolSize() { return false; } + @Override + public TransportChannelProvider setAllowHardBoundTokens(ArrayList allowedValues) { + return new FakeTransportProvider( + this.transport, + this.executor, + this.shouldAutoClose, + this.headers, + this.credentials, + this.endpoint); + } + @Override public TransportChannelProvider withPoolSize(int size) { throw new UnsupportedOperationException(