Skip to content

Commit 3ba5c76

Browse files
committed
Fixup 12492: Eliminate cyclic dependencies
- Move the parser objects up to `io.grpc.xds` - Move some common objects to `io.grpc.xds.client`
1 parent c65464a commit 3ba5c76

13 files changed

+173
-137
lines changed

xds/src/main/java/io/grpc/xds/internal/extauthz/ExtAuthzConfigParser.java renamed to xds/src/main/java/io/grpc/xds/ExtAuthzConfigParser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.grpc.xds.internal.extauthz;
17+
package io.grpc.xds;
1818

1919
import com.google.common.collect.ImmutableList;
2020
import io.envoyproxy.envoy.extensions.filters.http.ext_authz.v3.ExtAuthz;
2121
import io.grpc.internal.GrpcUtil;
2222
import io.grpc.xds.client.Bootstrapper.BootstrapInfo;
2323
import io.grpc.xds.client.Bootstrapper.ServerInfo;
2424
import io.grpc.xds.internal.MatcherParser;
25+
import io.grpc.xds.internal.extauthz.ExtAuthzConfig;
26+
import io.grpc.xds.internal.extauthz.ExtAuthzParseException;
2527
import io.grpc.xds.internal.grpcservice.GrpcServiceConfig;
26-
import io.grpc.xds.internal.grpcservice.GrpcServiceConfigParser;
2728
import io.grpc.xds.internal.grpcservice.GrpcServiceParseException;
2829
import io.grpc.xds.internal.headermutations.HeaderMutationRulesParseException;
2930
import io.grpc.xds.internal.headermutations.HeaderMutationRulesParser;

xds/src/main/java/io/grpc/xds/internal/grpcservice/ChannelCredsConfig.java renamed to xds/src/main/java/io/grpc/xds/GrpcBootstrapImplConfig.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,21 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.grpc.xds.internal.grpcservice;
17+
package io.grpc.xds;
18+
19+
import com.google.auto.value.AutoValue;
20+
import io.grpc.Internal;
21+
import io.grpc.xds.client.AllowedGrpcServices;
1822

