Compare commits
No commits in common. "main" and "test-scenario-3" have entirely different histories.
main
...
test-scena
@ -73,14 +73,22 @@ jobs:
|
||||
print(f"[{env}] Reconciler call failed: {e}")
|
||||
continue
|
||||
|
||||
# Format as markdown table
|
||||
# Format as markdown grouped by action
|
||||
ops = data.get("operations", [])
|
||||
summary = data.get("summary", {})
|
||||
lines = [f"## Reconciliation Plan: `{env}`\n"]
|
||||
if not ops:
|
||||
lines.append("No changes detected.\n")
|
||||
else:
|
||||
groups = {"Create": [], "Update": [], "Delete": []}
|
||||
for op in ops:
|
||||
t = op["type"]
|
||||
if t.startswith("create"): groups["Create"].append(op)
|
||||
elif t.startswith("delete"): groups["Delete"].append(op)
|
||||
else: groups["Update"].append(op)
|
||||
|
||||
def fmt_val(v):
|
||||
"""Format a value for display in markdown."""
|
||||
if isinstance(v, bool):
|
||||
return str(v).lower()
|
||||
if isinstance(v, list):
|
||||
@ -89,33 +97,14 @@ jobs:
|
||||
return "(none)"
|
||||
return str(v)
|
||||
|
||||
def get_action(op):
|
||||
"""Derive a human-readable action from the operation."""
|
||||
t = op["type"]
|
||||
changes = op.get("changes", [])
|
||||
# For updates, check if it's just an enable/disable toggle
|
||||
if not t.startswith("create") and not t.startswith("delete"):
|
||||
if len(changes) == 1 and changes[0]["field"] == "enabled":
|
||||
return "disable" if changes[0]["to"] is False else "enable"
|
||||
return "update"
|
||||
return t.split("_", 1)[0]
|
||||
|
||||
def fmt_details(op, action):
|
||||
"""Format details based on action type."""
|
||||
if action == "delete":
|
||||
return ""
|
||||
if action in ("enable", "disable"):
|
||||
return ""
|
||||
changes = op.get("changes", [])
|
||||
if changes:
|
||||
parts = []
|
||||
for c in changes:
|
||||
parts.append(f"`{c['field']}`: {fmt_val(c['from'])} → {fmt_val(c['to'])}")
|
||||
return "; ".join(parts)
|
||||
def fmt_create_details(op):
|
||||
"""Summarize key fields for a create operation."""
|
||||
d = op.get("details", {})
|
||||
if not d:
|
||||
return ""
|
||||
parts = []
|
||||
if "enabled" in d:
|
||||
parts.append(f"enabled={fmt_val(d['enabled'])}")
|
||||
if "sources" in d and "destinations" in d:
|
||||
parts.append(f"{fmt_val(d['sources'])} → {fmt_val(d['destinations'])}")
|
||||
if "auto_groups" in d:
|
||||
@ -126,13 +115,31 @@ jobs:
|
||||
parts.append(f"peers: {fmt_val(d['peers'])}")
|
||||
return "; ".join(parts) if parts else ""
|
||||
|
||||
lines.append("| Action | Resource | Name | Details |")
|
||||
lines.append("|--------|----------|------|---------|")
|
||||
for op in ops:
|
||||
def fmt_changes(op):
|
||||
"""Format field changes as 'field: old → new'."""
|
||||
changes = op.get("changes", [])
|
||||
if not changes:
|
||||
return ""
|
||||
parts = []
|
||||
for c in changes:
|
||||
parts.append(f"`{c['field']}`: {fmt_val(c['from'])} → {fmt_val(c['to'])}")
|
||||
return "; ".join(parts)
|
||||
|
||||
for action, items in groups.items():
|
||||
if not items:
|
||||
continue
|
||||
lines.append(f"### {action} ({len(items)})\n")
|
||||
lines.append("| Resource | Name | Details |")
|
||||
lines.append("|----------|------|---------|")
|
||||
for op in items:
|
||||
resource = op["type"].split("_", 1)[1] if "_" in op["type"] else op["type"]
|
||||
action = get_action(op)
|
||||
detail = fmt_details(op, action)
|
||||
lines.append(f"| {action} | {resource} | {op['name']} | {detail} |")
|
||||
if action == "Update":
|
||||
detail = fmt_changes(op)
|
||||
elif action == "Create":
|
||||
detail = fmt_create_details(op)
|
||||
else:
|
||||
detail = ""
|
||||
lines.append(f"| {resource} | {op['name']} | {detail} |")
|
||||
lines.append("")
|
||||
|
||||
c, u, d = summary.get("created", 0), summary.get("updated", 0), summary.get("deleted", 0)
|
||||
|
||||
@ -118,9 +118,7 @@ jobs:
|
||||
|
||||
keys = data.get("created_keys", {})
|
||||
if keys:
|
||||
print(f"[{env}] Created setup keys:")
|
||||
for name, value in keys.items():
|
||||
print(f" {name}: {value}")
|
||||
print(f"[{env}] Created setup keys: {list(keys.keys())}")
|
||||
|
||||
if failed:
|
||||
print(f"\nFailed environments: {failed}")
|
||||
|
||||
@ -12,7 +12,7 @@ function makeEvent(overrides: Partial<NbEvent> = {}): NbEvent {
|
||||
initiator_id: "init-1",
|
||||
initiator_name: "admin",
|
||||
target_id: "peer-1",
|
||||
meta: { setup_key_name: "drone-key", name: "drone-01" },
|
||||
meta: { setup_key: "drone-key", name: "drone-01" },
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
@ -66,7 +66,7 @@ Deno.test("processEnrollmentEvents filters by lastTimestamp", () => {
|
||||
Deno.test("processEnrollmentEvents ignores unknown keys", () => {
|
||||
const events: NbEvent[] = [
|
||||
makeEvent({
|
||||
meta: { setup_key_name: "rogue-key", name: "rogue-host" },
|
||||
meta: { setup_key: "rogue-key", name: "rogue-host" },
|
||||
target_id: "peer-x",
|
||||
}),
|
||||
];
|
||||
|
||||
@ -21,10 +21,10 @@ export function processEnrollmentEvents(
|
||||
.filter((e) => {
|
||||
if (e.activity_code !== "peer.setupkey.add") return false;
|
||||
if (lastTimestamp && e.timestamp <= lastTimestamp) return false;
|
||||
if (!knownKeyNames.has(e.meta.setup_key_name)) {
|
||||
if (!knownKeyNames.has(e.meta.setup_key)) {
|
||||
console.log(JSON.stringify({
|
||||
msg: "unknown_enrollment",
|
||||
setup_key_name: e.meta.setup_key_name,
|
||||
setup_key: e.meta.setup_key,
|
||||
peer_id: e.target_id,
|
||||
}));
|
||||
return false;
|
||||
@ -32,7 +32,7 @@ export function processEnrollmentEvents(
|
||||
return true;
|
||||
})
|
||||
.map((e) => ({
|
||||
setupKeyName: e.meta.setup_key_name,
|
||||
setupKeyName: e.meta.setup_key,
|
||||
peerId: e.target_id,
|
||||
peerHostname: e.meta.name,
|
||||
timestamp: e.timestamp,
|
||||
|
||||
@ -15,40 +15,23 @@
|
||||
"type": "one-off",
|
||||
"expires_in": 604800,
|
||||
"usage_limit": 1,
|
||||
"auto_groups": [
|
||||
"ground-stations"
|
||||
],
|
||||
"auto_groups": ["ground-stations"],
|
||||
"enrolled": false
|
||||
},
|
||||
"Pilot-TestHawk-1": {
|
||||
"type": "one-off",
|
||||
"expires_in": 604800,
|
||||
"usage_limit": 1,
|
||||
"auto_groups": [
|
||||
"pilots"
|
||||
],
|
||||
"auto_groups": ["pilots"],
|
||||
"enrolled": false
|
||||
},
|
||||
"GS-Enroll-Test": {
|
||||
"type": "one-off",
|
||||
"expires_in": 604800,
|
||||
"usage_limit": 1,
|
||||
"auto_groups": [
|
||||
"ground-stations"
|
||||
],
|
||||
"enrolled": true
|
||||
}
|
||||
},
|
||||
"policies": {
|
||||
"pilots-to-gs": {
|
||||
"description": "",
|
||||
"enabled": false,
|
||||
"sources": [
|
||||
"pilots"
|
||||
],
|
||||
"destinations": [
|
||||
"ground-stations"
|
||||
],
|
||||
"sources": ["pilots"],
|
||||
"destinations": ["ground-stations"],
|
||||
"bidirectional": true,
|
||||
"protocol": "all",
|
||||
"action": "accept",
|
||||
@ -57,22 +40,14 @@
|
||||
"observers-to-gs": {
|
||||
"description": "",
|
||||
"enabled": true,
|
||||
"sources": [
|
||||
"observers"
|
||||
],
|
||||
"destinations": [
|
||||
"ground-stations"
|
||||
],
|
||||
"sources": ["observers"],
|
||||
"destinations": ["ground-stations"],
|
||||
"bidirectional": false,
|
||||
"protocol": "all",
|
||||
"action": "accept",
|
||||
"source_posture_checks": []
|
||||
}
|
||||
},
|
||||
"routes": {},
|
||||
"dns": {
|
||||
"nameserver_groups": {}
|
||||
},
|
||||
"posture_checks": {},
|
||||
"networks": {},
|
||||
"peers": {},
|
||||
@ -82,5 +57,9 @@
|
||||
"role": "owner",
|
||||
"auto_groups": []
|
||||
}
|
||||
},
|
||||
"routes": {},
|
||||
"dns": {
|
||||
"nameserver_groups": {}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user