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