1923
/**
20-
* Configuration for channel credentials.
24+
* Custom configuration for gRPC xDS bootstrap implementation.
2125
*/
22-
public interface ChannelCredsConfig {
23-
/**
24-
* Returns the type of the credentials.
25-
*/
26-
String type();
26+
@Internal
27+
@AutoValue
28+
public abstract class GrpcBootstrapImplConfig {
29+
public abstract AllowedGrpcServices allowedGrpcServices();
30+
31+
public static GrpcBootstrapImplConfig create(AllowedGrpcServices services) {
32+
return new AutoValue_GrpcBootstrapImplConfig(services);
33+
}
2734
}

xds/src/main/java/io/grpc/xds/GrpcBootstrapperImpl.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
import io.grpc.CallCredentials;
2323
import io.grpc.ChannelCredentials;
2424
import io.grpc.internal.JsonUtil;
25+
import io.grpc.xds.client.AllowedGrpcServices;
26+
import io.grpc.xds.client.AllowedGrpcServices.AllowedGrpcService;
2527
import io.grpc.xds.client.BootstrapperImpl;
28+
import io.grpc.xds.client.ConfiguredChannelCredentials;
29+
import io.grpc.xds.client.ConfiguredChannelCredentials.ChannelCredsConfig;
2630
import io.grpc.xds.client.XdsInitializationException;
2731
import io.grpc.xds.client.XdsLogger;
28-
import io.grpc.xds.internal.grpcservice.AllowedGrpcService;
29-
import io.grpc.xds.internal.grpcservice.AllowedGrpcServices;
30-
import io.grpc.xds.internal.grpcservice.ChannelCredsConfig;
31-
import io.grpc.xds.internal.grpcservice.ConfiguredChannelCredentials;
3232
import java.io.IOException;
3333
import java.util.List;
3434
import java.util.Map;
@@ -173,11 +173,11 @@ private static ConfiguredChannelCredentials parseChannelCredentials(List<Map<Str
173173
}
174174

175175
@Override
176-
protected Optional<Object> parseAllowedGrpcServices(
176+
protected Optional<Object> parseImplSpecificObject(
177177
@Nullable Map<String, ?> rawAllowedGrpcServices)
178178
throws XdsInitializationException {
179179
if (rawAllowedGrpcServices == null || rawAllowedGrpcServices.isEmpty()) {
180-
return Optional.of(AllowedGrpcServices.empty());
180+
return Optional.of(GrpcBootstrapImplConfig.create(AllowedGrpcServices.empty()));
181181
}
182182

183183
ImmutableMap.Builder<String, AllowedGrpcService> builder =
@@ -203,7 +203,9 @@ protected Optional<Object> parseAllowedGrpcServices(
203203
callCredentials.ifPresent(b::callCredentials);
204204
builder.put(targetUri, b.build());
205205
}
206-
return Optional.of(AllowedGrpcServices.create(builder.build()));
206+
GrpcBootstrapImplConfig customConfig =
207+
GrpcBootstrapImplConfig.create(AllowedGrpcServices.create(builder.build()));
208+
return Optional.of(customConfig);
207209
}
208210

209211
@SuppressWarnings("unused")

xds/src/main/java/io/grpc/xds/internal/grpcservice/GrpcServiceConfigParser.java renamed to xds/src/main/java/io/grpc/xds/GrpcServiceConfigParser.java

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.grpc.xds.internal.grpcservice;
17+
package io.grpc.xds;
1818

1919
import com.google.auth.oauth2.AccessToken;
2020
import com.google.auth.oauth2.OAuth2Credentials;
@@ -33,8 +33,14 @@
3333
import io.grpc.SecurityLevel;
3434
import io.grpc.alts.GoogleDefaultChannelCredentials;
3535
import io.grpc.auth.MoreCallCredentials;
36-
import io.grpc.xds.XdsChannelCredentials;
36+
import io.grpc.xds.client.AllowedGrpcServices;
37+
import io.grpc.xds.client.AllowedGrpcServices.AllowedGrpcService;
3738
import io.grpc.xds.client.Bootstrapper;
39+
import io.grpc.xds.client.ConfiguredChannelCredentials;
40+
import io.grpc.xds.internal.grpcservice.GrpcServiceConfig;
41+
import io.grpc.xds.internal.grpcservice.GrpcServiceParseException;
42+
import io.grpc.xds.internal.grpcservice.HeaderValue;
43+
import io.grpc.xds.internal.grpcservice.HeaderValueValidationUtils;
3844
import java.net.URI;
3945
import java.net.URISyntaxException;
4046
import java.time.Duration;
@@ -65,7 +71,7 @@ public final class GrpcServiceConfigParser {
6571
"type.googleapis.com/envoy.extensions.grpc_service.channel_credentials."
6672
+ "google_default.v3.GoogleDefaultCredentials";
6773

68-
private GrpcServiceConfigParser() {}
74+
6975

7076
/**
7177
* Parses the {@link io.envoyproxy.envoy.config.core.v3.GrpcService} proto to create a
@@ -75,9 +81,8 @@ private GrpcServiceConfigParser() {}
7581
* @return A {@link GrpcServiceConfig} instance.
7682
* @throws GrpcServiceParseException if the proto is invalid or uses unsupported features.
7783
*/
78-
public static GrpcServiceConfig parse(
79-
GrpcService grpcServiceProto, Bootstrapper.BootstrapInfo bootstrapInfo,
80-
Bootstrapper.ServerInfo serverInfo)
84+
public static GrpcServiceConfig parse(GrpcService grpcServiceProto,
85+
Bootstrapper.BootstrapInfo bootstrapInfo, Bootstrapper.ServerInfo serverInfo)
8186
throws GrpcServiceParseException {
8287
if (!grpcServiceProto.hasGoogleGrpc()) {
8388
throw new GrpcServiceParseException(
@@ -125,15 +130,16 @@ public static GrpcServiceConfig parse(
125130
*/
126131
public static GrpcServiceConfig.GoogleGrpcConfig parseGoogleGrpcConfig(
127132
GrpcService.GoogleGrpc googleGrpcProto, Bootstrapper.BootstrapInfo bootstrapInfo,
128-
Bootstrapper.ServerInfo serverInfo)
129-
throws GrpcServiceParseException {
133+
Bootstrapper.ServerInfo serverInfo) throws GrpcServiceParseException {
130134

131135
String targetUri = googleGrpcProto.getTargetUri();
132136

133-
AllowedGrpcServices allowedGrpcServices = bootstrapInfo.allowedGrpcServices()
134-
.filter(AllowedGrpcServices.class::isInstance)
135-
.map(AllowedGrpcServices.class::cast)
136-
.orElse(AllowedGrpcServices.empty());
137+
AllowedGrpcServices allowedGrpcServices =
138+
bootstrapInfo.implSpecificObject()
139+
.filter(GrpcBootstrapImplConfig.class::isInstance)
140+
.map(GrpcBootstrapImplConfig.class::cast)
141+
.map(GrpcBootstrapImplConfig::allowedGrpcServices)
142+
.orElse(AllowedGrpcServices.empty());
137143

138144
boolean isTrustedControlPlane = serverInfo.isTrustedXdsServer();
139145
Optional<AllowedGrpcService> override =
@@ -165,8 +171,7 @@ public static GrpcServiceConfig.GoogleGrpcConfig parseGoogleGrpcConfig(
165171
}
166172

167173
GrpcServiceConfig.GoogleGrpcConfig.Builder builder =
168-
GrpcServiceConfig.GoogleGrpcConfig.builder()
169-
.target(targetUri)
174+
GrpcServiceConfig.GoogleGrpcConfig.builder().target(targetUri)
170175
.configuredChannelCredentials(override.get().configuredChannelCredentials());
171176
if (override.get().callCredentials().isPresent()) {
172177
builder.callCredentials(override.get().callCredentials().get());
@@ -189,19 +194,18 @@ public static GrpcServiceConfig.GoogleGrpcConfig parseGoogleGrpcConfig(
189194
return builder.build();
190195
}
191196

192-
private static Optional<ConfiguredChannelCredentials> channelCredsFromProto(
193-
Any cred) throws GrpcServiceParseException {
197+
private static Optional<ConfiguredChannelCredentials> channelCredsFromProto(Any cred)
198+
throws GrpcServiceParseException {
194199
String typeUrl = cred.getTypeUrl();
195200
try {
196201
switch (typeUrl) {
197202
case GOOGLE_DEFAULT_CREDENTIALS_TYPE_URL:
198-
return Optional.of(ConfiguredChannelCredentials.create(
199-
GoogleDefaultChannelCredentials.create(),
200-
new ProtoChannelCredsConfig(typeUrl, cred)));
203+
return Optional
204+
.of(ConfiguredChannelCredentials.create(GoogleDefaultChannelCredentials.create(),
205+
new ProtoChannelCredsConfig(typeUrl, cred)));
201206
case INSECURE_CREDENTIALS_TYPE_URL:
202207
return Optional.of(ConfiguredChannelCredentials.create(
203-
InsecureChannelCredentials.create(),
204-
new ProtoChannelCredsConfig(typeUrl, cred)));
208+
InsecureChannelCredentials.create(), new ProtoChannelCredsConfig(typeUrl, cred)));
205209
case XDS_CREDENTIALS_TYPE_URL:
206210
XdsCredentials xdsConfig = cred.unpack(XdsCredentials.class);
207211
Optional<ConfiguredChannelCredentials> fallbackCreds =
@@ -292,7 +296,8 @@ public void applyRequestMetadata(RequestInfo requestInfo, Executor appExecutor,
292296
}
293297
}
294298

295-
static final class ProtoChannelCredsConfig implements ChannelCredsConfig {
299+
static final class ProtoChannelCredsConfig
300+
implements ConfiguredChannelCredentials.ChannelCredsConfig {
296301
private final String type;
297302
private final Any configProto;
298303

xds/src/main/java/io/grpc/xds/internal/grpcservice/AllowedGrpcServices.java renamed to xds/src/main/java/io/grpc/xds/client/AllowedGrpcServices.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.grpc.xds.internal.grpcservice;
17+
package io.grpc.xds.client;
1818

1919
import com.google.auto.value.AutoValue;
2020
import com.google.common.collect.ImmutableMap;
21+
import io.grpc.CallCredentials;
22+
import io.grpc.Internal;
2123
import java.util.Map;
24+
import java.util.Optional;
2225

2326
/**
2427
* Wrapper for allowed gRPC services keyed by target URI.
2528
*/
29+
@Internal
2630
@AutoValue
2731
public abstract class AllowedGrpcServices {
2832
public abstract ImmutableMap<String, AllowedGrpcService> services();
@@ -34,4 +38,29 @@ public static AllowedGrpcServices create(Map<String, AllowedGrpcService> service
3438
public static AllowedGrpcServices empty() {
3539
return create(ImmutableMap.of());
3640
}
41+
42+
/**
43+
* Represents an allowed gRPC service configuration with call credentials.
44+
*/
45+
@Internal
46+
@AutoValue
47+
public abstract static class AllowedGrpcService {
48+
public abstract ConfiguredChannelCredentials configuredChannelCredentials();
49+
50+
public abstract Optional<CallCredentials> callCredentials();
51+
52+
public static Builder builder() {
53+
return new AutoValue_AllowedGrpcServices_AllowedGrpcService.Builder();
54+
}
55+
56+
@AutoValue.Builder
57+
public abstract static class Builder {
58+
public abstract Builder configuredChannelCredentials(
59+
ConfiguredChannelCredentials credentials);
60+
61+
public abstract Builder callCredentials(CallCredentials callCredentials);
62+
63+
public abstract AllowedGrpcService build();
64+
}
65+
}
3766
}

xds/src/main/java/io/grpc/xds/client/Bootstrapper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,17 @@ public abstract static class BootstrapInfo {
207207
public abstract ImmutableMap<String, AuthorityInfo> authorities();
208208

209209
/**
210-
* Parsed allowed_grpc_services configuration.
210+
* Parsed configuration for implementation-specific extensions.
211211
* Returns an opaque object containing the parsed configuration.
212212
*/
213-
public abstract Optional<Object> allowedGrpcServices();
213+
public abstract Optional<Object> implSpecificObject();
214214

215215
@VisibleForTesting
216216
public static Builder builder() {
217217
return new AutoValue_Bootstrapper_BootstrapInfo.Builder()
218218
.clientDefaultListenerResourceNameTemplate("%s")
219219
.authorities(ImmutableMap.<String, AuthorityInfo>of())
220-
.allowedGrpcServices(Optional.empty());
220+
.implSpecificObject(Optional.empty());
221221
}
222222

223223
@AutoValue.Builder
@@ -239,7 +239,7 @@ public abstract Builder clientDefaultListenerResourceNameTemplate(
239239

240240
public abstract Builder authorities(Map<String, AuthorityInfo> authorities);
241241

242-
public abstract Builder allowedGrpcServices(Optional<Object> allowedGrpcServices);
242+
public abstract Builder implSpecificObject(Optional<Object> implSpecificObject);
243243

244244
public abstract BootstrapInfo build();
245245
}

xds/src/main/java/io/grpc/xds/client/BootstrapperImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,12 @@ protected BootstrapInfo.Builder bootstrapBuilder(Map<String, ?> rawData)
242242
}
243243

244244
Map<String, ?> rawAllowedGrpcServices = JsonUtil.getObject(rawData, "allowed_grpc_services");
245-
builder.allowedGrpcServices(parseAllowedGrpcServices(rawAllowedGrpcServices));
245+
builder.implSpecificObject(parseImplSpecificObject(rawAllowedGrpcServices));
246246

247247
return builder;
248248
}
249249

250-
protected Optional<Object> parseAllowedGrpcServices(
250+
protected Optional<Object> parseImplSpecificObject(
251251
@Nullable Map<String, ?> rawAllowedGrpcServices)
252252
throws XdsInitializationException {
253253
return Optional.empty();

xds/src/main/java/io/grpc/xds/internal/grpcservice/ConfiguredChannelCredentials.java renamed to xds/src/main/java/io/grpc/xds/client/ConfiguredChannelCredentials.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.grpc.xds.internal.grpcservice;
17+
package io.grpc.xds.client;
1818

1919
import com.google.auto.value.AutoValue;
2020
import io.grpc.ChannelCredentials;
21+
import io.grpc.Internal;
2122

2223
/**
2324
* Composition of {@link ChannelCredentials} and {@link ChannelCredsConfig}.
2425
*/
26+
@Internal
2527
@AutoValue
2628
public abstract class ConfiguredChannelCredentials {
2729
public abstract ChannelCredentials channelCredentials();
@@ -32,4 +34,15 @@ public static ConfiguredChannelCredentials create(ChannelCredentials creds,
3234
ChannelCredsConfig config) {
3335
return new AutoValue_ConfiguredChannelCredentials(creds, config);
3436
}
37+
38+
/**
39+
* Configuration for channel credentials.
40+
*/
41+
@Internal
42+
public interface ChannelCredsConfig {
43+
/**
44+
* Returns the type of the credentials.
45+
*/
46+
String type();
47+
}
3548
}

xds/src/main/java/io/grpc/xds/internal/grpcservice/AllowedGrpcService.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)