Skip to content

Commit 38431a2

Browse files
authored
feat: add support for new setAllowHardBoundTokens field. (#3467)
Introduce new `setAllowHardBoundTokens` field.
1 parent afec970 commit 38431a2

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

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

+33
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,35 @@ public final class InstantiatingGrpcChannelProvider implements TransportChannelP
126126
@Nullable private final Boolean allowNonDefaultServiceAccount;
127127
@VisibleForTesting final ImmutableMap<String, ?> directPathServiceConfig;
128128
@Nullable private final MtlsProvider mtlsProvider;
129+
@Nullable private final List<HardBoundTokenTypes> allowedHardBoundTokenTypes;
129130
@VisibleForTesting final Map<String, String> headersWithDuplicatesRemoved = new HashMap<>();
130131

131132
@Nullable
132133
private final ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> channelConfigurator;
133134

135+
/*
136+
* Experimental feature
137+
*
138+
* <p>{@link HardBoundTokenTypes} specifies if hard bound tokens should be used if DirectPath
139+
* or S2A is used to estabilsh a connection to Google APIs.
140+
*
141+
*/
142+
@InternalApi
143+
public enum HardBoundTokenTypes {
144+
// If DirectPath is used to create the channel, use hard ALTS-bound tokens for requests sent on
145+
// that channel.
146+
ALTS,
147+
// If MTLS via S2A is used to create the channel, use hard MTLS-bound tokens for requests sent
148+
// on that channel.
149+
MTLS_S2A
150+
}
151+
134152
private InstantiatingGrpcChannelProvider(Builder builder) {
135153
this.processorCount = builder.processorCount;
136154
this.executor = builder.executor;
137155
this.headerProvider = builder.headerProvider;
138156
this.endpoint = builder.endpoint;
157+
this.allowedHardBoundTokenTypes = builder.allowedHardBoundTokenTypes;
139158
this.mtlsProvider = builder.mtlsProvider;
140159
this.envProvider = builder.envProvider;
141160
this.interceptorProvider = builder.interceptorProvider;
@@ -620,6 +639,7 @@ public static final class Builder {
620639
@Nullable private Boolean attemptDirectPathXds;
621640
@Nullable private Boolean allowNonDefaultServiceAccount;
622641
@Nullable private ImmutableMap<String, ?> directPathServiceConfig;
642+
@Nullable private List<HardBoundTokenTypes> allowedHardBoundTokenTypes;
623643

624644
private Builder() {
625645
processorCount = Runtime.getRuntime().availableProcessors();
@@ -700,6 +720,19 @@ public Builder setEndpoint(String endpoint) {
700720
return this;
701721
}
702722

723+
/*
724+
* Sets the allowed hard bound token types for this TransportChannelProvider.
725+
*
726+
* <p>The list of
727+
* {@link HardBoundTokenTypes} indicates for which methods of connecting to Google APIs hard bound tokens should
728+
* be used. This is optional; if it is not provided, bearer tokens will be used.
729+
*/
730+
@InternalApi
731+
public Builder setAllowHardBoundTokenTypes(List<HardBoundTokenTypes> allowedValues) {
732+
this.allowedHardBoundTokenTypes = allowedValues;
733+
return this;
734+
}
735+
703736
@VisibleForTesting
704737
Builder setMtlsProvider(MtlsProvider mtlsProvider) {
705738
this.mtlsProvider = mtlsProvider;

Diff for: gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java

+5
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ void testToBuilder() {
225225
throw new UnsupportedOperationException();
226226
};
227227
Map<String, ?> directPathServiceConfig = ImmutableMap.of("loadbalancingConfig", "grpclb");
228+
List<InstantiatingGrpcChannelProvider.HardBoundTokenTypes> hardBoundTokenTypes =
229+
new ArrayList<>();
230+
hardBoundTokenTypes.add(InstantiatingGrpcChannelProvider.HardBoundTokenTypes.ALTS);
231+
hardBoundTokenTypes.add(InstantiatingGrpcChannelProvider.HardBoundTokenTypes.MTLS_S2A);
228232

229233
InstantiatingGrpcChannelProvider provider =
230234
InstantiatingGrpcChannelProvider.newBuilder()
@@ -238,6 +242,7 @@ void testToBuilder() {
238242
.setChannelConfigurator(channelConfigurator)
239243
.setChannelsPerCpu(2.5)
240244
.setDirectPathServiceConfig(directPathServiceConfig)
245+
.setAllowHardBoundTokenTypes(hardBoundTokenTypes)
241246
.build();
242247

243248
InstantiatingGrpcChannelProvider.Builder builder = provider.toBuilder();

0 commit comments

Comments
 (0)