• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

grpc / grpc-java / #19826

23 May 2025 10:25AM UTC coverage: 88.641% (+0.005%) from 88.636%
#19826

push

github

web-flow
xds: Add GcpAuthenticationFilter to FilterRegistry (#12075) (#12097)

34686 of 39131 relevant lines covered (88.64%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.33
/../xds/src/main/java/io/grpc/xds/FilterRegistry.java
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.common.annotations.VisibleForTesting;
20
import io.grpc.internal.GrpcUtil;
21
import java.util.HashMap;
22
import java.util.Map;
23
import javax.annotation.Nullable;
24

25
/**
26
 * A registry for all supported {@link Filter}s. Filters can be queried from the registry
27
 * by any of the {@link Filter.Provider#typeUrls() type URLs}.
28
 */
29
final class FilterRegistry {
30
  private static FilterRegistry instance;
31

32
  private final Map<String, Filter.Provider> supportedFilters = new HashMap<>();
1✔
33

34
  private FilterRegistry() {}
1✔
35

36
  static boolean isEnabledGcpAuthnFilter =
1✔
37
      GrpcUtil.getFlag("GRPC_EXPERIMENTAL_XDS_GCP_AUTHENTICATION_FILTER", false);
1✔
38

39
  static synchronized FilterRegistry getDefaultRegistry() {
40
    if (instance == null) {
1✔
41
      instance = newRegistry().register(
1✔
42
              new FaultFilter.Provider(),
43
              new RouterFilter.Provider(),
44
              new RbacFilter.Provider());
45
      if (isEnabledGcpAuthnFilter) {
1✔
46
        instance.register(new GcpAuthenticationFilter.Provider());
×
47
      }
48
    }
49
    return instance;
1✔
50
  }
51

52
  @VisibleForTesting
53
  static FilterRegistry newRegistry() {
54
    return new FilterRegistry();
1✔
55
  }
56

57
  @VisibleForTesting
58
  FilterRegistry register(Filter.Provider... filters) {
59
    for (Filter.Provider filter : filters) {
1✔
60
      for (String typeUrl : filter.typeUrls()) {
1✔
61
        supportedFilters.put(typeUrl, filter);
1✔
62
      }
63
    }
64
    return this;
1✔
65
  }
66

67
  @Nullable
68
  Filter.Provider get(String typeUrl) {
69
    return supportedFilters.get(typeUrl);
1✔
70
  }
71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc