Search in sources :

Example 1 with FilterChainMatch

use of io.grpc.xds.EnvoyServerProtoData.FilterChainMatch in project grpc-java by grpc.

the class ClientXdsClient method parseServerSideListener.

@VisibleForTesting
static EnvoyServerProtoData.Listener parseServerSideListener(Listener proto, Set<String> rdsResources, TlsContextManager tlsContextManager, FilterRegistry filterRegistry, Set<String> certProviderInstances, boolean parseHttpFilter) throws ResourceInvalidException {
    if (!proto.getTrafficDirection().equals(TrafficDirection.INBOUND)) {
        throw new ResourceInvalidException("Listener " + proto.getName() + " with invalid traffic direction: " + proto.getTrafficDirection());
    }
    if (!proto.getListenerFiltersList().isEmpty()) {
        throw new ResourceInvalidException("Listener " + proto.getName() + " cannot have listener_filters");
    }
    if (proto.hasUseOriginalDst()) {
        throw new ResourceInvalidException("Listener " + proto.getName() + " cannot have use_original_dst set to true");
    }
    String address = null;
    if (proto.getAddress().hasSocketAddress()) {
        SocketAddress socketAddress = proto.getAddress().getSocketAddress();
        address = socketAddress.getAddress();
        switch(socketAddress.getPortSpecifierCase()) {
            case NAMED_PORT:
                address = address + ":" + socketAddress.getNamedPort();
                break;
            case PORT_VALUE:
                address = address + ":" + socketAddress.getPortValue();
                break;
            default:
        }
    }
    ImmutableList.Builder<FilterChain> filterChains = ImmutableList.builder();
    Set<FilterChainMatch> uniqueSet = new HashSet<>();
    for (io.envoyproxy.envoy.config.listener.v3.FilterChain fc : proto.getFilterChainsList()) {
        filterChains.add(parseFilterChain(fc, rdsResources, tlsContextManager, filterRegistry, uniqueSet, certProviderInstances, parseHttpFilter));
    }
    FilterChain defaultFilterChain = null;
    if (proto.hasDefaultFilterChain()) {
        defaultFilterChain = parseFilterChain(proto.getDefaultFilterChain(), rdsResources, tlsContextManager, filterRegistry, null, certProviderInstances, parseHttpFilter);
    }
    return EnvoyServerProtoData.Listener.create(proto.getName(), address, filterChains.build(), defaultFilterChain);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) FilterChain(io.grpc.xds.EnvoyServerProtoData.FilterChain) FilterChainMatch(io.grpc.xds.EnvoyServerProtoData.FilterChainMatch) SocketAddress(io.envoyproxy.envoy.config.core.v3.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) HashSet(java.util.HashSet) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with FilterChainMatch

use of io.grpc.xds.EnvoyServerProtoData.FilterChainMatch in project grpc-java by grpc.

the class ClientXdsClient method parseFilterChain.

@VisibleForTesting
static FilterChain parseFilterChain(io.envoyproxy.envoy.config.listener.v3.FilterChain proto, Set<String> rdsResources, TlsContextManager tlsContextManager, FilterRegistry filterRegistry, Set<FilterChainMatch> uniqueSet, Set<String> certProviderInstances, boolean parseHttpFilters) throws ResourceInvalidException {
    if (proto.getFiltersCount() != 1) {
        throw new ResourceInvalidException("FilterChain " + proto.getName() + " should contain exact one HttpConnectionManager filter");
    }
    io.envoyproxy.envoy.config.listener.v3.Filter filter = proto.getFiltersList().get(0);
    if (!filter.hasTypedConfig()) {
        throw new ResourceInvalidException("FilterChain " + proto.getName() + " contains filter " + filter.getName() + " without typed_config");
    }
    Any any = filter.getTypedConfig();
    // HttpConnectionManager is the only supported network filter at the moment.
    if (!any.getTypeUrl().equals(TYPE_URL_HTTP_CONNECTION_MANAGER)) {
        throw new ResourceInvalidException("FilterChain " + proto.getName() + " contains filter " + filter.getName() + " with unsupported typed_config type " + any.getTypeUrl());
    }
    HttpConnectionManager hcmProto;
    try {
        hcmProto = any.unpack(HttpConnectionManager.class);
    } catch (InvalidProtocolBufferException e) {
        throw new ResourceInvalidException("FilterChain " + proto.getName() + " with filter " + filter.getName() + " failed to unpack message", e);
    }
    io.grpc.xds.HttpConnectionManager httpConnectionManager = parseHttpConnectionManager(hcmProto, rdsResources, filterRegistry, parseHttpFilters, false);
    EnvoyServerProtoData.DownstreamTlsContext downstreamTlsContext = null;
    if (proto.hasTransportSocket()) {
        if (!TRANSPORT_SOCKET_NAME_TLS.equals(proto.getTransportSocket().getName())) {
            throw new ResourceInvalidException("transport-socket with name " + proto.getTransportSocket().getName() + " not supported.");
        }
        DownstreamTlsContext downstreamTlsContextProto;
        try {
            downstreamTlsContextProto = proto.getTransportSocket().getTypedConfig().unpack(DownstreamTlsContext.class);
        } catch (InvalidProtocolBufferException e) {
            throw new ResourceInvalidException("FilterChain " + proto.getName() + " failed to unpack message", e);
        }
        downstreamTlsContext = EnvoyServerProtoData.DownstreamTlsContext.fromEnvoyProtoDownstreamTlsContext(validateDownstreamTlsContext(downstreamTlsContextProto, certProviderInstances));
    }
    FilterChainMatch filterChainMatch = parseFilterChainMatch(proto.getFilterChainMatch());
    checkForUniqueness(uniqueSet, filterChainMatch);
    return FilterChain.create(proto.getName(), filterChainMatch, httpConnectionManager, downstreamTlsContext, tlsContextManager);
}
Also used : DownstreamTlsContext(io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Any(com.google.protobuf.Any) FilterChainMatch(io.grpc.xds.EnvoyServerProtoData.FilterChainMatch) HttpConnectionManager(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 FilterChainMatch (io.grpc.xds.EnvoyServerProtoData.FilterChainMatch)2 ImmutableList (com.google.common.collect.ImmutableList)1 Any (com.google.protobuf.Any)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 SocketAddress (io.envoyproxy.envoy.config.core.v3.SocketAddress)1 HttpConnectionManager (io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager)1 DownstreamTlsContext (io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext)1 FilterChain (io.grpc.xds.EnvoyServerProtoData.FilterChain)1 InetSocketAddress (java.net.InetSocketAddress)1 HashSet (java.util.HashSet)1