xds: security code refactoring: delete unused code and rename misc things (#9583)

This commit is contained in:
sanjaypujare 2022-10-04 12:41:17 -07:00 committed by GitHub
parent b118e00cf9
commit 6b80efcfa8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 13 additions and 150 deletions

View File

@ -208,10 +208,10 @@ public final class SecurityProtocolNegotiators {
new SslContextProvider.Callback(ctx.executor()) {
@Override
public void updateSecret(SslContext sslContext) {
public void updateSslContext(SslContext sslContext) {
logger.log(
Level.FINEST,
"ClientSdsHandler.updateSecret authority={0}, ctx.name={1}",
"ClientSdsHandler.updateSslContext authority={0}, ctx.name={1}",
new Object[]{grpcHandler.getAuthority(), ctx.name()});
ChannelHandler handler =
InternalProtocolNegotiators.tls(sslContext).newHandler(grpcHandler);
@ -347,7 +347,7 @@ public final class SecurityProtocolNegotiators {
new SslContextProvider.Callback(ctx.executor()) {
@Override
public void updateSecret(SslContext sslContext) {
public void updateSslContext(SslContext sslContext) {
ChannelHandler handler =
InternalProtocolNegotiators.serverTls(sslContext).newHandler(grpcHandler);

View File

@ -57,7 +57,7 @@ public abstract class SslContextProvider implements Closeable {
}
/** Informs callee of new/updated SslContext. */
@VisibleForTesting public abstract void updateSecret(SslContext sslContext);
@VisibleForTesting public abstract void updateSslContext(SslContext sslContext);
/** Informs callee of an exception that was generated. */
@VisibleForTesting protected abstract void onException(Throwable throwable);
@ -120,7 +120,7 @@ public abstract class SslContextProvider implements Closeable {
public void run() {
try {
SslContext sslContext = sslContextGetter.get();
callback.updateSecret(sslContext);
callback.updateSslContext(sslContext);
} catch (Throwable e) {
callback.onException(e);
}

View File

@ -66,8 +66,8 @@ public final class SslContextProviderSupplier implements Closeable {
new SslContextProvider.Callback(callback.getExecutor()) {
@Override
public void updateSecret(SslContext sslContext) {
callback.updateSecret(sslContext);
public void updateSslContext(SslContext sslContext) {
callback.updateSslContext(sslContext);
releaseSslContextProvider(toRelease);
}

View File

@ -1,137 +0,0 @@
/*
* Copyright 2019 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.xds;
import com.google.protobuf.Any;
import io.envoyproxy.envoy.config.core.v3.Address;
import io.envoyproxy.envoy.config.listener.v3.ApiListener;
import io.envoyproxy.envoy.config.listener.v3.FilterChain;
import io.envoyproxy.envoy.config.listener.v3.Listener;
import io.envoyproxy.envoy.config.route.v3.Route;
import io.envoyproxy.envoy.config.route.v3.RouteAction;
import io.envoyproxy.envoy.config.route.v3.RouteConfiguration;
import io.envoyproxy.envoy.config.route.v3.RouteMatch;
import io.envoyproxy.envoy.config.route.v3.VirtualHost;
import io.envoyproxy.envoy.service.discovery.v3.DiscoveryRequest;
import io.envoyproxy.envoy.service.discovery.v3.DiscoveryResponse;
import io.grpc.xds.EnvoyProtoData.Node;
import java.util.List;
/**
* Helper methods for building protobuf messages with custom data for xDS protocols.
*/
// TODO(chengyuanzhang, sanjaypujare): delete this class, should not dump everything here.
class XdsClientTestHelper {
static DiscoveryResponse buildDiscoveryResponse(String versionInfo,
List<Any> resources, String typeUrl, String nonce) {
return
DiscoveryResponse.newBuilder()
.setVersionInfo(versionInfo)
.setTypeUrl(typeUrl)
.addAllResources(resources)
.setNonce(nonce)
.build();
}
static io.envoyproxy.envoy.api.v2.DiscoveryResponse buildDiscoveryResponseV2(String versionInfo,
List<Any> resources, String typeUrl, String nonce) {
return
io.envoyproxy.envoy.api.v2.DiscoveryResponse.newBuilder()
.setVersionInfo(versionInfo)
.setTypeUrl(typeUrl)
.addAllResources(resources)
.setNonce(nonce)
.build();
}
static DiscoveryRequest buildDiscoveryRequest(Node node, String versionInfo,
List<String> resourceNames, String typeUrl, String nonce) {
return
DiscoveryRequest.newBuilder()
.setVersionInfo(versionInfo)
.setNode(node.toEnvoyProtoNode())
.setTypeUrl(typeUrl)
.addAllResourceNames(resourceNames)
.setResponseNonce(nonce)
.build();
}
static Listener buildListener(String name, com.google.protobuf.Any apiListener) {
return
Listener.newBuilder()
.setName(name)
.setAddress(Address.getDefaultInstance())
.addFilterChains(FilterChain.getDefaultInstance())
.setApiListener(ApiListener.newBuilder().setApiListener(apiListener))
.build();
}
static io.envoyproxy.envoy.api.v2.Listener buildListenerV2(
String name, com.google.protobuf.Any apiListener) {
return
io.envoyproxy.envoy.api.v2.Listener.newBuilder()
.setName(name)
.setAddress(io.envoyproxy.envoy.api.v2.core.Address.getDefaultInstance())
.addFilterChains(io.envoyproxy.envoy.api.v2.listener.FilterChain.getDefaultInstance())
.setApiListener(io.envoyproxy.envoy.config.listener.v2.ApiListener.newBuilder()
.setApiListener(apiListener))
.build();
}
static RouteConfiguration buildRouteConfiguration(String name,
List<VirtualHost> virtualHosts) {
return
RouteConfiguration.newBuilder()
.setName(name)
.addAllVirtualHosts(virtualHosts)
.build();
}
static io.envoyproxy.envoy.api.v2.RouteConfiguration buildRouteConfigurationV2(String name,
List<io.envoyproxy.envoy.api.v2.route.VirtualHost> virtualHosts) {
return
io.envoyproxy.envoy.api.v2.RouteConfiguration.newBuilder()
.setName(name)
.addAllVirtualHosts(virtualHosts)
.build();
}
static VirtualHost buildVirtualHost(List<String> domains, String clusterName) {
return VirtualHost.newBuilder()
.setName("virtualhost00.googleapis.com") // don't care
.addAllDomains(domains)
.addRoutes(
Route.newBuilder()
.setRoute(RouteAction.newBuilder().setCluster(clusterName))
.setMatch(RouteMatch.newBuilder().setPrefix("")))
.build();
}
static io.envoyproxy.envoy.api.v2.route.VirtualHost buildVirtualHostV2(
List<String> domains, String clusterName) {
return io.envoyproxy.envoy.api.v2.route.VirtualHost.newBuilder()
.setName("virtualhost00.googleapis.com") // don't care
.addAllDomains(domains)
.addRoutes(
io.envoyproxy.envoy.api.v2.route.Route.newBuilder()
.setRoute(
io.envoyproxy.envoy.api.v2.route.RouteAction.newBuilder()
.setCluster(clusterName))
.setMatch(io.envoyproxy.envoy.api.v2.route.RouteMatch.newBuilder().setPrefix("")))
.build();
}
}

View File

@ -424,7 +424,7 @@ public class CommonTlsContextTestsUtil {
}
@Override
public void updateSecret(SslContext sslContext) {
public void updateSslContext(SslContext sslContext) {
updatedSslContext = sslContext;
}

View File

@ -168,7 +168,7 @@ public class SecurityProtocolNegotiatorsTest {
sslContextProviderSupplier
.updateSslContext(new SslContextProvider.Callback(MoreExecutors.directExecutor()) {
@Override
public void updateSecret(SslContext sslContext) {
public void updateSslContext(SslContext sslContext) {
future.set(sslContext);
}
@ -245,7 +245,7 @@ public class SecurityProtocolNegotiatorsTest {
sslContextProviderSupplier
.updateSslContext(new SslContextProvider.Callback(MoreExecutors.directExecutor()) {
@Override
public void updateSecret(SslContext sslContext) {
public void updateSslContext(SslContext sslContext) {
future.set(sslContext);
}
@ -381,7 +381,7 @@ public class SecurityProtocolNegotiatorsTest {
sslContextProviderSupplier
.updateSslContext(new SslContextProvider.Callback(MoreExecutors.directExecutor()) {
@Override
public void updateSecret(SslContext sslContext) {
public void updateSslContext(SslContext sslContext) {
future.set(sslContext);
}

View File

@ -85,8 +85,8 @@ public class SslContextProviderSupplierTest {
SslContextProvider.Callback capturedCallback = callbackCaptor.getValue();
assertThat(capturedCallback).isNotNull();
SslContext mockSslContext = mock(SslContext.class);
capturedCallback.updateSecret(mockSslContext);
verify(mockCallback, times(1)).updateSecret(eq(mockSslContext));
capturedCallback.updateSslContext(mockSslContext);
verify(mockCallback, times(1)).updateSslContext(eq(mockSslContext));
verify(mockTlsContextManager, times(1))
.releaseClientSslContextProvider(eq(mockSslContextProvider));
SslContextProvider.Callback mockCallback = mock(SslContextProvider.Callback.class);