1 /* 2 * Copyright 2021 The gRPC Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package io.grpc.xds; 18 19 import com.google.protobuf.Message; 20 import io.grpc.ClientInterceptor; 21 import io.grpc.LoadBalancer.PickSubchannelArgs; 22 import io.grpc.ServerInterceptor; 23 import io.grpc.xds.Filter.ClientInterceptorBuilder; 24 import io.grpc.xds.Filter.ServerInterceptorBuilder; 25 import java.util.concurrent.ScheduledExecutorService; 26 import javax.annotation.Nullable; 27 28 /** 29 * Router filter implementation. Currently this filter does not parse any field in the config. 30 */ 31 enum RouterFilter implements Filter, ClientInterceptorBuilder, ServerInterceptorBuilder { 32 INSTANCE; 33 34 static final String TYPE_URL = 35 "type.googleapis.com/envoy.extensions.filters.http.router.v3.Router"; 36 37 static final FilterConfig ROUTER_CONFIG = new FilterConfig() { 38 @Override 39 public String typeUrl() { 40 return RouterFilter.TYPE_URL; 41 } 42 43 @Override 44 public String toString() { 45 return "ROUTER_CONFIG"; 46 } 47 }; 48 49 @Override typeUrls()50 public String[] typeUrls() { 51 return new String[] { TYPE_URL }; 52 } 53 54 @Override parseFilterConfig(Message rawProtoMessage)55 public ConfigOrError<? extends FilterConfig> parseFilterConfig(Message rawProtoMessage) { 56 return ConfigOrError.fromConfig(ROUTER_CONFIG); 57 } 58 59 @Override parseFilterConfigOverride(Message rawProtoMessage)60 public ConfigOrError<? extends FilterConfig> parseFilterConfigOverride(Message rawProtoMessage) { 61 return ConfigOrError.fromError("Router Filter should not have override config"); 62 } 63 64 @Nullable 65 @Override buildClientInterceptor( FilterConfig config, @Nullable FilterConfig overrideConfig, PickSubchannelArgs args, ScheduledExecutorService scheduler)66 public ClientInterceptor buildClientInterceptor( 67 FilterConfig config, @Nullable FilterConfig overrideConfig, PickSubchannelArgs args, 68 ScheduledExecutorService scheduler) { 69 return null; 70 } 71 72 @Nullable 73 @Override buildServerInterceptor( FilterConfig config, @Nullable Filter.FilterConfig overrideConfig)74 public ServerInterceptor buildServerInterceptor( 75 FilterConfig config, @Nullable Filter.FilterConfig overrideConfig) { 76 return null; 77 } 78 } 79