feat(office): align heartbeat office registrations
This commit is contained in:
parent
9c31e7f90c
commit
a17d7d678a
19 changed files with 1085 additions and 45 deletions
|
|
@ -6,6 +6,7 @@ import argparse
|
|||
import json
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from host_vehicle_registry import verify_registered_vehicle
|
||||
|
||||
from office_infrastructure import bootstrap
|
||||
|
||||
|
|
@ -24,6 +25,8 @@ def validate_application(application: dict[str, Any], subjects: dict[str, Any],
|
|||
human_id = application.get("human_id")
|
||||
persona_id = application.get("persona_id")
|
||||
office_id = application.get("office_id")
|
||||
host = application.get("host")
|
||||
vehicle_id = application.get("vehicle_id")
|
||||
errors: list[str] = []
|
||||
subject_map = {item.get("id"): item for item in subjects.get("subjects", [])}
|
||||
human = subject_map.get(human_id)
|
||||
|
|
@ -37,7 +40,9 @@ def validate_application(application: dict[str, Any], subjects: dict[str, Any],
|
|||
existing |= {item.get("id") for item in number_registry.get("registrations", []) if str(item.get("id", "")).startswith("HB-OFFICE-")}
|
||||
if office_id in existing: errors.append("OFFICE_ID_COLLISION")
|
||||
if not isinstance(office_id, str) or not office_id.startswith("HB-OFFICE-"): errors.append("OFFICE_ID_NOT_REGISTERED_NAMESPACE")
|
||||
return {"outcome":"PASS" if not errors else "FAIL", "errors":errors, "human":human, "persona":persona, "existing_office_count":len(existing), "office_id":office_id}
|
||||
if not host or not vehicle_id: errors.append("REGISTERED_HOST_VEHICLE_REQUIRED")
|
||||
elif verify_registered_vehicle(host,vehicle_id).get("outcome") != "PASS": errors.append("REGISTERED_HOST_VEHICLE_REQUIRED")
|
||||
return {"outcome":"PASS" if not errors else "FAIL", "errors":errors, "human":human, "persona":persona, "existing_office_count":len(existing), "office_id":office_id, "host":host, "vehicle_id":vehicle_id}
|
||||
|
||||
|
||||
def register(application: dict[str, Any], office_root: Path) -> dict[str, Any]:
|
||||
|
|
@ -45,7 +50,7 @@ def register(application: dict[str, Any], office_root: Path) -> dict[str, Any]:
|
|||
check = validate_application(application, subjects, numbers, board, ledger)
|
||||
if check["outcome"] != "PASS": return {"outcome":"REJECTED", "check":check, "authority_granted":False}
|
||||
installed = bootstrap(application["office_id"], application["office_name"], office_root, application["persona_id"], application["human_id"])
|
||||
ledger["registrations"].append({"office_id":application["office_id"], "office_name":application["office_name"], "human_id":application["human_id"], "persona_id":application["persona_id"], "state":"REGISTERED_STANDARD_INFRASTRUCTURE_BOOTSTRAPPED", "infrastructure":installed["organs"]})
|
||||
ledger["registrations"].append({"office_id":application["office_id"], "office_name":application["office_name"], "human_id":application["human_id"], "persona_id":application["persona_id"], "host":application["host"], "vehicle_id":application["vehicle_id"], "state":"REGISTERED_STANDARD_INFRASTRUCTURE_BOOTSTRAPPED", "hr_stamp":{"state":"HR_REGISTERED","office_id":application["office_id"],"host":application["host"],"vehicle_id":application["vehicle_id"]}, "infrastructure":installed["organs"]})
|
||||
REGISTRY.write_text(json.dumps(ledger, ensure_ascii=False, indent=2) + "\n")
|
||||
return {"outcome":"REGISTERED", "check":check, "registration":ledger["registrations"][-1], "authority_granted":False}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue