Skip to content

Commit

Permalink
Add support for new setAllowHardBoundTokens field.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmehta19 committed Dec 14, 2024
1 parent c334a0c commit 09eb2b2
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -126,6 +127,7 @@ public final class InstantiatingGrpcChannelProvider implements TransportChannelP
@Nullable private final Boolean allowNonDefaultServiceAccount;
@VisibleForTesting final ImmutableMap<String, ?> directPathServiceConfig;
@Nullable private final MtlsProvider mtlsProvider;
@Nullable private final ArrayList<String> allowedValues;
@VisibleForTesting final Map<String, String> headersWithDuplicatesRemoved = new HashMap<>();

@Nullable
Expand All @@ -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;
Expand Down Expand Up @@ -225,6 +228,11 @@ public TransportChannelProvider withEndpoint(String endpoint) {
return toBuilder().setEndpoint(endpoint).build();
}

@Override
public TransportChannelProvider setAllowHardBoundTokens(ArrayList<String> allowedValues) {
return toBuilder().setAllowHardBoundTokens(allowedValues).build();
}

/** @deprecated Please modify pool settings via {@link #toBuilder()} */
@Deprecated
@Override
Expand Down Expand Up @@ -620,6 +628,7 @@ public static final class Builder {
@Nullable private Boolean attemptDirectPathXds;
@Nullable private Boolean allowNonDefaultServiceAccount;
@Nullable private ImmutableMap<String, ?> directPathServiceConfig;
@Nullable private ArrayList<String> allowedValues;

private Builder() {
processorCount = Runtime.getRuntime().availableProcessors();
Expand Down Expand Up @@ -700,6 +709,11 @@ public Builder setEndpoint(String endpoint) {
return this;
}

public Builder setAllowHardBoundTokens(ArrayList<String> allowedValues) {
this.allowedValues = allowedValues;
return this;
}

@VisibleForTesting
Builder setMtlsProvider(MtlsProvider mtlsProvider) {
this.mtlsProvider = mtlsProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -106,6 +107,12 @@ public TransportChannelProvider withEndpoint(String endpoint) {
throw new UnsupportedOperationException("LocalChannelProvider doesn't need an endpoint");
}

@Override
public TransportChannelProvider setAllowHardBoundTokens(ArrayList<String> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -139,6 +140,12 @@ public TransportChannelProvider withPoolSize(int size) {
"InstantiatingHttpJsonChannelProvider doesn't allow pool size customization");
}

@Override
public TransportChannelProvider setAllowHardBoundTokens(ArrayList<String> allowedValues) {
throw new UnsupportedOperationException(
"InstantiatingHttpJsonChannelProvider doesn't support hard-bound tokens");
}

@Override
public String getTransportName() {
return HttpJsonTransportChannel.getHttpJsonTransportName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,6 +69,12 @@ public FixedTransportChannelProvider withExecutor(Executor executor) {
"FixedTransportChannelProvider doesn't need an executor");
}

@Override
public TransportChannelProvider setAllowHardBoundTokens(ArrayList<String> allowedValues) {
throw new UnsupportedOperationException(
"FixedTransportChannelProvider doesn't support hard-bound tokens");
}

@Override
public boolean needsHeaders() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -97,6 +98,9 @@ public interface TransportChannelProvider {
*/
TransportChannelProvider withEndpoint(String endpoint);

/** Sets the allowed hard bound token types. */
TransportChannelProvider setAllowHardBoundTokens(ArrayList<String> allowedValues);

/**
* Reports whether this provider allows pool size customization.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -200,6 +201,17 @@ public boolean acceptsPoolSize() {
return false;
}

@Override
public TransportChannelProvider setAllowHardBoundTokens(ArrayList<String> 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(
Expand Down

0 comments on commit 09eb2b2

Please sign in to comment.