From 09eb2b229774e0c3ea5cefa1d36301484e07c1b5 Mon Sep 17 00:00:00 2001 From: Riya Mehta Date: Fri, 13 Dec 2024 21:21:17 -0800 Subject: [PATCH 1/8] 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( From 960084de06eb7d34322f5e7f72a690d39be3fa61 Mon Sep 17 00:00:00 2001 From: Riya Mehta Date: Thu, 9 Jan 2025 06:55:52 -0800 Subject: [PATCH 2/8] Clarify variable name in InstantiatingGrpcChannelProvider. --- .../gax/grpc/InstantiatingGrpcChannelProvider.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 7ee7b0c517..42bbff6079 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 @@ -127,7 +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; + @Nullable private final ArrayList allowedHardBoundTokenTypes; @VisibleForTesting final Map headersWithDuplicatesRemoved = new HashMap<>(); @Nullable @@ -138,7 +138,7 @@ private InstantiatingGrpcChannelProvider(Builder builder) { this.executor = builder.executor; this.headerProvider = builder.headerProvider; this.endpoint = builder.endpoint; - this.allowedValues = builder.allowedValues; + this.allowedHardBoundTokenTypes = builder.allowedHardBoundTokenTypes; this.mtlsProvider = builder.mtlsProvider; this.envProvider = builder.envProvider; this.interceptorProvider = builder.interceptorProvider; @@ -230,7 +230,7 @@ public TransportChannelProvider withEndpoint(String endpoint) { @Override public TransportChannelProvider setAllowHardBoundTokens(ArrayList allowedValues) { - return toBuilder().setAllowHardBoundTokens(allowedValues).build(); + return toBuilder().setAllowHardBoundTokenTypes(allowedValues).build(); } /** @deprecated Please modify pool settings via {@link #toBuilder()} */ @@ -628,7 +628,7 @@ public static final class Builder { @Nullable private Boolean attemptDirectPathXds; @Nullable private Boolean allowNonDefaultServiceAccount; @Nullable private ImmutableMap directPathServiceConfig; - @Nullable private ArrayList allowedValues; + @Nullable private ArrayList allowedHardBoundTokenTypes; private Builder() { processorCount = Runtime.getRuntime().availableProcessors(); @@ -709,8 +709,8 @@ public Builder setEndpoint(String endpoint) { return this; } - public Builder setAllowHardBoundTokens(ArrayList allowedValues) { - this.allowedValues = allowedValues; + public Builder setAllowHardBoundTokenTypes(ArrayList allowedValues) { + this.allowedHardBoundTokenTypes = allowedValues; return this; } From 60dafd0d6539960eaf6b4444468ae289a7df1ec8 Mon Sep 17 00:00:00 2001 From: Riya Mehta Date: Thu, 16 Jan 2025 10:05:47 -0800 Subject: [PATCH 3/8] add setter for allowed hard bound token types to only the GRPC channel provider. --- .../gax/grpc/InstantiatingGrpcChannelProvider.java | 1 - .../api/gax/grpc/testing/LocalChannelProvider.java | 7 ------- .../InstantiatingHttpJsonChannelProvider.java | 7 ------- .../api/gax/rpc/FixedTransportChannelProvider.java | 7 ------- .../google/api/gax/rpc/TransportChannelProvider.java | 4 ---- .../com/google/api/gax/rpc/ClientContextTest.java | 12 ------------ 6 files changed, 38 deletions(-) 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 42bbff6079..e9006fb555 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 @@ -228,7 +228,6 @@ public TransportChannelProvider withEndpoint(String endpoint) { return toBuilder().setEndpoint(endpoint).build(); } - @Override public TransportChannelProvider setAllowHardBoundTokens(ArrayList allowedValues) { return toBuilder().setAllowHardBoundTokenTypes(allowedValues).build(); } 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 19ed557069..5e538a06c2 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,7 +47,6 @@ 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; @@ -107,12 +106,6 @@ 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 9096867e51..f92bdf299c 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,7 +42,6 @@ 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; @@ -140,12 +139,6 @@ 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 d7f0f78af7..0bf6205dd9 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,7 +33,6 @@ 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; @@ -69,12 +68,6 @@ 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 5181b46b48..21f3c31f63 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,7 +33,6 @@ 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; @@ -98,9 +97,6 @@ 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 daf91c7e91..826864a49c 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,7 +63,6 @@ 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; @@ -201,17 +200,6 @@ 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( From e193cc9412ae68b01ca5d1a21eb38baf35d68a71 Mon Sep 17 00:00:00 2001 From: Riya Mehta Date: Thu, 16 Jan 2025 10:42:14 -0800 Subject: [PATCH 4/8] List not ArrayList, no setter, InternalApi. --- .../gax/grpc/InstantiatingGrpcChannelProvider.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) 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 e9006fb555..6c94b155b7 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,7 +64,6 @@ 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; @@ -127,7 +126,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 allowedHardBoundTokenTypes; + @Nullable private final List allowedHardBoundTokenTypes; @VisibleForTesting final Map headersWithDuplicatesRemoved = new HashMap<>(); @Nullable @@ -228,10 +227,6 @@ public TransportChannelProvider withEndpoint(String endpoint) { return toBuilder().setEndpoint(endpoint).build(); } - public TransportChannelProvider setAllowHardBoundTokens(ArrayList allowedValues) { - return toBuilder().setAllowHardBoundTokenTypes(allowedValues).build(); - } - /** @deprecated Please modify pool settings via {@link #toBuilder()} */ @Deprecated @Override @@ -627,7 +622,7 @@ public static final class Builder { @Nullable private Boolean attemptDirectPathXds; @Nullable private Boolean allowNonDefaultServiceAccount; @Nullable private ImmutableMap directPathServiceConfig; - @Nullable private ArrayList allowedHardBoundTokenTypes; + @Nullable private List allowedHardBoundTokenTypes; private Builder() { processorCount = Runtime.getRuntime().availableProcessors(); @@ -708,7 +703,8 @@ public Builder setEndpoint(String endpoint) { return this; } - public Builder setAllowHardBoundTokenTypes(ArrayList allowedValues) { + @InternalApi + public Builder setAllowHardBoundTokenTypes(List allowedValues) { this.allowedHardBoundTokenTypes = allowedValues; return this; } From 0e40f22636269b7db06281fe228cfb50dad2c0d5 Mon Sep 17 00:00:00 2001 From: Riya Mehta Date: Thu, 16 Jan 2025 12:33:19 -0800 Subject: [PATCH 5/8] add enum + javadocs. --- .../InstantiatingGrpcChannelProvider.java | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) 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 6c94b155b7..3ee6b6fa58 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 @@ -126,12 +126,26 @@ public final class InstantiatingGrpcChannelProvider implements TransportChannelP @Nullable private final Boolean allowNonDefaultServiceAccount; @VisibleForTesting final ImmutableMap directPathServiceConfig; @Nullable private final MtlsProvider mtlsProvider; - @Nullable private final List allowedHardBoundTokenTypes; + @Nullable private final List allowedHardBoundTokenTypes; @VisibleForTesting final Map headersWithDuplicatesRemoved = new HashMap<>(); @Nullable private final ApiFunction channelConfigurator; + /* + * Experimental feature + * + *

{@link HardBoundTokenTypes} specifies if hard bound tokens should be used if DirectPath + * or S2A is used to estabilsh a connection to Google APIs. + * + */ + public enum HardBoundTokenTypes { + // Use ALTS bound tokens when using DirectPath + ALTS, + // Use MTLS bound tokens when using S2A + MTLS_S2A + } + private InstantiatingGrpcChannelProvider(Builder builder) { this.processorCount = builder.processorCount; this.executor = builder.executor; @@ -622,7 +636,7 @@ public static final class Builder { @Nullable private Boolean attemptDirectPathXds; @Nullable private Boolean allowNonDefaultServiceAccount; @Nullable private ImmutableMap directPathServiceConfig; - @Nullable private List allowedHardBoundTokenTypes; + @Nullable private List allowedHardBoundTokenTypes; private Builder() { processorCount = Runtime.getRuntime().availableProcessors(); @@ -703,8 +717,26 @@ public Builder setEndpoint(String endpoint) { return this; } + /* + * Sets the allowed hard bound token types for this TransportChannelProvider. + * + *

This is optional; if it is not provided, bearer tokens will be used. + * + *

Examples: + * + *

allowedValues is {HardBoundTokenTypes.ALTS}: If DirectPath is used to create the channel, + * use hard ALTS-bound tokens for requests sent on that channel. + * + *

allowedValues is {HardBoundTokenTypes.MTLS_S2A}: If MTLS via S2A is used to create the + * channel, use hard MTLS-bound tokens for requests sent on that channel. + * + *

allowedValues is {HardBoundTokenTypes.ALTS, HardBoundTokenTypes.MTLS_S2A}: if DirectPath + * is used to create the channel, use hard ALTS-bound tokens for requests sent on that channel. + * If MTLS via S2A is used to create the channel, use hard MTLS-bound tokens for requests sent + * on that channel. + */ @InternalApi - public Builder setAllowHardBoundTokenTypes(List allowedValues) { + public Builder setAllowHardBoundTokenTypes(List allowedValues) { this.allowedHardBoundTokenTypes = allowedValues; return this; } From 591ef68d0914b23ce493aa2762137ba6ff1d686d Mon Sep 17 00:00:00 2001 From: Riya Mehta Date: Tue, 21 Jan 2025 11:26:01 -0800 Subject: [PATCH 6/8] mark enum as internal only. --- .../google/api/gax/grpc/InstantiatingGrpcChannelProvider.java | 1 + 1 file changed, 1 insertion(+) 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 3ee6b6fa58..dc27a58065 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 @@ -139,6 +139,7 @@ public final class InstantiatingGrpcChannelProvider implements TransportChannelP * or S2A is used to estabilsh a connection to Google APIs. * */ + @InternalApi public enum HardBoundTokenTypes { // Use ALTS bound tokens when using DirectPath ALTS, From 90a32af5e30e009fda5f84f20bfcd5c46ee59ef3 Mon Sep 17 00:00:00 2001 From: Riya Mehta Date: Tue, 21 Jan 2025 12:23:20 -0800 Subject: [PATCH 7/8] improve javadoc for setter. --- .../InstantiatingGrpcChannelProvider.java | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) 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 dc27a58065..4cdeb8d74f 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 @@ -141,9 +141,11 @@ public final class InstantiatingGrpcChannelProvider implements TransportChannelP */ @InternalApi public enum HardBoundTokenTypes { - // Use ALTS bound tokens when using DirectPath + // If DirectPath is used to create the channel, use hard ALTS-bound tokens for requests sent on + // that channel. ALTS, - // Use MTLS bound tokens when using S2A + // If MTLS via S2A is used to create the channel, use hard MTLS-bound tokens for requests sent + // on that channel. MTLS_S2A } @@ -721,20 +723,9 @@ public Builder setEndpoint(String endpoint) { /* * Sets the allowed hard bound token types for this TransportChannelProvider. * - *

This is optional; if it is not provided, bearer tokens will be used. - * - *

Examples: - * - *

allowedValues is {HardBoundTokenTypes.ALTS}: If DirectPath is used to create the channel, - * use hard ALTS-bound tokens for requests sent on that channel. - * - *

allowedValues is {HardBoundTokenTypes.MTLS_S2A}: If MTLS via S2A is used to create the - * channel, use hard MTLS-bound tokens for requests sent on that channel. - * - *

allowedValues is {HardBoundTokenTypes.ALTS, HardBoundTokenTypes.MTLS_S2A}: if DirectPath - * is used to create the channel, use hard ALTS-bound tokens for requests sent on that channel. - * If MTLS via S2A is used to create the channel, use hard MTLS-bound tokens for requests sent - * on that channel. + *

The list of + * {@link HardBoundTokenTypes} indicates for which methods of connecting to Google APIs hard bound tokens should + * be used. This is optional; if it is not provided, bearer tokens will be used. */ @InternalApi public Builder setAllowHardBoundTokenTypes(List allowedValues) { From a7f8384ec83e4cd09ba5218aa116a38b4db1fabb Mon Sep 17 00:00:00 2001 From: Riya Mehta Date: Tue, 21 Jan 2025 12:45:03 -0800 Subject: [PATCH 8/8] add to existing unit test. --- .../api/gax/grpc/InstantiatingGrpcChannelProviderTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java index a58f9b8173..6ec9317ab9 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java @@ -225,6 +225,10 @@ void testToBuilder() { throw new UnsupportedOperationException(); }; Map directPathServiceConfig = ImmutableMap.of("loadbalancingConfig", "grpclb"); + List hardBoundTokenTypes = + new ArrayList<>(); + hardBoundTokenTypes.add(InstantiatingGrpcChannelProvider.HardBoundTokenTypes.ALTS); + hardBoundTokenTypes.add(InstantiatingGrpcChannelProvider.HardBoundTokenTypes.MTLS_S2A); InstantiatingGrpcChannelProvider provider = InstantiatingGrpcChannelProvider.newBuilder() @@ -238,6 +242,7 @@ void testToBuilder() { .setChannelConfigurator(channelConfigurator) .setChannelsPerCpu(2.5) .setDirectPathServiceConfig(directPathServiceConfig) + .setAllowHardBoundTokenTypes(hardBoundTokenTypes) .build(); InstantiatingGrpcChannelProvider.Builder builder = provider.toBuilder();