File tree 4 files changed +27
-4
lines changed 4 files changed +27
-4
lines changed Original file line number Diff line number Diff line change 17
17
package io .grpc .xds ;
18
18
19
19
import com .google .common .annotations .VisibleForTesting ;
20
+ import io .grpc .internal .GrpcUtil ;
20
21
import java .util .HashMap ;
21
22
import java .util .Map ;
22
23
import javax .annotation .Nullable ;
@@ -32,12 +33,18 @@ final class FilterRegistry {
32
33
33
34
private FilterRegistry () {}
34
35
36
+ static boolean isEnabledGcpAuthnFilter =
37
+ GrpcUtil .getFlag ("GRPC_EXPERIMENTAL_XDS_GCP_AUTHENTICATION_FILTER" , false );
38
+
35
39
static synchronized FilterRegistry getDefaultRegistry () {
36
40
if (instance == null ) {
37
41
instance = newRegistry ().register (
38
42
new FaultFilter .Provider (),
39
43
new RouterFilter .Provider (),
40
44
new RbacFilter .Provider ());
45
+ if (isEnabledGcpAuthnFilter ) {
46
+ instance .register (new GcpAuthenticationFilter .Provider ());
47
+ }
41
48
}
42
49
return instance ;
43
50
}
Original file line number Diff line number Diff line change 17
17
package io .grpc .xds ;
18
18
19
19
import static com .google .common .base .Preconditions .checkNotNull ;
20
+ import static io .grpc .xds .FilterRegistry .isEnabledGcpAuthnFilter ;
20
21
import static io .grpc .xds .XdsNameResolver .CLUSTER_SELECTION_KEY ;
21
22
import static io .grpc .xds .XdsNameResolver .XDS_CONFIG_CALL_OPTION_KEY ;
22
23
@@ -312,6 +313,10 @@ public String getTypeUrl() {
312
313
public AudienceWrapper parse (Any any ) throws ResourceInvalidException {
313
314
Audience audience ;
314
315
try {
316
+ if (!isEnabledGcpAuthnFilter ) {
317
+ throw new InvalidProtocolBufferException ("Environment variable for GCP Authentication "
318
+ + "Filter is Not Set" );
319
+ }
315
320
audience = any .unpack (Audience .class );
316
321
} catch (InvalidProtocolBufferException ex ) {
317
322
throw new ResourceInvalidException ("Invalid Resource in address proto" , ex );
Original file line number Diff line number Diff line change 73
73
import java .util .Collections ;
74
74
import java .util .HashMap ;
75
75
import java .util .Map ;
76
+ import org .junit .Before ;
76
77
import org .junit .Test ;
77
78
import org .junit .runner .RunWith ;
78
79
import org .junit .runners .JUnit4 ;
@@ -89,6 +90,11 @@ public class GcpAuthenticationFilterTest {
89
90
private static final RdsUpdate rdsUpdate = getRdsUpdate ();
90
91
private static final CdsUpdate cdsUpdate = getCdsUpdate ();
91
92
93
+ @ Before
94
+ public void setUp () {
95
+ System .setProperty ("GRPC_EXPERIMENTAL_XDS_GCP_AUTHENTICATION_FILTER" , "true" );
96
+ }
97
+
92
98
@ Test
93
99
public void testNewFilterInstancesPerFilterName () {
94
100
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) {
2417
2417
2418
2418
@ Test
2419
2419
public void processCluster_parsesAudienceMetadata () throws Exception {
2420
+ FilterRegistry .isEnabledGcpAuthnFilter = true ;
2420
2421
MetadataRegistry .getInstance ();
2421
2422
2422
2423
Audience audience = Audience .newBuilder ()
@@ -2460,10 +2461,14 @@ public void processCluster_parsesAudienceMetadata() throws Exception {
2460
2461
"FILTER_METADATA" , ImmutableMap .of (
2461
2462
"key1" , "value1" ,
2462
2463
"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
+ }
2467
2472
}
2468
2473
2469
2474
@ Test
You can’t perform that action at this time.
0 commit comments