Skip to content

Commit

Permalink
Throw exception is no server with supported channel creds is found.
Browse files Browse the repository at this point in the history
  • Loading branch information
voidzcy committed Sep 8, 2020
1 parent 311ed9d commit c1f54ce
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions xds/src/main/java/io/grpc/xds/XdsChannelFactory.java
Expand Up @@ -52,17 +52,28 @@ XdsChannel createChannel(List<ServerInfo> servers) throws XdsInitializationExcep
List<ChannelCreds> channelCredsList = serverInfo.getChannelCredentials();
ManagedChannelBuilder<?> channelBuilder = null;
// Use the first supported channel credentials configuration.
// Currently, only "google_default" is supported.
for (ChannelCreds creds : channelCredsList) {
if (creds.getType().equals("google_default")) {
logger.log(XdsLogLevel.INFO, "Using channel credentials: google_default");
channelBuilder = GoogleDefaultChannelBuilder.forTarget(serverUri);
switch (creds.getType()) {
case "google_default":
logger.log(XdsLogLevel.INFO, "Using channel credentials: google_default");
channelBuilder = GoogleDefaultChannelBuilder.forTarget(serverUri);
break;
case "insecure":
logger.log(XdsLogLevel.INFO, "Using channel credentials: insecure");
channelBuilder = ManagedChannelBuilder.forTarget(serverUri).usePlaintext();
break;
case "tls":
logger.log(XdsLogLevel.INFO, "Using channel credentials: tls");
channelBuilder = ManagedChannelBuilder.forTarget(serverUri);
break;
default:
}
if (channelBuilder != null) {
break;
}
}
if (channelBuilder == null) {
logger.log(XdsLogLevel.INFO, "Using default channel credentials");
channelBuilder = ManagedChannelBuilder.forTarget(serverUri);
throw new XdsInitializationException("No server with supported channel creds found");
}

ManagedChannel channel = channelBuilder
Expand Down

0 comments on commit c1f54ce

Please sign in to comment.