Extract shared adapter validation helpers

This commit is contained in:
Lyncoln
2026-09-20 18:47:21 -04:00
parent d4ceb7e1df
commit 832928159d
6 changed files with 232 additions and 28 deletions
+41
View File
@@ -0,0 +1,41 @@
from .adapters import Endpoint, NormalizedObject, PlanAction
def require_endpoint_plugin(
endpoint: Endpoint,
plugin_name: str,
) -> None:
expected = plugin_name.strip().lower()
if not expected:
raise ValueError("Adapter plugin name cannot be empty")
if endpoint.plugin != expected:
raise RuntimeError(
f"Adapter {expected!r} cannot use endpoint "
f"{endpoint.identity!r}"
)
def require_action_endpoint(
action: PlanAction,
endpoint: Endpoint,
) -> None:
if action.endpoint_id != endpoint.identity:
raise RuntimeError(
f"Plan action for {action.endpoint_id!r} does not belong "
f"to adapter endpoint {endpoint.identity!r}"
)
def require_desired(
action: PlanAction,
*,
context: str = "Adapter apply",
) -> NormalizedObject:
if action.desired is None:
raise RuntimeError(
f"{context} requires desired state"
)
return action.desired