File tree Expand file tree Collapse file tree 4 files changed +27
-4
lines changed
Expand file tree Collapse file tree 4 files changed +27
-4
lines changed 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 @@ -2417,6 +2417,7 @@ public Object parse(Any value) {
24172417
24182418 @ Test
24192419 public void processCluster_parsesAudienceMetadata () throws Exception {
2420+ FilterRegistry .isEnabledGcpAuthnFilter = true ;
24202421 MetadataRegistry .getInstance ();
24212422
24222423 Audience audience = Audience .newBuilder ()
@@ -2460,10 +2461,14 @@ public void processCluster_parsesAudienceMetadata() throws Exception {
24602461 "FILTER_METADATA" , ImmutableMap .of (
24612462 "key1" , "value1" ,
24622463 "key2" , 42.0 ));
2463- assertThat (update .parsedMetadata ().get ("FILTER_METADATA" ))
2464- .isEqualTo (expectedParsedMetadata .get ("FILTER_METADATA" ));
2465- assertThat (update .parsedMetadata ().get ("AUDIENCE_METADATA" ))
2466- .isInstanceOf (AudienceWrapper .class );
2464+ try {
2465+ assertThat (update .parsedMetadata ().get ("FILTER_METADATA" ))
2466+ .isEqualTo (expectedParsedMetadata .get ("FILTER_METADATA" ));
2467+ assertThat (update .parsedMetadata ().get ("AUDIENCE_METADATA" ))
2468+ .isInstanceOf (AudienceWrapper .class );
2469+ } finally {
2470+ FilterRegistry .isEnabledGcpAuthnFilter = false ;
2471+ }
24672472 }
24682473
24692474 @ Test
You can’t perform that action at this time.
0 commit comments