Skip to content

Commit

Permalink
resolve merge conflict.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmehta19 committed Jan 22, 2025
2 parents 22562d6 + 38431a2 commit b046dc9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,36 @@ public final class InstantiatingGrpcChannelProvider implements TransportChannelP
@VisibleForTesting final ImmutableMap<String, ?> directPathServiceConfig;
@Nullable private final MtlsProvider mtlsProvider;
@Nullable private final SecureSessionAgent s2aConfigProvider;
@Nullable private final List<HardBoundTokenTypes> allowedHardBoundTokenTypes;
@VisibleForTesting final Map<String, String> headersWithDuplicatesRemoved = new HashMap<>();

@Nullable
private final ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> channelConfigurator;

/*
* Experimental feature
*
* <p>{@link HardBoundTokenTypes} specifies if hard bound tokens should be used if DirectPath
* or S2A is used to estabilsh a connection to Google APIs.
*
*/
@InternalApi
public enum HardBoundTokenTypes {
// If DirectPath is used to create the channel, use hard ALTS-bound tokens for requests sent on
// that channel.
ALTS,
// If MTLS via S2A is used to create the channel, use hard MTLS-bound tokens for requests sent
// on that channel.
MTLS_S2A
}

private InstantiatingGrpcChannelProvider(Builder builder) {
this.processorCount = builder.processorCount;
this.executor = builder.executor;
this.headerProvider = builder.headerProvider;
this.useS2A = builder.useS2A;
this.endpoint = builder.endpoint;
this.allowedHardBoundTokenTypes = builder.allowedHardBoundTokenTypes;
this.mtlsProvider = builder.mtlsProvider;
this.s2aConfigProvider = builder.s2aConfigProvider;
this.envProvider = builder.envProvider;
Expand Down Expand Up @@ -799,6 +818,7 @@ public static final class Builder {
@Nullable private Boolean attemptDirectPathXds;
@Nullable private Boolean allowNonDefaultServiceAccount;
@Nullable private ImmutableMap<String, ?> directPathServiceConfig;
@Nullable private List<HardBoundTokenTypes> allowedHardBoundTokenTypes;

private Builder() {
processorCount = Runtime.getRuntime().availableProcessors();
Expand Down Expand Up @@ -885,6 +905,18 @@ Builder setUseS2A(boolean useS2A) {
this.useS2A = useS2A;
return this;
}
/*
* Sets the allowed hard bound token types for this TransportChannelProvider.
*
* <p>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<HardBoundTokenTypes> allowedValues) {
this.allowedHardBoundTokenTypes = allowedValues;
return this;
}

@VisibleForTesting
Builder setMtlsProvider(MtlsProvider mtlsProvider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ void testToBuilder() {
throw new UnsupportedOperationException();
};
Map<String, ?> directPathServiceConfig = ImmutableMap.of("loadbalancingConfig", "grpclb");
List<InstantiatingGrpcChannelProvider.HardBoundTokenTypes> hardBoundTokenTypes =
new ArrayList<>();
hardBoundTokenTypes.add(InstantiatingGrpcChannelProvider.HardBoundTokenTypes.ALTS);
hardBoundTokenTypes.add(InstantiatingGrpcChannelProvider.HardBoundTokenTypes.MTLS_S2A);

InstantiatingGrpcChannelProvider provider =
InstantiatingGrpcChannelProvider.newBuilder()
Expand All @@ -242,6 +246,7 @@ void testToBuilder() {
.setChannelConfigurator(channelConfigurator)
.setChannelsPerCpu(2.5)
.setDirectPathServiceConfig(directPathServiceConfig)
.setAllowHardBoundTokenTypes(hardBoundTokenTypes)
.build();

InstantiatingGrpcChannelProvider.Builder builder = provider.toBuilder();
Expand Down

0 comments on commit b046dc9

Please sign in to comment.