xds: fix lint

This commit is contained in:
ZHANG Dapeng 2020-07-08 17:21:16 -07:00 committed by GitHub
parent c756c2db56
commit cd70dcbfae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 40 additions and 36 deletions

View File

@ -418,6 +418,7 @@ final class EnvoyProtoData {
break;
case MILLION:
break;
case UNRECOGNIZED:
default:
throw new IllegalArgumentException("Unknown denominator type of " + percent);
}
@ -444,6 +445,7 @@ final class EnvoyProtoData {
break;
case MILLION:
break;
case UNRECOGNIZED:
default:
throw new IllegalArgumentException("Unknown denominator type of " + percent);
}

View File

@ -19,6 +19,8 @@ package io.grpc.xds;
import com.google.common.annotations.VisibleForTesting;
import com.google.protobuf.Any;
import com.google.protobuf.InvalidProtocolBufferException;
import io.envoyproxy.envoy.config.core.v3.Address;
import io.envoyproxy.envoy.config.core.v3.SocketAddress;
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CommonTlsContext;
import io.grpc.Internal;
import java.util.ArrayList;
@ -355,10 +357,9 @@ public final class EnvoyServerProtoData {
this.filterChains = Collections.unmodifiableList(filterChains);
}
private static String convertEnvoyAddressToString(
io.envoyproxy.envoy.config.core.v3.Address proto) {
private static String convertEnvoyAddressToString(Address proto) {
if (proto.hasSocketAddress()) {
io.envoyproxy.envoy.config.core.v3.SocketAddress socketAddress = proto.getSocketAddress();
SocketAddress socketAddress = proto.getSocketAddress();
String address = socketAddress.getAddress();
switch (socketAddress.getPortSpecifierCase()) {
case NAMED_PORT:

View File

@ -35,12 +35,14 @@ import com.google.rpc.Code;
import io.envoyproxy.envoy.api.v2.DiscoveryRequest;
import io.envoyproxy.envoy.api.v2.DiscoveryResponse;
import io.envoyproxy.envoy.api.v2.core.Node;
import io.envoyproxy.envoy.api.v2.core.SocketAddress;
import io.envoyproxy.envoy.config.cluster.v3.Cluster;
import io.envoyproxy.envoy.config.cluster.v3.Cluster.DiscoveryType;
import io.envoyproxy.envoy.config.cluster.v3.Cluster.EdsClusterConfig;
import io.envoyproxy.envoy.config.cluster.v3.Cluster.LbPolicy;
import io.envoyproxy.envoy.config.core.v3.Address;
import io.envoyproxy.envoy.config.endpoint.v3.ClusterLoadAssignment;
import io.envoyproxy.envoy.config.endpoint.v3.LbEndpoint;
import io.envoyproxy.envoy.config.listener.v3.FilterChain;
import io.envoyproxy.envoy.config.listener.v3.FilterChainMatch;
import io.envoyproxy.envoy.config.listener.v3.Listener;
@ -468,7 +470,7 @@ final class XdsClientImpl extends XdsClient {
io.envoyproxy.envoy.api.v2.core.Address listeningAddress =
io.envoyproxy.envoy.api.v2.core.Address.newBuilder()
.setSocketAddress(
io.envoyproxy.envoy.api.v2.core.SocketAddress.newBuilder()
SocketAddress.newBuilder()
.setAddress("0.0.0.0")
.setPortValue(port)
.build())
@ -1191,8 +1193,7 @@ final class XdsClientImpl extends XdsClient {
priorities.add(localityPriority);
// The endpoint field of each lb_endpoints must be set.
// Inside of it: the address field must be set.
for (io.envoyproxy.envoy.config.endpoint.v3.LbEndpoint lbEndpoint
: localityLbEndpoints.getLbEndpointsList()) {
for (LbEndpoint lbEndpoint : localityLbEndpoints.getLbEndpointsList()) {
if (!lbEndpoint.getEndpoint().hasAddress()) {
errorMessage = "ClusterLoadAssignment " + clusterName + " : endpoint with no address.";
break;

View File

@ -16,6 +16,7 @@
package io.grpc.xds.internal.certprovider;
import io.grpc.Status;
import java.io.Closeable;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;
@ -38,7 +39,7 @@ public abstract class CertificateProvider implements Closeable {
void updateTrustedRoots(List<X509Certificate> trustedRoots);
void onError(io.grpc.Status errorStatus);
void onError(Status errorStatus);
}
/**

View File

@ -35,5 +35,5 @@ interface CertificateProviderProvider {
* @param notifyCertUpdates See {@link CertificateProvider#CertificateProvider(Watcher, boolean)}
*/
CertificateProvider createCertificateProvider(
Object config, Watcher watcher, boolean notifyCertUpdates) throws IllegalArgumentException;
Object config, Watcher watcher, boolean notifyCertUpdates);
}

View File

@ -22,8 +22,13 @@ import com.google.common.testing.EqualsTester;
import com.google.protobuf.BoolValue;
import com.google.protobuf.UInt32Value;
import com.google.re2j.Pattern;
import io.envoyproxy.envoy.config.core.v3.RuntimeFractionalPercent;
import io.envoyproxy.envoy.config.route.v3.QueryParameterMatcher;
import io.envoyproxy.envoy.config.route.v3.RedirectAction;
import io.envoyproxy.envoy.config.route.v3.WeightedCluster;
import io.envoyproxy.envoy.type.matcher.v3.RegexMatcher;
import io.envoyproxy.envoy.type.v3.FractionalPercent;
import io.envoyproxy.envoy.type.v3.Int64Range;
import io.grpc.xds.EnvoyProtoData.ClusterWeight;
import io.grpc.xds.EnvoyProtoData.Locality;
import io.grpc.xds.EnvoyProtoData.Route;
@ -210,8 +215,7 @@ public class EnvoyProtoDataTest {
// path_specifier = safe_regex
io.envoyproxy.envoy.config.route.v3.RouteMatch proto4 =
io.envoyproxy.envoy.config.route.v3.RouteMatch.newBuilder()
.setSafeRegex(
io.envoyproxy.envoy.type.matcher.v3.RegexMatcher.newBuilder().setRegex("."))
.setSafeRegex(RegexMatcher.newBuilder().setRegex("."))
.build();
StructOrError<RouteMatch> struct4 = Route.convertEnvoyProtoRouteMatch(proto4);
assertThat(struct4.getErrorDetail()).isNull();
@ -277,13 +281,11 @@ public class EnvoyProtoDataTest {
io.envoyproxy.envoy.config.route.v3.RouteMatch.newBuilder()
.setPrefix("")
.setRuntimeFraction(
io.envoyproxy.envoy.config.core.v3.RuntimeFractionalPercent.newBuilder()
RuntimeFractionalPercent.newBuilder()
.setDefaultValue(
io.envoyproxy.envoy.type.v3.FractionalPercent.newBuilder()
FractionalPercent.newBuilder()
.setNumerator(30)
.setDenominator(
io.envoyproxy.envoy.type.v3.FractionalPercent.DenominatorType
.HUNDRED)))
.setDenominator(FractionalPercent.DenominatorType.HUNDRED)))
.build();
StructOrError<RouteMatch> struct = Route.convertEnvoyProtoRouteMatch(proto);
assertThat(struct.getErrorDetail()).isNull();
@ -318,9 +320,9 @@ public class EnvoyProtoDataTest {
io.envoyproxy.envoy.config.route.v3.RouteAction proto3 =
io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder()
.setWeightedClusters(
io.envoyproxy.envoy.config.route.v3.WeightedCluster.newBuilder()
WeightedCluster.newBuilder()
.addClusters(
io.envoyproxy.envoy.config.route.v3.WeightedCluster.ClusterWeight
WeightedCluster.ClusterWeight
.newBuilder()
.setName("cluster-baz")
.setWeight(UInt32Value.newBuilder().setValue(100))))
@ -356,8 +358,7 @@ public class EnvoyProtoDataTest {
io.envoyproxy.envoy.config.route.v3.HeaderMatcher proto3 =
io.envoyproxy.envoy.config.route.v3.HeaderMatcher.newBuilder()
.setName(":method")
.setSafeRegexMatch(
io.envoyproxy.envoy.type.matcher.v3.RegexMatcher.newBuilder().setRegex("P*"))
.setSafeRegexMatch(RegexMatcher.newBuilder().setRegex("P*"))
.build();
StructOrError<HeaderMatcher> struct3 = Route.convertEnvoyProtoHeaderMatcher(proto3);
assertThat(struct3.getErrorDetail()).isNull();
@ -368,8 +369,7 @@ public class EnvoyProtoDataTest {
io.envoyproxy.envoy.config.route.v3.HeaderMatcher proto4 =
io.envoyproxy.envoy.config.route.v3.HeaderMatcher.newBuilder()
.setName("timeout")
.setRangeMatch(
io.envoyproxy.envoy.type.v3.Int64Range.newBuilder().setStart(10L).setEnd(20L))
.setRangeMatch(Int64Range.newBuilder().setStart(10L).setEnd(20L))
.build();
StructOrError<HeaderMatcher> struct4 = Route.convertEnvoyProtoHeaderMatcher(proto4);
assertThat(struct4.getErrorDetail()).isNull();
@ -424,8 +424,7 @@ public class EnvoyProtoDataTest {
io.envoyproxy.envoy.config.route.v3.HeaderMatcher proto =
io.envoyproxy.envoy.config.route.v3.HeaderMatcher.newBuilder()
.setName(":method")
.setSafeRegexMatch(
io.envoyproxy.envoy.type.matcher.v3.RegexMatcher.newBuilder().setRegex("["))
.setSafeRegexMatch(RegexMatcher.newBuilder().setRegex("["))
.build();
StructOrError<HeaderMatcher> struct = Route.convertEnvoyProtoHeaderMatcher(proto);
assertThat(struct.getErrorDetail()).isNotNull();

View File

@ -20,6 +20,8 @@ import com.google.common.base.Strings;
import com.google.protobuf.BoolValue;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import io.envoyproxy.envoy.api.v2.core.ApiConfigSource.ApiType;
import io.envoyproxy.envoy.api.v2.core.GrpcService.GoogleGrpc;
import io.envoyproxy.envoy.config.core.v3.ApiConfigSource;
import io.envoyproxy.envoy.config.core.v3.ConfigSource;
import io.envoyproxy.envoy.config.core.v3.DataSource;
@ -87,18 +89,16 @@ public class CommonTlsContextTestsUtil {
*/
private static io.envoyproxy.envoy.api.v2.core.ConfigSource buildConfigSourceV2(
String targetUri, String channelType) {
io.envoyproxy.envoy.api.v2.core.GrpcService.GoogleGrpc.Builder googleGrpcBuilder =
io.envoyproxy.envoy.api.v2.core.GrpcService.GoogleGrpc.newBuilder().setTargetUri(targetUri);
GoogleGrpc.Builder googleGrpcBuilder = GoogleGrpc.newBuilder().setTargetUri(targetUri);
if (channelType != null) {
Struct.Builder structBuilder = Struct.newBuilder();
structBuilder.putFields(
"channelType", Value.newBuilder().setStringValue(channelType).build());
Struct.Builder structBuilder = Struct.newBuilder()
.putFields("channelType", Value.newBuilder().setStringValue(channelType).build());
googleGrpcBuilder.setConfig(structBuilder.build());
}
return io.envoyproxy.envoy.api.v2.core.ConfigSource.newBuilder()
.setApiConfigSource(
io.envoyproxy.envoy.api.v2.core.ApiConfigSource.newBuilder()
.setApiType(io.envoyproxy.envoy.api.v2.core.ApiConfigSource.ApiType.GRPC)
.setApiType(ApiType.GRPC)
.addGrpcServices(
io.envoyproxy.envoy.api.v2.core.GrpcService.newBuilder()
.setGoogleGrpc(googleGrpcBuilder.build())
@ -116,9 +116,8 @@ public class CommonTlsContextTestsUtil {
GrpcService.GoogleGrpc.Builder googleGrpcBuilder =
GrpcService.GoogleGrpc.newBuilder().setTargetUri(targetUri);
if (channelType != null) {
Struct.Builder structBuilder = Struct.newBuilder();
structBuilder.putFields(
"channelType", Value.newBuilder().setStringValue(channelType).build());
Struct.Builder structBuilder = Struct.newBuilder()
.putFields("channelType", Value.newBuilder().setStringValue(channelType).build());
googleGrpcBuilder.setConfig(structBuilder.build());
}
return ConfigSource.newBuilder()
@ -193,13 +192,14 @@ public class CommonTlsContextTestsUtil {
.addAllVerifySubjectAltName(verifySubjectAltNames).build();
if (sdsSecretConfig != null && certValidationContext != null) {
io.envoyproxy.envoy.api.v2.auth.CommonTlsContext.CombinedCertificateValidationContext.Builder
combinedBuilder =
io.envoyproxy.envoy.api.v2.auth.CommonTlsContext.CombinedCertificateValidationContext
combined =
io.envoyproxy.envoy.api.v2.auth.CommonTlsContext.CombinedCertificateValidationContext
.newBuilder()
.setDefaultValidationContext(certValidationContext)
.setValidationContextSdsSecretConfig(sdsSecretConfig);
builder.setCombinedValidationContext(combinedBuilder);
.setValidationContextSdsSecretConfig(sdsSecretConfig)
.build();
builder.setCombinedValidationContext(combined);
} else if (sdsSecretConfig != null) {
builder.setValidationContextSdsSecretConfig(sdsSecretConfig);
} else if (certValidationContext != null) {