| 53 | using ::google::rpc::context::AttributeContext; |
| 54 | |
| 55 | absl::StatusOr<std::unique_ptr<cel::Compiler>> MakeCelCompiler() { |
| 56 | // Note: we are using the generated descriptor pool here for simplicity, but |
| 57 | // it has the drawback of including all message types that are linked into the |
| 58 | // binary instead of just the ones expected for the CEL environment. |
| 59 | google::protobuf::LinkMessageReflection<AttributeContext>(); |
| 60 | CEL_ASSIGN_OR_RETURN( |
| 61 | std::unique_ptr<cel::CompilerBuilder> builder, |
| 62 | cel::NewCompilerBuilder(google::protobuf::DescriptorPool::generated_pool())); |
| 63 | |
| 64 | CEL_RETURN_IF_ERROR(builder->AddLibrary(cel::StandardCompilerLibrary())); |
| 65 | // === Start Codelab === |
| 66 | // Add 'AttributeContext' as a context message to the type checker and a |
| 67 | // boolean variable 'bool_var'. Relevant functions are on the |
| 68 | // TypeCheckerBuilder class (see CompilerBuilder::GetCheckerBuilder). |
| 69 | // |
| 70 | // We're reusing the same compiler for both evaluation paths here for brevity, |
| 71 | // but it's likely a better fit to configure a separate compiler per use case. |
| 72 | // === End Codelab === |
| 73 | |
| 74 | return builder->Build(); |
| 75 | } |
| 76 | |
| 77 | // Parse a cel expression and evaluate it against the given activation and |
| 78 | // arena. |
no test coverage detected