File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717package io .grpc .xds ;
1818
1919import com .google .common .annotations .VisibleForTesting ;
20+ import io .grpc .internal .GrpcUtil ;
2021import java .util .HashMap ;
2122import java .util .Map ;
2223import javax .annotation .Nullable ;
@@ -32,12 +33,18 @@ final class FilterRegistry {
3233
3334 private FilterRegistry () {}
3435
36+ static boolean isEnabledGcpAuthnFilter =
37+ GrpcUtil .getFlag ("GRPC_EXPERIMENTAL_XDS_GCP_AUTHENTICATION_FILTER" , false );
38+
3539 static synchronized FilterRegistry getDefaultRegistry () {
3640 if (instance == null ) {
3741 instance = newRegistry ().register (
3842 new FaultFilter .Provider (),
3943 new RouterFilter .Provider (),
4044 new RbacFilter .Provider ());
45+ if (isEnabledGcpAuthnFilter ) {
46+ instance .register (new GcpAuthenticationFilter .Provider ());
47+ }
4148 }
4249 return instance ;
4350 }
Original file line number Diff line number Diff line change 1717package io .grpc .xds ;
1818
1919import static com .google .common .base .Preconditions .checkNotNull ;
20+ import static io .grpc .xds .FilterRegistry .isEnabledGcpAuthnFilter ;
2021import static io .grpc .xds .XdsNameResolver .CLUSTER_SELECTION_KEY ;
2122import static io .grpc .xds .XdsNameResolver .XDS_CONFIG_CALL_OPTION_KEY ;
2223
@@ -312,6 +313,10 @@ public String getTypeUrl() {
312313 public AudienceWrapper parse (Any any ) throws ResourceInvalidException {
313314 Audience audience ;
314315 try {
316+ if (!isEnabledGcpAuthnFilter ) {
317+ throw new InvalidProtocolBufferException ("Environment variable for GCP Authentication "
318+ + "Filter is Not Set" );
319+ }
315320 audience = any .unpack (Audience .class );
316321 } catch (InvalidProtocolBufferException ex ) {
317322 throw new ResourceInvalidException ("Invalid Resource in address proto" , ex );
Original file line number Diff line number Diff line change 7373import java .util .Collections ;
7474import java .util .HashMap ;
7575import java .util .Map ;
76+ import org .junit .Before ;
7677import org .junit .Test ;
7778import org .junit .runner .RunWith ;
7879import org .junit .runners .JUnit4 ;
@@ -89,6 +90,11 @@ public class GcpAuthenticationFilterTest {
8990 private static final RdsUpdate rdsUpdate = getRdsUpdate ();
9091 private static final CdsUpdate cdsUpdate = getCdsUpdate ();
9192
93+ @ Before
94+ public void setUp () {
95+ System .setProperty ("GRPC_EXPERIMENTAL_XDS_GCP_AUTHENTICATION_FILTER" , "true" );
96+ }
97+
9298 @ Test
9399 public void testNewFilterInstancesPerFilterName () {
94100 assertThat (new GcpAuthenticationFilter ("FILTER_INSTANCE_NAME1" , 10 ))
Original file line number Diff line number Diff line change @@ -2419,6 +2419,7 @@ public Object parse(Any value) {
24192419
24202420 @ Test
24212421 public void processCluster_parsesAudienceMetadata () throws Exception {
2422+ FilterRegistry .isEnabledGcpAuthnFilter = true ;
24222423 MetadataRegistry .getInstance ();
24232424
24242425 Audience audience = Audience .newBuilder ()
@@ -2462,10 +2463,14 @@ public void processCluster_parsesAudienceMetadata() throws Exception {
24622463 "FILTER_METADATA" , ImmutableMap .of (
24632464 "key1" , "value1" ,
24642465 "key2" , 42.0 ));
2465- assertThat (update .parsedMetadata ().get ("FILTER_METADATA" ))
2466- .isEqualTo (expectedParsedMetadata .get ("FILTER_METADATA" ));
2467- assertThat (update .parsedMetadata ().get ("AUDIENCE_METADATA" ))
2468- .isInstanceOf (AudienceWrapper .class );
2466+ try {
2467+ assertThat (update .parsedMetadata ().get ("FILTER_METADATA" ))
2468+ .isEqualTo (expectedParsedMetadata .get ("FILTER_METADATA" ));
2469+ assertThat (update .parsedMetadata ().get ("AUDIENCE_METADATA" ))
2470+ .isInstanceOf (AudienceWrapper .class );
2471+ } finally {
2472+ FilterRegistry .isEnabledGcpAuthnFilter = false ;
2473+ }
24692474 }
24702475
24712476 @ Test
You can’t perform that action at this time.
0 commit comments