|
| 1 | +// Copyright 2026 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#include "absl/status/status.h" |
| 16 | +#include "absl/strings/str_cat.h" |
| 17 | +#include "compiler/compiler.h" |
| 18 | +#include "extensions/lists_functions.h" |
| 19 | +#include "runtime/runtime_builder.h" |
| 20 | +#include "runtime/runtime_options.h" |
| 21 | +#include "cel_expr_python/cel_extension.h" |
| 22 | +#include "cel_expr_python/py_error_status.h" |
| 23 | + |
| 24 | +namespace cel_python { |
| 25 | + |
| 26 | +class ExtLists : public CelExtension { |
| 27 | + public: |
| 28 | + explicit ExtLists(int version) |
| 29 | + : CelExtension("cel.lib.ext.lists", "lists", version) { |
| 30 | + if (version < 0 || |
| 31 | + version > cel::extensions::kListsExtensionLatestVersion) { |
| 32 | + throw StatusToException(absl::InvalidArgumentError(absl::StrCat( |
| 33 | + "'lists' extension version: ", version, " not in range [0, ", |
| 34 | + cel::extensions::kListsExtensionLatestVersion, "]"))); |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + ExtLists() : ExtLists(cel::extensions::kListsExtensionLatestVersion) {} |
| 39 | + |
| 40 | + cel::CompilerLibrary GetCompilerLibrary() override { |
| 41 | + return cel::extensions::ListsCompilerLibrary(version()); |
| 42 | + } |
| 43 | + |
| 44 | + absl::Status ConfigureRuntime(cel::RuntimeBuilder& runtime_builder, |
| 45 | + const cel::RuntimeOptions& opts) override { |
| 46 | + return cel::extensions::RegisterListsFunctions( |
| 47 | + runtime_builder.function_registry(), opts, |
| 48 | + cel::extensions::ListsExtensionOptions{.version = version()}); |
| 49 | + } |
| 50 | +}; |
| 51 | + |
| 52 | +CEL_VERSIONED_EXTENSION_MODULE(ext_lists, ExtLists); |
| 53 | + |
| 54 | +} // namespace cel_python |
0 commit comments