| 58 | using ::google::rpc::context::AttributeContext; |
| 59 | |
| 60 | absl::StatusOr<std::unique_ptr<cel::Compiler>> MakeCelCompiler() { |
| 61 | // Note: we are using the generated descriptor pool here for simplicity, but |
| 62 | // it has the drawback of including all message types that are linked into the |
| 63 | // binary instead of just the ones expected for the CEL environment. |
| 64 | google::protobuf::LinkMessageReflection<AttributeContext>(); |
| 65 | CEL_ASSIGN_OR_RETURN( |
| 66 | std::unique_ptr<cel::CompilerBuilder> builder, |
| 67 | cel::NewCompilerBuilder(google::protobuf::DescriptorPool::generated_pool())); |
| 68 | |
| 69 | CEL_RETURN_IF_ERROR(builder->AddLibrary(cel::StandardCompilerLibrary())); |
| 70 | // === Start Codelab === |
| 71 | cel::TypeCheckerBuilder& checker_builder = builder->GetCheckerBuilder(); |
| 72 | CEL_RETURN_IF_ERROR(checker_builder.AddVariable( |
| 73 | cel::MakeVariableDecl("bool_var", cel::BoolType()))); |
| 74 | CEL_RETURN_IF_ERROR(checker_builder.AddContextDeclaration( |
| 75 | AttributeContext::descriptor()->full_name())); |
| 76 | // === End Codelab === |
| 77 | |
| 78 | return builder->Build(); |
| 79 | } |
| 80 | |
| 81 | // Parse a cel expression and evaluate it against the given activation and |
| 82 | // arena. |
no test coverage detected