| 446 | } |
| 447 | |
| 448 | absl::Status Eval(const conformance::v1alpha1::EvalRequest& request, |
| 449 | conformance::v1alpha1::EvalResponse& response) override { |
| 450 | Arena arena; |
| 451 | cel::expr::SourceInfo source_info; |
| 452 | cel::expr::Expr expr = ExtractExpr(request); |
| 453 | builder_->set_container(request.container()); |
| 454 | absl::StatusOr<std::unique_ptr<CelExpression>> cel_expression_status = |
| 455 | absl::InternalError( |
| 456 | "no expression provided in ConformanceService::Eval"); |
| 457 | |
| 458 | if (request.has_parsed_expr()) { |
| 459 | cel::expr::ParsedExpr parsed_expr; |
| 460 | if (!ConvertWireCompatProto(request.parsed_expr(), &parsed_expr)) { |
| 461 | return absl::InternalError( |
| 462 | "failed to convert versioned ParsedExpr to unversioned"); |
| 463 | } |
| 464 | cel_expression_status = builder_->CreateExpression( |
| 465 | &parsed_expr.expr(), &parsed_expr.source_info()); |
| 466 | } else if (request.has_checked_expr()) { |
| 467 | cel::expr::CheckedExpr checked_expr; |
| 468 | if (!ConvertWireCompatProto(request.checked_expr(), &checked_expr)) { |
| 469 | return absl::InternalError( |
| 470 | "failed to convert versioned CheckedExpr to unversioned"); |
| 471 | } |
| 472 | cel_expression_status = builder_->CreateExpression(&checked_expr); |
| 473 | } |
| 474 | |
| 475 | if (!cel_expression_status.ok()) { |
| 476 | return absl::InternalError(cel_expression_status.status().ToString( |
| 477 | absl::StatusToStringMode::kWithEverything)); |
| 478 | } |
| 479 | |
| 480 | auto cel_expression = std::move(cel_expression_status.value()); |
| 481 | Activation activation; |
| 482 | |
| 483 | for (const auto& pair : request.bindings()) { |
| 484 | auto* import_value = Arena::Create<cel::expr::Value>(&arena); |
| 485 | ABSL_CHECK(ConvertWireCompatProto(pair.second.value(), // Crash OK |
| 486 | import_value)); |
| 487 | auto import_status = ValueToCelValue(*import_value, &arena); |
| 488 | if (!import_status.ok()) { |
| 489 | return absl::InternalError(import_status.status().ToString( |
| 490 | absl::StatusToStringMode::kWithEverything)); |
| 491 | } |
| 492 | activation.InsertValue(pair.first, import_status.value()); |
| 493 | } |
| 494 | |
| 495 | auto eval_status = cel_expression->Evaluate(activation, &arena); |
| 496 | if (!eval_status.ok()) { |
| 497 | *response.mutable_result() |
| 498 | ->mutable_error() |
| 499 | ->add_errors() |
| 500 | ->mutable_message() = eval_status.status().ToString( |
| 501 | absl::StatusToStringMode::kWithEverything); |
| 502 | return absl::OkStatus(); |
| 503 | } |
| 504 | |
| 505 | CelValue result = eval_status.value(); |
no test coverage detected