Resolve endpoint-local object dependencies

This commit is contained in:
Lyncoln
2026-09-19 21:34:23 -04:00
parent dc6505d165
commit 8caac79a1e
8 changed files with 1174 additions and 42 deletions
+39 -7
View File
@@ -1,5 +1,6 @@
from ...adapters import (
DNS_RECORDS,
ApplyResult,
Capability,
CapabilityOperation,
DiscoveredObject,
@@ -119,7 +120,7 @@ class Plugin:
wildcard=False,
)
def apply(self, action: PlanAction) -> str | None:
def apply(self, action: PlanAction) -> ApplyResult | None:
if action.endpoint_id != self.endpoint.identity:
raise RuntimeError(
"Plan action belongs to a different endpoint"
@@ -139,13 +140,44 @@ class Plugin:
record = self._desired_record(action.desired)
if action.operation == PlanOperation.CREATE:
return self.provider.add_record(record)
if action.operation == PlanOperation.UPDATE:
return self.provider.update_record(record)
detail = self.provider.add_record(record)
elif action.operation == PlanOperation.UPDATE:
detail = self.provider.update_record(record)
else:
raise RuntimeError(
f"Verizon adapter does not support "
f"{action.operation.value} actions"
)
raise RuntimeError(
f"Verizon adapter does not support "
f"{action.operation.value} actions"
records = self.provider.list_records()
applied_record = records.get(record.hostname.lower())
if applied_record is None:
applied_record = records.get(record.hostname)
if applied_record is None:
raise RuntimeError(
"Verizon mutation succeeded but the applied DNS "
f"record {record.hostname!r} could not be rediscovered"
)
slot = applied_record.metadata.get("slot")
if isinstance(slot, bool) or not isinstance(slot, int):
raise RuntimeError(
f"Verizon DNS record {record.hostname!r} "
"has no valid endpoint-local slot after apply"
)
applied = NormalizedObject(
object_type=action.desired.object_type,
logical_key=action.desired.logical_key,
local_key=str(slot),
payload=dict(action.desired.payload),
references=action.desired.references,
)
return ApplyResult(
object=applied,
detail=detail,
)
def verify(self, object: NormalizedObject) -> bool: