Skip to content

Commit f312c9c

Browse files
committed
Restore MatchContext and CelMatcherTestHelper additions for Unified Matcher
1 parent 5836446 commit f312c9c

2 files changed

Lines changed: 34 additions & 6 deletions

File tree

xds/src/main/java/io/grpc/xds/internal/matcher/MatchContext.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,52 @@
1818

1919
import com.google.common.base.Preconditions;
2020
import io.grpc.Metadata;
21+
import javax.annotation.Nullable;
2122

2223
public final class MatchContext {
2324
private final Metadata metadata;
25+
@Nullable
2426
private final String path;
27+
@Nullable
2528
private final String host;
29+
@Nullable
2630
private final String method;
31+
@Nullable
32+
private final String id;
2733

28-
public MatchContext(Metadata metadata, String path,
29-
String host, String method) {
34+
public MatchContext(Metadata metadata, @Nullable String path,
35+
@Nullable String host, @Nullable String method,
36+
@Nullable String id) {
3037
this.metadata = Preconditions.checkNotNull(metadata, "metadata");
31-
this.path = Preconditions.checkNotNull(path, "path");
32-
this.host = Preconditions.checkNotNull(host, "host");
33-
this.method = Preconditions.checkNotNull(method, "method");
38+
this.path = path;
39+
this.host = host;
40+
this.method = method;
41+
this.id = id;
3442
}
3543

3644
public Metadata getMetadata() {
3745
return metadata;
3846
}
3947

48+
@Nullable
4049
public String getPath() {
4150
return path;
4251
}
4352

53+
@Nullable
4454
public String getHost() {
4555
return host;
4656
}
4757

58+
@Nullable
4859
public String getMethod() {
4960
return method;
5061
}
62+
63+
@Nullable
64+
public String getId() {
65+
return id;
66+
}
5167

5268
public static Builder newBuilder() {
5369
return new Builder();
@@ -58,6 +74,7 @@ public static final class Builder {
5874
private String path;
5975
private String host;
6076
private String method;
77+
private String id;
6178

6279
public Builder setMetadata(Metadata metadata) {
6380
this.metadata = metadata;
@@ -79,8 +96,13 @@ public Builder setMethod(String method) {
7996
return this;
8097
}
8198

99+
public Builder setId(String id) {
100+
this.id = id;
101+
return this;
102+
}
103+
82104
public MatchContext build() {
83-
return new MatchContext(metadata, path, host, method);
105+
return new MatchContext(metadata, path, host, method, id);
84106
}
85107
}
86108
}

xds/src/test/java/io/grpc/xds/internal/matcher/CelMatcherTestHelper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public static CelAbstractSyntaxTree compileAst(String expression)
5454
return COMPILER.compile(expression).getAst();
5555
}
5656

57+
public static CelMatcher compile(String expression)
58+
throws dev.cel.common.CelException {
59+
CelAbstractSyntaxTree ast = COMPILER.compile(expression).getAst();
60+
return CelMatcher.compile(ast);
61+
}
62+
5763
public static CelStringExtractor compileStringExtractor(String expression)
5864
throws dev.cel.common.CelException {
5965
CelAbstractSyntaxTree ast = COMPILER.compile(expression).getAst();

0 commit comments

Comments
 (0)