extractCategoryFromExpr walks the CEL AST to extract the category value.
(expr celast.Expr)
| 505 | |
| 506 | // extractCategoryFromExpr walks the CEL AST to extract the category value. |
| 507 | func extractCategoryFromExpr(expr celast.Expr) (string, error) { |
| 508 | switch expr.Kind() { |
| 509 | case celast.CallKind: |
| 510 | call := expr.AsCall() |
| 511 | functionName := call.FunctionName() |
| 512 | |
| 513 | // Handle: category == "value" |
| 514 | if functionName == celoperators.Equals { |
| 515 | variable, value := getVariableAndValueFromExpr(expr) |
| 516 | if variable == "category" { |
| 517 | if categoryValue, ok := value.(string); ok { |
| 518 | return categoryValue, nil |
| 519 | } |
| 520 | return "", errors.Errorf("category value must be a string, got %T", value) |
| 521 | } |
| 522 | return "", errors.Errorf("unsupported filter variable: %s", variable) |
| 523 | } |
| 524 | |
| 525 | return "", errors.Errorf("unsupported operator: %s (only '==' is supported)", functionName) |
| 526 | |
| 527 | default: |
| 528 | return "", errors.Errorf("unsupported expression type") |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | func renderTrain(template, timezone string, t time.Time) (string, error) { |
| 533 | // Validate template |
no test coverage detected