mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-29 19:35:20 +02:00
feat(automation): add template run context builder
This commit is contained in:
parent
de6da1b775
commit
cb42b3a84f
2 changed files with 53 additions and 0 deletions
12
surfsense_backend/app/automations/templating/__init__.py
Normal file
12
surfsense_backend/app/automations/templating/__init__.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
"""Sandboxed template engine for automation definitions."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from .context import build_run_context
|
||||
from .render import evaluate_predicate, render_template
|
||||
|
||||
__all__ = [
|
||||
"build_run_context",
|
||||
"evaluate_predicate",
|
||||
"render_template",
|
||||
]
|
||||
41
surfsense_backend/app/automations/templating/context.py
Normal file
41
surfsense_backend/app/automations/templating/context.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
"""Builder for the ``{run, inputs, steps}`` namespace exposed to every template."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
|
||||
def build_run_context(
|
||||
*,
|
||||
run_id: int,
|
||||
automation_id: int,
|
||||
automation_name: str | None,
|
||||
automation_version: int | None,
|
||||
search_space_id: int | None,
|
||||
creator_id: Any,
|
||||
trigger_id: int | None,
|
||||
trigger_type: str | None,
|
||||
started_at: datetime | None,
|
||||
attempt: int,
|
||||
resolved_inputs: Mapping[str, Any],
|
||||
step_outputs: Mapping[str, Any],
|
||||
) -> dict[str, Any]:
|
||||
"""Build the ``{run, inputs, steps}`` namespace exposed to every template."""
|
||||
return {
|
||||
"run": {
|
||||
"id": run_id,
|
||||
"automation_id": automation_id,
|
||||
"automation_name": automation_name,
|
||||
"automation_version": automation_version,
|
||||
"search_space_id": search_space_id,
|
||||
"creator_id": creator_id,
|
||||
"trigger_id": trigger_id,
|
||||
"trigger_type": trigger_type,
|
||||
"started_at": started_at,
|
||||
"attempt": attempt,
|
||||
},
|
||||
"inputs": dict(resolved_inputs),
|
||||
"steps": dict(step_outputs),
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue