Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions extensions/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ java_library(
exports = ["//extensions/src/main/java/dev/cel/extensions:math"],
)

java_library(
name = "network",
exports = ["//extensions/src/main/java/dev/cel/extensions:network"],
)

java_library(
name = "optional_library",
exports = ["//extensions/src/main/java/dev/cel/extensions:optional_library"],
Expand Down
20 changes: 20 additions & 0 deletions extensions/src/main/java/dev/cel/extensions/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ java_library(
":encoders",
":lists",
":math",
":network",
":optional_library",
":protos",
":regex",
Expand Down Expand Up @@ -135,6 +136,25 @@ java_library(
],
)

java_library(
name = "network",
srcs = ["CelNetworkExtensions.java"],
deps = [
":extension_library",
"//checker:checker_builder",
"//common:compiler_common",
"//common/types",
"//common/types:type_providers",
"//compiler:compiler_builder",
"//java/com/google/common/net",
"//java/com/google/net/base:base-core",
"//runtime",
"//runtime:function_binding",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
],
)

java_library(
name = "bindings",
srcs = ["CelBindingsExtensions.java"],
Expand Down
53 changes: 29 additions & 24 deletions extensions/src/main/java/dev/cel/extensions/CelExtensions.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public final class CelExtensions {
private static final CelRegexExtensions REGEX_EXTENSIONS = new CelRegexExtensions();
private static final CelComprehensionsExtensions COMPREHENSIONS_EXTENSIONS =
new CelComprehensionsExtensions();
private static final CelNetworkExtensions NETWORK_EXTENSIONS = new CelNetworkExtensions();

/**
* Implementation of optional values.
Expand Down Expand Up @@ -319,6 +320,18 @@ public static CelComprehensionsExtensions comprehensions() {
return COMPREHENSIONS_EXTENSIONS;
}

/**
* Extended functions for Network manipulation.
*
* <p>Refer to README.md for available functions.
*
* <p>This will include all functions denoted in {@link CelNetworkExtensions.Function}, including
* any future additions.
*/
public static CelNetworkExtensions network() {
return NETWORK_EXTENSIONS;
}

/**
* Retrieves all function names used by every extension libraries.
*
Expand All @@ -339,38 +352,30 @@ public static ImmutableSet<String> getAllFunctionNames() {
.map(CelListsExtensions.Function::getFunction),
stream(CelRegexExtensions.Function.values())
.map(CelRegexExtensions.Function::getFunction),
stream(CelNetworkExtensions.Function.values())
.map(CelNetworkExtensions.Function::getFunction),
stream(CelComprehensionsExtensions.Function.values())
.map(CelComprehensionsExtensions.Function::getFunction))
.collect(toImmutableSet());
}

public static CelExtensionLibrary<? extends CelExtensionLibrary.FeatureSet> getExtensionLibrary(
String name, CelOptions options) {
switch (name) {
case "bindings":
return CelBindingsExtensions.library();
case "encoders":
return CelEncoderExtensions.library(options);
case "lists":
return CelListsExtensions.library();
case "math":
return CelMathExtensions.library(options);
case "optional":
return CelOptionalLibrary.library();
case "protos":
return CelProtoExtensions.library();
case "regex":
return CelRegexExtensions.library();
case "sets":
return CelSetsExtensions.library(options);
case "strings":
return CelStringExtensions.library();
case "comprehensions":
return CelComprehensionsExtensions.library();
return switch (name) {
case "bindings" -> CelBindingsExtensions.library();
case "encoders" -> CelEncoderExtensions.library(options);
case "lists" -> CelListsExtensions.library();
case "math" -> CelMathExtensions.library(options);
case "network" -> CelNetworkExtensions.library();
case "optional" -> CelOptionalLibrary.library();
case "protos" -> CelProtoExtensions.library();
case "regex" -> CelRegexExtensions.library();
case "sets" -> CelSetsExtensions.library(options);
case "strings" -> CelStringExtensions.library();
case "comprehensions" -> CelComprehensionsExtensions.library();
// TODO: add support for remaining standard extensions
default:
throw new IllegalArgumentException("Unknown standard extension '" + name + "'");
}
default -> throw new IllegalArgumentException("Unknown standard extension '" + name + "'");
};
}

private CelExtensions() {}
Expand Down
Loading
Loading