Skip to content

Commit

Permalink
xds: fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
dapengzhang0 authored and dfawley committed Jan 15, 2021
1 parent 6e7bfd4 commit c09c3a1
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 36 deletions.
2 changes: 2 additions & 0 deletions xds/src/main/java/io/grpc/xds/EnvoyProtoData.java
Expand Up @@ -418,6 +418,7 @@ static DropOverload fromEnvoyProtoDropOverload(
break;
case MILLION:
break;
case UNRECOGNIZED:
default:
throw new IllegalArgumentException("Unknown denominator type of " + percent);
}
Expand All @@ -444,6 +445,7 @@ static DropOverload fromEnvoyProtoDropOverloadV2(
break;
case MILLION:
break;
case UNRECOGNIZED:
default:
throw new IllegalArgumentException("Unknown denominator type of " + percent);
}
Expand Down
7 changes: 4 additions & 3 deletions xds/src/main/java/io/grpc/xds/EnvoyServerProtoData.java
Expand Up @@ -19,6 +19,8 @@
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;
Expand Down Expand Up @@ -355,10 +357,9 @@ static final class Listener {
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:
Expand Down
7 changes: 4 additions & 3 deletions xds/src/main/java/io/grpc/xds/XdsClientImpl.java
Expand Up @@ -35,12 +35,14 @@
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;
Expand Down Expand Up @@ -468,7 +470,7 @@ private void updateNodeMetadataForListenerRequest(int port) {
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())
Expand Down Expand Up @@ -1191,8 +1193,7 @@ private void handleEdsResponse(DiscoveryResponse edsResponse) {
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;
Expand Down
Expand Up @@ -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;
Expand All @@ -38,7 +39,7 @@ public interface Watcher {

void updateTrustedRoots(List<X509Certificate> trustedRoots);

void onError(io.grpc.Status errorStatus);
void onError(Status errorStatus);
}

/**
Expand Down
Expand Up @@ -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);
}
29 changes: 14 additions & 15 deletions xds/src/test/java/io/grpc/xds/EnvoyProtoDataTest.java
Expand Up @@ -22,8 +22,13 @@
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;
Expand Down Expand Up @@ -210,8 +215,7 @@ public void convertRouteMatch_pathMatching() {
// 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();
Expand Down Expand Up @@ -277,13 +281,11 @@ public void convertRouteMatch_withRuntimeFraction() {
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();
Expand Down Expand Up @@ -318,9 +320,9 @@ public void convertRouteAction() {
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))))
Expand Down Expand Up @@ -356,8 +358,7 @@ public void convertHeaderMatcher() {
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();
Expand All @@ -368,8 +369,7 @@ public void convertHeaderMatcher() {
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();
Expand Down Expand Up @@ -424,8 +424,7 @@ public void convertHeaderMatcher_malformedRegExPattern() {
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();
Expand Down
Expand Up @@ -20,6 +20,8 @@
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;
Expand Down Expand Up @@ -87,18 +89,16 @@ static io.envoyproxy.envoy.api.v2.auth.SdsSecretConfig buildSdsSecretConfigV2(
*/
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())
Expand All @@ -116,9 +116,8 @@ private static ConfigSource buildConfigSource(String targetUri, String channelTy
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()
Expand Down Expand Up @@ -193,13 +192,14 @@ static CommonTlsContext buildCommonTlsContextFromSdsConfigForTlsCertificate(
.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) {
Expand Down

0 comments on commit c09c3a1

Please sign in to comment.