diff --git a/api/src/main/java/io/grpc/ResourceAllocatingChannelCredentials.java b/api/src/main/java/io/grpc/ResourceAllocatingChannelCredentials.java new file mode 100644 index 00000000000..c0443feaac4 --- /dev/null +++ b/api/src/main/java/io/grpc/ResourceAllocatingChannelCredentials.java @@ -0,0 +1,55 @@ +/* + * Copyright 2025 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import java.io.Closeable; + +/** + * {@code ChannelCredentials} which holds allocated resources (e.g. file watchers) upon + * instantiation of a given {@code ChannelCredentials} object, which must be closed once + * mentioned {@code ChannelCredentials} are no longer in use. + */ +public final class ResourceAllocatingChannelCredentials extends ChannelCredentials { + public static ChannelCredentials create( + ChannelCredentials channelCreds, ImmutableList resources) { + return new ResourceAllocatingChannelCredentials(channelCreds, resources); + } + + private final ChannelCredentials channelCreds; + private final ImmutableList resources; + + private ResourceAllocatingChannelCredentials( + ChannelCredentials channelCreds, ImmutableList resources) { + this.channelCreds = Preconditions.checkNotNull(channelCreds, "channelCreds"); + this.resources = Preconditions.checkNotNull(resources, "resources"); + } + + public ChannelCredentials getChannelCredentials() { + return channelCreds; + } + + public ImmutableList getAllocatedResources() { + return resources; + } + + @Override + public ChannelCredentials withoutBearerTokens() { + return channelCreds.withoutBearerTokens(); + } +} diff --git a/api/src/test/java/io/grpc/ResourceAllocatingChannelCredentialsTest.java b/api/src/test/java/io/grpc/ResourceAllocatingChannelCredentialsTest.java new file mode 100644 index 00000000000..2647c3ee0a0 --- /dev/null +++ b/api/src/test/java/io/grpc/ResourceAllocatingChannelCredentialsTest.java @@ -0,0 +1,43 @@ +/* + * Copyright 2025 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.common.collect.ImmutableList; +import java.io.Closeable; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Tests for {@link ResourceAllocatingChannelCredentials}. */ +@RunWith(JUnit4.class) +public class ResourceAllocatingChannelCredentialsTest { + @Test + public void withoutBearerTokenDelegatesCall() { + ChannelCredentials channelChreds = new ChannelCredentials() { + @Override + public ChannelCredentials withoutBearerTokens() { + return this; + } + }; + ImmutableList resources = ImmutableList.of(); + ChannelCredentials creds = + ResourceAllocatingChannelCredentials.create(channelChreds, resources); + assertThat(creds.withoutBearerTokens()).isEqualTo(channelChreds); + } +} diff --git a/xds/src/main/java/io/grpc/xds/GrpcBootstrapperImpl.java b/xds/src/main/java/io/grpc/xds/GrpcBootstrapperImpl.java index f61fab42cae..05e4f49f1d2 100644 --- a/xds/src/main/java/io/grpc/xds/GrpcBootstrapperImpl.java +++ b/xds/src/main/java/io/grpc/xds/GrpcBootstrapperImpl.java @@ -18,7 +18,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableMap; -import io.grpc.ChannelCredentials; +import com.google.common.collect.ImmutableSet; import io.grpc.internal.JsonUtil; import io.grpc.xds.client.BootstrapperImpl; import io.grpc.xds.client.XdsInitializationException; @@ -90,31 +90,32 @@ protected String getJsonContent() throws XdsInitializationException, IOException } @Override - protected Object getImplSpecificConfig(Map serverConfig, String serverUri) + protected ImmutableMap getImplSpecificConfig(Map serverConfig, + String serverUri) throws XdsInitializationException { - return getChannelCredentials(serverConfig, serverUri); + return getChannelCredentialsConfig(serverConfig, serverUri); } - private static ChannelCredentials getChannelCredentials(Map serverConfig, - String serverUri) + private static ImmutableMap getChannelCredentialsConfig(Map serverConfig, + String serverUri) throws XdsInitializationException { List rawChannelCredsList = JsonUtil.getList(serverConfig, "channel_creds"); if (rawChannelCredsList == null || rawChannelCredsList.isEmpty()) { throw new XdsInitializationException( "Invalid bootstrap: server " + serverUri + " 'channel_creds' required"); } - ChannelCredentials channelCredentials = + ImmutableMap channelCredentialsConfig = parseChannelCredentials(JsonUtil.checkObjectList(rawChannelCredsList), serverUri); - if (channelCredentials == null) { + if (channelCredentialsConfig == null) { throw new XdsInitializationException( "Server " + serverUri + ": no supported channel credentials found"); } - return channelCredentials; + return channelCredentialsConfig; } @Nullable - private static ChannelCredentials parseChannelCredentials(List> jsonList, - String serverUri) + private static ImmutableMap parseChannelCredentials(List> jsonList, + String serverUri) throws XdsInitializationException { for (Map channelCreds : jsonList) { String type = JsonUtil.getString(channelCreds, "type"); @@ -122,15 +123,10 @@ private static ChannelCredentials parseChannelCredentials(List> j throw new XdsInitializationException( "Invalid bootstrap: server " + serverUri + " with 'channel_creds' type unspecified"); } - XdsCredentialsProvider provider = XdsCredentialsRegistry.getDefaultRegistry() - .getProvider(type); - if (provider != null) { - Map config = JsonUtil.getObject(channelCreds, "config"); - if (config == null) { - config = ImmutableMap.of(); - } - - return provider.newChannelCredentials(config); + ImmutableSet supportedNames = XdsCredentialsRegistry.getDefaultRegistry() + .getSupportedCredentialNames(); + if (supportedNames.contains(type)) { + return ImmutableMap.copyOf(channelCreds); } } return null; diff --git a/xds/src/main/java/io/grpc/xds/GrpcXdsTransportFactory.java b/xds/src/main/java/io/grpc/xds/GrpcXdsTransportFactory.java index 0da51bf47f7..7192e3b8459 100644 --- a/xds/src/main/java/io/grpc/xds/GrpcXdsTransportFactory.java +++ b/xds/src/main/java/io/grpc/xds/GrpcXdsTransportFactory.java @@ -19,6 +19,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.VisibleForTesting; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import io.grpc.CallCredentials; import io.grpc.CallOptions; import io.grpc.ChannelCredentials; @@ -28,9 +30,15 @@ import io.grpc.ManagedChannel; import io.grpc.Metadata; import io.grpc.MethodDescriptor; +import io.grpc.ResourceAllocatingChannelCredentials; import io.grpc.Status; +import io.grpc.internal.GrpcUtil; +import io.grpc.internal.JsonUtil; import io.grpc.xds.client.Bootstrapper; +import io.grpc.xds.client.XdsInitializationException; import io.grpc.xds.client.XdsTransportFactory; +import java.io.Closeable; +import java.util.Map; import java.util.concurrent.TimeUnit; final class GrpcXdsTransportFactory implements XdsTransportFactory { @@ -42,7 +50,7 @@ final class GrpcXdsTransportFactory implements XdsTransportFactory { } @Override - public XdsTransport create(Bootstrapper.ServerInfo serverInfo) { + public XdsTransport create(Bootstrapper.ServerInfo serverInfo) throws XdsInitializationException { return new GrpcXdsTransport(serverInfo, callCredentials); } @@ -56,8 +64,9 @@ static class GrpcXdsTransport implements XdsTransport { private final ManagedChannel channel; private final CallCredentials callCredentials; + private final ImmutableList resources; - public GrpcXdsTransport(Bootstrapper.ServerInfo serverInfo) { + public GrpcXdsTransport(Bootstrapper.ServerInfo serverInfo) throws XdsInitializationException { this(serverInfo, null); } @@ -66,9 +75,27 @@ public GrpcXdsTransport(ManagedChannel channel) { this(channel, null); } - public GrpcXdsTransport(Bootstrapper.ServerInfo serverInfo, CallCredentials callCredentials) { + public GrpcXdsTransport(Bootstrapper.ServerInfo serverInfo, CallCredentials callCredentials) + throws XdsInitializationException { String target = serverInfo.target(); - ChannelCredentials channelCredentials = (ChannelCredentials) serverInfo.implSpecificConfig(); + Map implSpecificConfig = serverInfo.implSpecificConfig(); + String type = JsonUtil.getString(implSpecificConfig, "type"); + XdsCredentialsProvider provider = XdsCredentialsRegistry.getDefaultRegistry() + .getProvider(type); + Map config = JsonUtil.getObject(implSpecificConfig, "config"); + if (config == null) { + config = ImmutableMap.of(); + } + ChannelCredentials channelCredentials = provider.newChannelCredentials(config); + if (channelCredentials == null) { + throw new XdsInitializationException( + "Cannot create channel credentials of type " + type + " for target " + target); + } + // if {@code ChannelCredentials} instance has allocated resource of any type, save them to be + // released once the channel is shutdown + this.resources = (channelCredentials instanceof ResourceAllocatingChannelCredentials) + ? ((ResourceAllocatingChannelCredentials) channelCredentials).getAllocatedResources() + : ImmutableList.of(); this.channel = Grpc.newChannelBuilder(target, channelCredentials) .keepAliveTime(5, TimeUnit.MINUTES) .build(); @@ -79,6 +106,7 @@ public GrpcXdsTransport(Bootstrapper.ServerInfo serverInfo, CallCredentials call public GrpcXdsTransport(ManagedChannel channel, CallCredentials callCredentials) { this.channel = checkNotNull(channel, "channel"); this.callCredentials = callCredentials; + this.resources = ImmutableList.of(); } @Override @@ -99,6 +127,9 @@ public StreamingCall createStreamingCall( @Override public void shutdown() { channel.shutdown(); + for (Closeable resource : resources) { + GrpcUtil.closeQuietly(resource); + } } private class XdsStreamingCall implements diff --git a/xds/src/main/java/io/grpc/xds/XdsCredentialsRegistry.java b/xds/src/main/java/io/grpc/xds/XdsCredentialsRegistry.java index 9dfefaf1a65..b78bbff6a23 100644 --- a/xds/src/main/java/io/grpc/xds/XdsCredentialsRegistry.java +++ b/xds/src/main/java/io/grpc/xds/XdsCredentialsRegistry.java @@ -21,6 +21,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import com.google.errorprone.annotations.concurrent.GuardedBy; import io.grpc.InternalServiceProviders; import java.util.ArrayList; @@ -147,6 +148,14 @@ public synchronized XdsCredentialsProvider getProvider(String name) { return effectiveProviders.get(checkNotNull(name, "name")); } + /** + * Returns list of registered xds credential names. Each provider declares its name via + * {@link XdsCredentialsProvider#getName}. + */ + public synchronized ImmutableSet getSupportedCredentialNames() { + return effectiveProviders.keySet(); + } + @VisibleForTesting static List> getHardCodedClasses() { // Class.forName(String) is used to remove the need for ProGuard configuration. Note that diff --git a/xds/src/main/java/io/grpc/xds/client/Bootstrapper.java b/xds/src/main/java/io/grpc/xds/client/Bootstrapper.java index 4fa75f6b335..c3ae86fa9bf 100644 --- a/xds/src/main/java/io/grpc/xds/client/Bootstrapper.java +++ b/xds/src/main/java/io/grpc/xds/client/Bootstrapper.java @@ -57,7 +57,7 @@ public BootstrapInfo bootstrap(Map rawData) throws XdsInitializationE public abstract static class ServerInfo { public abstract String target(); - public abstract Object implSpecificConfig(); + public abstract ImmutableMap implSpecificConfig(); public abstract boolean ignoreResourceDeletion(); @@ -66,14 +66,15 @@ public abstract static class ServerInfo { public abstract boolean resourceTimerIsTransientError(); @VisibleForTesting - public static ServerInfo create(String target, @Nullable Object implSpecificConfig) { + public static ServerInfo create( + String target, @Nullable ImmutableMap implSpecificConfig) { return new AutoValue_Bootstrapper_ServerInfo(target, implSpecificConfig, false, false, false); } @VisibleForTesting public static ServerInfo create( - String target, Object implSpecificConfig, boolean ignoreResourceDeletion, + String target, ImmutableMap implSpecificConfig, boolean ignoreResourceDeletion, boolean isTrustedXdsServer, boolean resourceTimerIsTransientError) { return new AutoValue_Bootstrapper_ServerInfo(target, implSpecificConfig, ignoreResourceDeletion, isTrustedXdsServer, resourceTimerIsTransientError); diff --git a/xds/src/main/java/io/grpc/xds/client/BootstrapperImpl.java b/xds/src/main/java/io/grpc/xds/client/BootstrapperImpl.java index 423c1a118e8..ead67640a75 100644 --- a/xds/src/main/java/io/grpc/xds/client/BootstrapperImpl.java +++ b/xds/src/main/java/io/grpc/xds/client/BootstrapperImpl.java @@ -76,8 +76,8 @@ protected BootstrapperImpl() { protected abstract String getJsonContent() throws IOException, XdsInitializationException; - protected abstract Object getImplSpecificConfig(Map serverConfig, String serverUri) - throws XdsInitializationException; + protected abstract ImmutableMap getImplSpecificConfig( + Map serverConfig, String serverUri) throws XdsInitializationException; /** @@ -253,7 +253,7 @@ private List parseServerInfos(List rawServerConfigs, XdsLogger lo } logger.log(XdsLogLevel.INFO, "xDS server URI: {0}", serverUri); - Object implSpecificConfig = getImplSpecificConfig(serverConfig, serverUri); + ImmutableMap implSpecificConfig = getImplSpecificConfig(serverConfig, serverUri); boolean resourceTimerIsTransientError = false; boolean ignoreResourceDeletion = false; diff --git a/xds/src/main/java/io/grpc/xds/client/XdsTransportFactory.java b/xds/src/main/java/io/grpc/xds/client/XdsTransportFactory.java index ec700bd6dc9..8ad48098842 100644 --- a/xds/src/main/java/io/grpc/xds/client/XdsTransportFactory.java +++ b/xds/src/main/java/io/grpc/xds/client/XdsTransportFactory.java @@ -25,7 +25,7 @@ */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/10823") public interface XdsTransportFactory { - XdsTransport create(Bootstrapper.ServerInfo serverInfo); + XdsTransport create(Bootstrapper.ServerInfo serverInfo) throws XdsInitializationException; /** * Represents transport for xDS communication (e.g., a gRPC channel). diff --git a/xds/src/test/java/io/grpc/xds/ClusterImplLoadBalancerTest.java b/xds/src/test/java/io/grpc/xds/ClusterImplLoadBalancerTest.java index 7df0630b779..1dcec49f9ca 100644 --- a/xds/src/test/java/io/grpc/xds/ClusterImplLoadBalancerTest.java +++ b/xds/src/test/java/io/grpc/xds/ClusterImplLoadBalancerTest.java @@ -34,7 +34,6 @@ import io.grpc.ConnectivityState; import io.grpc.ConnectivityStateInfo; import io.grpc.EquivalentAddressGroup; -import io.grpc.InsecureChannelCredentials; import io.grpc.LoadBalancer; import io.grpc.LoadBalancer.CreateSubchannelArgs; import io.grpc.LoadBalancer.FixedResultPicker; @@ -116,7 +115,7 @@ public class ClusterImplLoadBalancerTest { private static final String CLUSTER = "cluster-foo.googleapis.com"; private static final String EDS_SERVICE_NAME = "service.googleapis.com"; private static final ServerInfo LRS_SERVER_INFO = - ServerInfo.create("api.google.com", InsecureChannelCredentials.create()); + ServerInfo.create("api.google.com", ImmutableMap.of("type", "insecure")); private static final Metadata.Key ORCA_ENDPOINT_LOAD_METRICS_KEY = Metadata.Key.of( "endpoint-load-metrics-bin", diff --git a/xds/src/test/java/io/grpc/xds/ClusterResolverLoadBalancerTest.java b/xds/src/test/java/io/grpc/xds/ClusterResolverLoadBalancerTest.java index 982677d24da..d9304e25f06 100644 --- a/xds/src/test/java/io/grpc/xds/ClusterResolverLoadBalancerTest.java +++ b/xds/src/test/java/io/grpc/xds/ClusterResolverLoadBalancerTest.java @@ -38,7 +38,6 @@ import io.grpc.ConnectivityState; import io.grpc.EquivalentAddressGroup; import io.grpc.HttpConnectProxiedSocketAddress; -import io.grpc.InsecureChannelCredentials; import io.grpc.LoadBalancer; import io.grpc.LoadBalancer.Helper; import io.grpc.LoadBalancer.PickResult; @@ -126,7 +125,7 @@ public class ClusterResolverLoadBalancerTest { private static final String EDS_SERVICE_NAME2 = "backend-service-bar.googleapis.com"; private static final String DNS_HOST_NAME = "dns-service.googleapis.com"; private static final ServerInfo LRS_SERVER_INFO = - ServerInfo.create("lrs.googleapis.com", InsecureChannelCredentials.create()); + ServerInfo.create("lrs.googleapis.com", ImmutableMap.of("type", "insecure")); private final Locality locality1 = Locality.create("test-region-1", "test-zone-1", "test-subzone-1"); private final Locality locality2 = diff --git a/xds/src/test/java/io/grpc/xds/CsdsServiceTest.java b/xds/src/test/java/io/grpc/xds/CsdsServiceTest.java index 573aef7ca1e..6fe56efa214 100644 --- a/xds/src/test/java/io/grpc/xds/CsdsServiceTest.java +++ b/xds/src/test/java/io/grpc/xds/CsdsServiceTest.java @@ -38,7 +38,6 @@ import io.envoyproxy.envoy.service.status.v3.ClientStatusResponse; import io.envoyproxy.envoy.type.matcher.v3.NodeMatcher; import io.grpc.Deadline; -import io.grpc.InsecureChannelCredentials; import io.grpc.MetricRecorder; import io.grpc.Status; import io.grpc.Status.Code; @@ -79,7 +78,7 @@ public class CsdsServiceTest { EnvoyProtoData.Node.newBuilder().setId(NODE_ID).build(); private static final BootstrapInfo BOOTSTRAP_INFO = BootstrapInfo.builder() .servers(ImmutableList.of( - ServerInfo.create(SERVER_URI, InsecureChannelCredentials.create()))) + ServerInfo.create(SERVER_URI, ImmutableMap.of("type", "insecure")))) .node(BOOTSTRAP_NODE) .build(); private static final FakeXdsClient XDS_CLIENT_NO_RESOURCES = new FakeXdsClient(); diff --git a/xds/src/test/java/io/grpc/xds/GrpcBootstrapperImplTest.java b/xds/src/test/java/io/grpc/xds/GrpcBootstrapperImplTest.java index 3f93cc6f191..b8bcbf3c1b2 100644 --- a/xds/src/test/java/io/grpc/xds/GrpcBootstrapperImplTest.java +++ b/xds/src/test/java/io/grpc/xds/GrpcBootstrapperImplTest.java @@ -24,8 +24,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; -import io.grpc.InsecureChannelCredentials; -import io.grpc.TlsChannelCredentials; import io.grpc.internal.GrpcUtil; import io.grpc.internal.GrpcUtil.GrpcBuildVersion; import io.grpc.xds.client.Bootstrapper; @@ -115,7 +113,7 @@ public void parseBootstrap_singleXdsServer() throws XdsInitializationException { assertThat(info.servers()).hasSize(1); ServerInfo serverInfo = Iterables.getOnlyElement(info.servers()); assertThat(serverInfo.target()).isEqualTo(SERVER_URI); - assertThat(serverInfo.implSpecificConfig()).isInstanceOf(InsecureChannelCredentials.class); + assertThat(serverInfo.implSpecificConfig()).isEqualTo(ImmutableMap.of("type", "insecure")); assertThat(info.node()).isEqualTo( getNodeBuilder() .setId("ENVOY_NODE_ID") @@ -169,11 +167,11 @@ public void parseBootstrap_multipleXdsServers() throws XdsInitializationExceptio assertThat(serverInfoList.get(0).target()) .isEqualTo("trafficdirector-foo.googleapis.com:443"); assertThat(serverInfoList.get(0).implSpecificConfig()) - .isInstanceOf(TlsChannelCredentials.class); + .isEqualTo(ImmutableMap.of("type", "tls")); assertThat(serverInfoList.get(1).target()) .isEqualTo("trafficdirector-bar.googleapis.com:443"); assertThat(serverInfoList.get(1).implSpecificConfig()) - .isInstanceOf(InsecureChannelCredentials.class); + .isEqualTo(ImmutableMap.of("type", "insecure")); assertThat(info.node()).isEqualTo( getNodeBuilder() .setId("ENVOY_NODE_ID") @@ -217,7 +215,7 @@ public void parseBootstrap_IgnoreIrrelevantFields() throws XdsInitializationExce assertThat(info.servers()).hasSize(1); ServerInfo serverInfo = Iterables.getOnlyElement(info.servers()); assertThat(serverInfo.target()).isEqualTo(SERVER_URI); - assertThat(serverInfo.implSpecificConfig()).isInstanceOf(InsecureChannelCredentials.class); + assertThat(serverInfo.implSpecificConfig()).isEqualTo(ImmutableMap.of("type", "insecure"));; assertThat(info.node()).isEqualTo( getNodeBuilder() .setId("ENVOY_NODE_ID") @@ -288,7 +286,7 @@ public void parseBootstrap_useFirstSupportedChannelCredentials() assertThat(info.servers()).hasSize(1); ServerInfo serverInfo = Iterables.getOnlyElement(info.servers()); assertThat(serverInfo.target()).isEqualTo(SERVER_URI); - assertThat(serverInfo.implSpecificConfig()).isInstanceOf(InsecureChannelCredentials.class); + assertThat(serverInfo.implSpecificConfig()).isEqualTo(ImmutableMap.of("type", "insecure"));; assertThat(info.node()).isEqualTo(getNodeBuilder().build()); } @@ -583,7 +581,7 @@ public void useV2ProtocolByDefault() throws XdsInitializationException { BootstrapInfo info = bootstrapper.bootstrap(); ServerInfo serverInfo = Iterables.getOnlyElement(info.servers()); assertThat(serverInfo.target()).isEqualTo(SERVER_URI); - assertThat(serverInfo.implSpecificConfig()).isInstanceOf(InsecureChannelCredentials.class); + assertThat(serverInfo.implSpecificConfig()).isEqualTo(ImmutableMap.of("type", "insecure")); assertThat(serverInfo.ignoreResourceDeletion()).isFalse(); } @@ -605,7 +603,7 @@ public void useV3ProtocolIfV3FeaturePresent() throws XdsInitializationException BootstrapInfo info = bootstrapper.bootstrap(); ServerInfo serverInfo = Iterables.getOnlyElement(info.servers()); assertThat(serverInfo.target()).isEqualTo(SERVER_URI); - assertThat(serverInfo.implSpecificConfig()).isInstanceOf(InsecureChannelCredentials.class); + assertThat(serverInfo.implSpecificConfig()).isEqualTo(ImmutableMap.of("type", "insecure")); assertThat(serverInfo.ignoreResourceDeletion()).isFalse(); } @@ -627,7 +625,7 @@ public void serverFeatureIgnoreResourceDeletion() throws XdsInitializationExcept BootstrapInfo info = bootstrapper.bootstrap(); ServerInfo serverInfo = Iterables.getOnlyElement(info.servers()); assertThat(serverInfo.target()).isEqualTo(SERVER_URI); - assertThat(serverInfo.implSpecificConfig()).isInstanceOf(InsecureChannelCredentials.class); + assertThat(serverInfo.implSpecificConfig()).isEqualTo(ImmutableMap.of("type", "insecure")); // Only ignore_resource_deletion feature enabled: confirm it's on, and xds_v3 is off. assertThat(serverInfo.ignoreResourceDeletion()).isTrue(); } @@ -650,7 +648,7 @@ public void serverFeatureTrustedXdsServer() throws XdsInitializationException { BootstrapInfo info = bootstrapper.bootstrap(); ServerInfo serverInfo = Iterables.getOnlyElement(info.servers()); assertThat(serverInfo.target()).isEqualTo(SERVER_URI); - assertThat(serverInfo.implSpecificConfig()).isInstanceOf(InsecureChannelCredentials.class); + assertThat(serverInfo.implSpecificConfig()).isEqualTo(ImmutableMap.of("type", "insecure")); assertThat(serverInfo.isTrustedXdsServer()).isTrue(); } @@ -672,7 +670,7 @@ public void serverFeatureIgnoreResourceDeletion_xdsV3() throws XdsInitialization BootstrapInfo info = bootstrapper.bootstrap(); ServerInfo serverInfo = Iterables.getOnlyElement(info.servers()); assertThat(serverInfo.target()).isEqualTo(SERVER_URI); - assertThat(serverInfo.implSpecificConfig()).isInstanceOf(InsecureChannelCredentials.class); + assertThat(serverInfo.implSpecificConfig()).isEqualTo(ImmutableMap.of("type", "insecure")); // ignore_resource_deletion features enabled: confirm both are on. assertThat(serverInfo.ignoreResourceDeletion()).isTrue(); } diff --git a/xds/src/test/java/io/grpc/xds/GrpcXdsClientImplDataTest.java b/xds/src/test/java/io/grpc/xds/GrpcXdsClientImplDataTest.java index 3650e5d5bb9..2ab8b833db5 100644 --- a/xds/src/test/java/io/grpc/xds/GrpcXdsClientImplDataTest.java +++ b/xds/src/test/java/io/grpc/xds/GrpcXdsClientImplDataTest.java @@ -113,7 +113,6 @@ import io.envoyproxy.envoy.type.v3.FractionalPercent.DenominatorType; import io.envoyproxy.envoy.type.v3.Int64Range; import io.grpc.EquivalentAddressGroup; -import io.grpc.InsecureChannelCredentials; import io.grpc.LoadBalancerRegistry; import io.grpc.Status.Code; import io.grpc.internal.JsonUtil; @@ -168,7 +167,7 @@ public class GrpcXdsClientImplDataTest { private static final RouterFilter.Provider ROUTER_FILTER_PROVIDER = new RouterFilter.Provider(); private static final ServerInfo LRS_SERVER_INFO = - ServerInfo.create("lrs.googleapis.com", InsecureChannelCredentials.create()); + ServerInfo.create("lrs.googleapis.com", ImmutableMap.of("type", "insecure")); private static final String GRPC_EXPERIMENTAL_XDS_AUTHORITY_REWRITE = "GRPC_EXPERIMENTAL_XDS_AUTHORITY_REWRITE"; @@ -3549,7 +3548,7 @@ private static Filter buildHttpConnectionManagerFilter(HttpFilter... httpFilters private XdsResourceType.Args getXdsResourceTypeArgs(boolean isTrustedServer) { return new XdsResourceType.Args( - ServerInfo.create("http://td", "", false, isTrustedServer, false), "1.0", null, null, null, null + ServerInfo.create("http://td", ImmutableMap.of(), false, isTrustedServer, false), "1.0", null, null, null, null ); } } diff --git a/xds/src/test/java/io/grpc/xds/GrpcXdsClientImplTestBase.java b/xds/src/test/java/io/grpc/xds/GrpcXdsClientImplTestBase.java index 9ff19c6d1b0..b560c8c2994 100644 --- a/xds/src/test/java/io/grpc/xds/GrpcXdsClientImplTestBase.java +++ b/xds/src/test/java/io/grpc/xds/GrpcXdsClientImplTestBase.java @@ -48,10 +48,8 @@ import io.envoyproxy.envoy.extensions.filters.http.router.v3.Router; import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateProviderPluginInstance; import io.grpc.BindableService; -import io.grpc.ChannelCredentials; import io.grpc.Context; import io.grpc.Context.CancellableContext; -import io.grpc.InsecureChannelCredentials; import io.grpc.ManagedChannel; import io.grpc.Server; import io.grpc.Status; @@ -160,7 +158,6 @@ public abstract class GrpcXdsClientImplTestBase { private static final String NODE_ID = "cool-node-id"; private static final Node NODE = Node.newBuilder().setId(NODE_ID).build(); private static final Any FAILING_ANY = MessageFactory.FAILING_ANY; - private static final ChannelCredentials CHANNEL_CREDENTIALS = InsecureChannelCredentials.create(); private static final XdsResourceType LDS = XdsListenerResource.getInstance(); private static final XdsResourceType CDS = XdsClusterResource.getInstance(); private static final XdsResourceType RDS = XdsRouteConfigureResource.getInstance(); @@ -361,7 +358,8 @@ public void setUp() throws IOException { channel = cleanupRule.register(InProcessChannelBuilder.forName(serverName).directExecutor().build()); - xdsServerInfo = ServerInfo.create(SERVER_URI, CHANNEL_CREDENTIALS, ignoreResourceDeletion(), + xdsServerInfo = ServerInfo.create( + SERVER_URI, ImmutableMap.of("type", "insecure"), ignoreResourceDeletion(), true, false); BootstrapInfo bootstrapInfo = Bootstrapper.BootstrapInfo.builder() @@ -372,12 +370,12 @@ public void setUp() throws IOException { AuthorityInfo.create( "xdstp://authority.xds.com/envoy.config.listener.v3.Listener/%s", ImmutableList.of(Bootstrapper.ServerInfo.create( - SERVER_URI_CUSTOM_AUTHORITY, CHANNEL_CREDENTIALS))), + SERVER_URI_CUSTOM_AUTHORITY, ImmutableMap.of("type", "insecure")))), "", AuthorityInfo.create( "xdstp:///envoy.config.listener.v3.Listener/%s", ImmutableList.of(Bootstrapper.ServerInfo.create( - SERVER_URI_EMPTY_AUTHORITY, CHANNEL_CREDENTIALS))))) + SERVER_URI_EMPTY_AUTHORITY, ImmutableMap.of("type", "insecure")))))) .certProviders(ImmutableMap.of("cert-instance-name", CertificateProviderInfo.create("file-watcher", ImmutableMap.of()))) .build(); @@ -3191,7 +3189,7 @@ public void flowControlAbsent() throws Exception { @Test public void resourceTimerIsTransientError_schedulesExtendedTimeout() { BootstrapperImpl.xdsDataErrorHandlingEnabled = true; - ServerInfo serverInfo = ServerInfo.create(SERVER_URI, CHANNEL_CREDENTIALS, + ServerInfo serverInfo = ServerInfo.create(SERVER_URI, ImmutableMap.of("type", "insecure"), false, true, true); BootstrapInfo bootstrapInfo = Bootstrapper.BootstrapInfo.builder() @@ -3202,7 +3200,7 @@ public void resourceTimerIsTransientError_schedulesExtendedTimeout() { AuthorityInfo.create( "xdstp:///envoy.config.listener.v3.Listener/%s", ImmutableList.of(Bootstrapper.ServerInfo.create( - SERVER_URI_EMPTY_AUTHORITY, CHANNEL_CREDENTIALS))))) + SERVER_URI_EMPTY_AUTHORITY, ImmutableMap.of("type", "insecure")))))) .certProviders(ImmutableMap.of()) .build(); xdsClient = new XdsClientImpl( @@ -3236,8 +3234,8 @@ public void resourceTimerIsTransientError_schedulesExtendedTimeout() { @Test public void resourceTimerIsTransientError_callsOnErrorUnavailable() { BootstrapperImpl.xdsDataErrorHandlingEnabled = true; - xdsServerInfo = ServerInfo.create(SERVER_URI, CHANNEL_CREDENTIALS, ignoreResourceDeletion(), - true, true); + xdsServerInfo = ServerInfo.create( + SERVER_URI, ImmutableMap.of("type", "insecure"), ignoreResourceDeletion(), true, true); BootstrapInfo bootstrapInfo = Bootstrapper.BootstrapInfo.builder() .servers(Collections.singletonList(xdsServerInfo)) @@ -3247,12 +3245,12 @@ public void resourceTimerIsTransientError_callsOnErrorUnavailable() { AuthorityInfo.create( "xdstp://authority.xds.com/envoy.config.listener.v3.Listener/%s", ImmutableList.of(Bootstrapper.ServerInfo.create( - SERVER_URI_CUSTOM_AUTHORITY, CHANNEL_CREDENTIALS))), + SERVER_URI_CUSTOM_AUTHORITY, ImmutableMap.of("type", "insecure")))), "", AuthorityInfo.create( "xdstp:///envoy.config.listener.v3.Listener/%s", ImmutableList.of(Bootstrapper.ServerInfo.create( - SERVER_URI_EMPTY_AUTHORITY, CHANNEL_CREDENTIALS))))) + SERVER_URI_EMPTY_AUTHORITY, ImmutableMap.of("type", "insecure")))))) .certProviders(ImmutableMap.of("cert-instance-name", CertificateProviderInfo.create("file-watcher", ImmutableMap.of()))) .build(); @@ -4354,7 +4352,7 @@ private XdsClientImpl createXdsClient(String serverUri) { private BootstrapInfo buildBootStrap(String serverUri) { - ServerInfo xdsServerInfo = ServerInfo.create(serverUri, CHANNEL_CREDENTIALS, + ServerInfo xdsServerInfo = ServerInfo.create(serverUri, ImmutableMap.of("type", "insecure"), ignoreResourceDeletion(), true, false); return Bootstrapper.BootstrapInfo.builder() @@ -4365,12 +4363,12 @@ private BootstrapInfo buildBootStrap(String serverUri) { AuthorityInfo.create( "xdstp://authority.xds.com/envoy.config.listener.v3.Listener/%s", ImmutableList.of(Bootstrapper.ServerInfo.create( - SERVER_URI_CUSTOM_AUTHORITY, CHANNEL_CREDENTIALS))), + SERVER_URI_CUSTOM_AUTHORITY, ImmutableMap.of("type", "insecure")))), "", AuthorityInfo.create( "xdstp:///envoy.config.listener.v3.Listener/%s", ImmutableList.of(Bootstrapper.ServerInfo.create( - SERVER_URI_EMPTY_AUTHORITY, CHANNEL_CREDENTIALS))))) + SERVER_URI_EMPTY_AUTHORITY, ImmutableMap.of("type", "insecure")))))) .certProviders(ImmutableMap.of("cert-instance-name", CertificateProviderInfo.create("file-watcher", ImmutableMap.of()))) .build(); diff --git a/xds/src/test/java/io/grpc/xds/GrpcXdsTransportFactoryTest.java b/xds/src/test/java/io/grpc/xds/GrpcXdsTransportFactoryTest.java index 66e0d4b3198..92a9ff44ccf 100644 --- a/xds/src/test/java/io/grpc/xds/GrpcXdsTransportFactoryTest.java +++ b/xds/src/test/java/io/grpc/xds/GrpcXdsTransportFactoryTest.java @@ -18,13 +18,13 @@ import static com.google.common.truth.Truth.assertThat; +import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.SettableFuture; import io.envoyproxy.envoy.service.discovery.v3.AggregatedDiscoveryServiceGrpc; import io.envoyproxy.envoy.service.discovery.v3.DiscoveryRequest; import io.envoyproxy.envoy.service.discovery.v3.DiscoveryResponse; import io.grpc.BindableService; import io.grpc.Grpc; -import io.grpc.InsecureChannelCredentials; import io.grpc.InsecureServerCredentials; import io.grpc.MethodDescriptor; import io.grpc.Server; @@ -95,7 +95,7 @@ public void callApis() throws Exception { new GrpcXdsTransportFactory(null) .create( Bootstrapper.ServerInfo.create( - "localhost:" + server.getPort(), InsecureChannelCredentials.create())); + "localhost:" + server.getPort(), ImmutableMap.of("type", "insecure"))); MethodDescriptor methodDescriptor = AggregatedDiscoveryServiceGrpc.getStreamAggregatedResourcesMethod(); XdsTransportFactory.StreamingCall streamingCall = diff --git a/xds/src/test/java/io/grpc/xds/SharedXdsClientPoolProviderTest.java b/xds/src/test/java/io/grpc/xds/SharedXdsClientPoolProviderTest.java index 24f1750d5a8..467a73c275e 100644 --- a/xds/src/test/java/io/grpc/xds/SharedXdsClientPoolProviderTest.java +++ b/xds/src/test/java/io/grpc/xds/SharedXdsClientPoolProviderTest.java @@ -26,10 +26,10 @@ import com.google.auth.oauth2.AccessToken; import com.google.auth.oauth2.OAuth2Credentials; +import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.SettableFuture; import io.grpc.CallCredentials; import io.grpc.Grpc; -import io.grpc.InsecureChannelCredentials; import io.grpc.InsecureServerCredentials; import io.grpc.Metadata; import io.grpc.MetricRecorder; @@ -88,7 +88,7 @@ public void noServer() throws XdsInitializationException { @Test public void sharedXdsClientObjectPool() throws XdsInitializationException { - ServerInfo server = ServerInfo.create(SERVER_URI, InsecureChannelCredentials.create()); + ServerInfo server = ServerInfo.create(SERVER_URI, ImmutableMap.of("type", "insecure")); BootstrapInfo bootstrapInfo = BootstrapInfo.builder().servers(Collections.singletonList(server)).node(node).build(); when(bootstrapper.bootstrap()).thenReturn(bootstrapInfo); @@ -105,7 +105,7 @@ public void sharedXdsClientObjectPool() throws XdsInitializationException { @Test public void refCountedXdsClientObjectPool_delayedCreation() { - ServerInfo server = ServerInfo.create(SERVER_URI, InsecureChannelCredentials.create()); + ServerInfo server = ServerInfo.create(SERVER_URI, ImmutableMap.of("type", "insecure")); BootstrapInfo bootstrapInfo = BootstrapInfo.builder().servers(Collections.singletonList(server)).node(node).build(); SharedXdsClientPoolProvider provider = new SharedXdsClientPoolProvider(bootstrapper); @@ -119,7 +119,7 @@ public void refCountedXdsClientObjectPool_delayedCreation() { @Test public void refCountedXdsClientObjectPool_refCounted() { - ServerInfo server = ServerInfo.create(SERVER_URI, InsecureChannelCredentials.create()); + ServerInfo server = ServerInfo.create(SERVER_URI, ImmutableMap.of("type", "insecure")); BootstrapInfo bootstrapInfo = BootstrapInfo.builder().servers(Collections.singletonList(server)).node(node).build(); SharedXdsClientPoolProvider provider = new SharedXdsClientPoolProvider(bootstrapper); @@ -140,7 +140,7 @@ public void refCountedXdsClientObjectPool_refCounted() { @Test public void refCountedXdsClientObjectPool_getObjectCreatesNewInstanceIfAlreadyShutdown() { - ServerInfo server = ServerInfo.create(SERVER_URI, InsecureChannelCredentials.create()); + ServerInfo server = ServerInfo.create(SERVER_URI, ImmutableMap.of("type", "insecure")); BootstrapInfo bootstrapInfo = BootstrapInfo.builder().servers(Collections.singletonList(server)).node(node).build(); SharedXdsClientPoolProvider provider = new SharedXdsClientPoolProvider(bootstrapper); @@ -186,7 +186,7 @@ public void xdsClient_usesCallCredentials() throws Exception { String xdsServerUri = "localhost:" + xdsServer.getPort(); // Set up bootstrap & xDS client pool provider - ServerInfo server = ServerInfo.create(xdsServerUri, InsecureChannelCredentials.create()); + ServerInfo server = ServerInfo.create(xdsServerUri, ImmutableMap.of("type", "insecure")); BootstrapInfo bootstrapInfo = BootstrapInfo.builder().servers(Collections.singletonList(server)).node(node).build(); when(bootstrapper.bootstrap()).thenReturn(bootstrapInfo); diff --git a/xds/src/test/java/io/grpc/xds/XdsClientFallbackTest.java b/xds/src/test/java/io/grpc/xds/XdsClientFallbackTest.java index 1e7ce6dc2a2..d0af40d3fcc 100644 --- a/xds/src/test/java/io/grpc/xds/XdsClientFallbackTest.java +++ b/xds/src/test/java/io/grpc/xds/XdsClientFallbackTest.java @@ -36,6 +36,7 @@ import io.grpc.Status; import io.grpc.internal.ExponentialBackoffPolicy; import io.grpc.internal.FakeClock; +import io.grpc.internal.JsonUtil; import io.grpc.internal.ObjectPool; import io.grpc.xds.client.Bootstrapper; import io.grpc.xds.client.CommonBootstrapperTestUtils; @@ -346,8 +347,15 @@ public void connect_then_mainServerDown_fallbackServerUp() throws Exception { XdsTransportFactory xdsTransportFactory = new XdsTransportFactory() { @Override public XdsTransport create(Bootstrapper.ServerInfo serverInfo) { - ChannelCredentials channelCredentials = - (ChannelCredentials) serverInfo.implSpecificConfig(); + ImmutableMap implSpecificConfig = serverInfo.implSpecificConfig(); + String type = JsonUtil.getString(implSpecificConfig, "type"); + XdsCredentialsProvider provider = XdsCredentialsRegistry.getDefaultRegistry() + .getProvider(type); + Map config = JsonUtil.getObject(implSpecificConfig, "config"); + if (config == null) { + config = ImmutableMap.of(); + } + ChannelCredentials channelCredentials = provider.newChannelCredentials(config); return new GrpcXdsTransportFactory.GrpcXdsTransport( Grpc.newChannelBuilder(serverInfo.target(), channelCredentials) .executor(executor) diff --git a/xds/src/test/java/io/grpc/xds/XdsNameResolverTest.java b/xds/src/test/java/io/grpc/xds/XdsNameResolverTest.java index b50bdfce01f..325c298697e 100644 --- a/xds/src/test/java/io/grpc/xds/XdsNameResolverTest.java +++ b/xds/src/test/java/io/grpc/xds/XdsNameResolverTest.java @@ -52,7 +52,6 @@ import io.grpc.ClientInterceptor; import io.grpc.ClientInterceptors; import io.grpc.Deadline; -import io.grpc.InsecureChannelCredentials; import io.grpc.InternalConfigSelector; import io.grpc.InternalConfigSelector.Result; import io.grpc.LoadBalancer.PickDetailsConsumer; @@ -176,7 +175,7 @@ public ConfigOrError parseServiceConfig(Map rawServiceConfig) { private final MetricRecorder metricRecorder = new MetricRecorder() {}; private BootstrapInfo bootstrapInfo = BootstrapInfo.builder() .servers(ImmutableList.of(ServerInfo.create( - "td.googleapis.com", InsecureChannelCredentials.create()))) + "td.googleapis.com", ImmutableMap.of("type", "insecure")))) .node(Node.newBuilder().build()) .build(); private String expectedLdsResourceName = AUTHORITY; @@ -301,7 +300,7 @@ public void resolving_withTargetAuthorityNotFound() { public void resolving_noTargetAuthority_templateWithoutXdstp() { bootstrapInfo = BootstrapInfo.builder() .servers(ImmutableList.of(ServerInfo.create( - "td.googleapis.com", InsecureChannelCredentials.create()))) + "td.googleapis.com", ImmutableMap.of("type", "insecure")))) .node(Node.newBuilder().build()) .clientDefaultListenerResourceNameTemplate("%s/id=1") .build(); @@ -319,7 +318,7 @@ public void resolving_noTargetAuthority_templateWithoutXdstp() { public void resolving_noTargetAuthority_templateWithXdstp() { bootstrapInfo = BootstrapInfo.builder() .servers(ImmutableList.of(ServerInfo.create( - "td.googleapis.com", InsecureChannelCredentials.create()))) + "td.googleapis.com", ImmutableMap.of("type", "insecure")))) .node(Node.newBuilder().build()) .clientDefaultListenerResourceNameTemplate( "xdstp://xds.authority.com/envoy.config.listener.v3.Listener/%s?id=1") @@ -340,7 +339,7 @@ public void resolving_noTargetAuthority_templateWithXdstp() { public void resolving_noTargetAuthority_xdstpWithMultipleSlashes() { bootstrapInfo = BootstrapInfo.builder() .servers(ImmutableList.of(ServerInfo.create( - "td.googleapis.com", InsecureChannelCredentials.create()))) + "td.googleapis.com", ImmutableMap.of("type", "insecure")))) .node(Node.newBuilder().build()) .clientDefaultListenerResourceNameTemplate( "xdstp://xds.authority.com/envoy.config.listener.v3.Listener/%s?id=1") @@ -368,13 +367,13 @@ public void resolving_targetAuthorityInAuthoritiesMap() { String serviceAuthority = "[::FFFF:129.144.52.38]:80"; bootstrapInfo = BootstrapInfo.builder() .servers(ImmutableList.of(ServerInfo.create( - "td.googleapis.com", InsecureChannelCredentials.create(), true, true, false))) + "td.googleapis.com", ImmutableMap.of("type", "insecure"), true, true, false))) .node(Node.newBuilder().build()) .authorities( ImmutableMap.of(targetAuthority, AuthorityInfo.create( "xdstp://" + targetAuthority + "/envoy.config.listener.v3.Listener/%s?foo=1&bar=2", ImmutableList.of(ServerInfo.create( - "td.googleapis.com", InsecureChannelCredentials.create(), true, true, false))))) + "td.googleapis.com", ImmutableMap.of("type", "insecure"), true, true, false))))) .build(); expectedLdsResourceName = "xdstp://xds.authority.com/envoy.config.listener.v3.Listener/" + "%5B::FFFF:129.144.52.38%5D:80?bar=2&foo=1"; // query param canonified @@ -407,7 +406,7 @@ public void resolving_ldsResourceUpdateRdsName() { ImmutableMap.of()); bootstrapInfo = BootstrapInfo.builder() .servers(ImmutableList.of(ServerInfo.create( - "td.googleapis.com", InsecureChannelCredentials.create()))) + "td.googleapis.com", ImmutableMap.of("type", "insecure")))) .clientDefaultListenerResourceNameTemplate("test-%s") .node(Node.newBuilder().build()) .build(); diff --git a/xds/src/test/java/io/grpc/xds/XdsServerTestHelper.java b/xds/src/test/java/io/grpc/xds/XdsServerTestHelper.java index b0472b4729d..d6cf54870af 100644 --- a/xds/src/test/java/io/grpc/xds/XdsServerTestHelper.java +++ b/xds/src/test/java/io/grpc/xds/XdsServerTestHelper.java @@ -22,7 +22,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.SettableFuture; import io.envoyproxy.envoy.config.core.v3.SocketAddress.Protocol; -import io.grpc.InsecureChannelCredentials; import io.grpc.MetricRecorder; import io.grpc.internal.ObjectPool; import io.grpc.xds.EnvoyServerProtoData.ConnectionSourceType; @@ -67,7 +66,7 @@ public class XdsServerTestHelper { Bootstrapper.BootstrapInfo.builder() .servers(Arrays.asList( Bootstrapper.ServerInfo.create( - SERVER_URI, InsecureChannelCredentials.create()))) + SERVER_URI, ImmutableMap.of("type", "insecure")))) .node(BOOTSTRAP_NODE) .serverListenerResourceNameTemplate("grpc/server?udpa.resource.listening_address=%s") .build(); diff --git a/xds/src/test/java/io/grpc/xds/XdsServerWrapperTest.java b/xds/src/test/java/io/grpc/xds/XdsServerWrapperTest.java index ce1c6b94a35..f1a8ebc78d7 100644 --- a/xds/src/test/java/io/grpc/xds/XdsServerWrapperTest.java +++ b/xds/src/test/java/io/grpc/xds/XdsServerWrapperTest.java @@ -39,7 +39,6 @@ import com.google.common.util.concurrent.SettableFuture; import io.envoyproxy.envoy.config.core.v3.SocketAddress.Protocol; import io.grpc.Attributes; -import io.grpc.InsecureChannelCredentials; import io.grpc.Metadata; import io.grpc.MethodDescriptor; import io.grpc.Server; @@ -149,7 +148,7 @@ public void testBootstrap() throws Exception { Bootstrapper.BootstrapInfo b = Bootstrapper.BootstrapInfo.builder() .servers(Arrays.asList( - Bootstrapper.ServerInfo.create("uri", InsecureChannelCredentials.create()))) + Bootstrapper.ServerInfo.create("uri", ImmutableMap.of("type", "insecure")))) .node(EnvoyProtoData.Node.newBuilder().setId("id").build()) .serverListenerResourceNameTemplate("grpc/server?udpa.resource.listening_address=%s") .build(); @@ -180,7 +179,7 @@ public void testBootstrap_noTemplate() throws Exception { Bootstrapper.BootstrapInfo b = Bootstrapper.BootstrapInfo.builder() .servers(Arrays.asList( - Bootstrapper.ServerInfo.create("uri", InsecureChannelCredentials.create()))) + Bootstrapper.ServerInfo.create("uri", ImmutableMap.of("type", "insecure")))) .node(EnvoyProtoData.Node.newBuilder().setId("id").build()) .build(); verifyBootstrapFail(b); @@ -220,7 +219,7 @@ public void testBootstrap_templateWithXdstp() throws Exception { Bootstrapper.BootstrapInfo b = Bootstrapper.BootstrapInfo.builder() .servers(Arrays.asList( Bootstrapper.ServerInfo.create( - "uri", InsecureChannelCredentials.create()))) + "uri", ImmutableMap.of("type", "insecure")))) .node(EnvoyProtoData.Node.newBuilder().setId("id").build()) .serverListenerResourceNameTemplate( "xdstp://xds.authority.com/envoy.config.listener.v3.Listener/grpc/server/%s") diff --git a/xds/src/test/java/io/grpc/xds/client/CommonBootstrapperTestUtils.java b/xds/src/test/java/io/grpc/xds/client/CommonBootstrapperTestUtils.java index 754e903f8a9..8f175060547 100644 --- a/xds/src/test/java/io/grpc/xds/client/CommonBootstrapperTestUtils.java +++ b/xds/src/test/java/io/grpc/xds/client/CommonBootstrapperTestUtils.java @@ -18,8 +18,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import io.grpc.ChannelCredentials; -import io.grpc.InsecureChannelCredentials; import io.grpc.internal.BackoffPolicy; import io.grpc.internal.FakeClock; import io.grpc.internal.JsonParser; @@ -35,7 +33,6 @@ public class CommonBootstrapperTestUtils { public static final String SERVER_URI = "trafficdirector.googleapis.com"; - private static final ChannelCredentials CHANNEL_CREDENTIALS = InsecureChannelCredentials.create(); private static final String SERVER_URI_CUSTOM_AUTHORITY = "trafficdirector2.googleapis.com"; private static final String SERVER_URI_EMPTY_AUTHORITY = "trafficdirector3.googleapis.com"; public static final String LDS_RESOURCE = "listener.googleapis.com"; @@ -203,7 +200,8 @@ public static Bootstrapper.BootstrapInfo buildBootStrap(List serverUris) List serverInfos = new ArrayList<>(); for (String uri : serverUris) { - serverInfos.add(ServerInfo.create(uri, CHANNEL_CREDENTIALS, false, true, false)); + serverInfos.add( + ServerInfo.create(uri, ImmutableMap.of("type", "insecure"), false, true,false)); } EnvoyProtoData.Node node = EnvoyProtoData.Node.newBuilder().setId("node-id").build(); @@ -214,13 +212,17 @@ public static Bootstrapper.BootstrapInfo buildBootStrap(List serverUris) "authority.xds.com", Bootstrapper.AuthorityInfo.create( "xdstp://authority.xds.com/envoy.config.listener.v3.Listener/%s", - ImmutableList.of(Bootstrapper.ServerInfo.create( - SERVER_URI_CUSTOM_AUTHORITY, CHANNEL_CREDENTIALS))), + ImmutableList.of( + Bootstrapper.ServerInfo.create( + SERVER_URI_CUSTOM_AUTHORITY, + ImmutableMap.of("type", "insecure")))), "", Bootstrapper.AuthorityInfo.create( "xdstp:///envoy.config.listener.v3.Listener/%s", - ImmutableList.of(Bootstrapper.ServerInfo.create( - SERVER_URI_EMPTY_AUTHORITY, CHANNEL_CREDENTIALS))))) + ImmutableList.of( + Bootstrapper.ServerInfo.create( + SERVER_URI_EMPTY_AUTHORITY, + ImmutableMap.of("type", "insecure")))))) .certProviders(ImmutableMap.of("cert-instance-name", Bootstrapper.CertificateProviderInfo.create("file-watcher", ImmutableMap.of()))) .build();