|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from dataclasses import dataclass |
| 4 | + |
| 5 | + |
| 6 | +@dataclass(frozen=True, slots=True) |
| 7 | +class NodeSnapshot: |
| 8 | + peer_id: str |
| 9 | + channel_peers: tuple[str, ...] |
| 10 | + registered_agents: tuple[str, ...] |
| 11 | + active_agent_count: int |
| 12 | + |
| 13 | + def validate(self) -> None: |
| 14 | + if not self.peer_id.strip(): |
| 15 | + raise ValueError("peer_id must not be empty") |
| 16 | + |
| 17 | + |
| 18 | +@dataclass(frozen=True, slots=True) |
| 19 | +class NetworkSnapshot: |
| 20 | + peer_ids: tuple[str, ...] |
| 21 | + node_snapshots: tuple[NodeSnapshot, ...] |
| 22 | + |
| 23 | + def validate(self) -> None: |
| 24 | + snapshot_peer_ids = tuple(snapshot.peer_id for snapshot in self.node_snapshots) |
| 25 | + if tuple(sorted(snapshot_peer_ids)) != tuple(sorted(self.peer_ids)): |
| 26 | + raise ValueError("peer_ids do not match node_snapshots") |
| 27 | + |
| 28 | + |
| 29 | +@dataclass(frozen=True, slots=True) |
| 30 | +class ApplicationSnapshot: |
| 31 | + product_name: str |
| 32 | + version: str |
| 33 | + mode: str |
| 34 | + transport: str |
| 35 | + boot_id: str |
| 36 | + runtime_root: str |
| 37 | + audit_log_path: str |
| 38 | + identity_path: str |
| 39 | + identity_exists: bool |
| 40 | + native_extension_available: bool |
| 41 | + local_peer_id: str | None |
| 42 | + |
| 43 | + def validate(self) -> None: |
| 44 | + if not self.product_name.strip(): |
| 45 | + raise ValueError("product_name must not be empty") |
| 46 | + if not self.version.strip(): |
| 47 | + raise ValueError("version must not be empty") |
| 48 | + if not self.mode.strip(): |
| 49 | + raise ValueError("mode must not be empty") |
| 50 | + if not self.transport.strip(): |
| 51 | + raise ValueError("transport must not be empty") |
| 52 | + if not self.boot_id.strip(): |
| 53 | + raise ValueError("boot_id must not be empty") |
| 54 | + if not self.runtime_root.strip(): |
| 55 | + raise ValueError("runtime_root must not be empty") |
| 56 | + if not self.audit_log_path.strip(): |
| 57 | + raise ValueError("audit_log_path must not be empty") |
| 58 | + if not self.identity_path.strip(): |
| 59 | + raise ValueError("identity_path must not be empty") |
| 60 | + if self.local_peer_id is not None and not self.local_peer_id.strip(): |
| 61 | + raise ValueError("local_peer_id must not be empty when provided") |
0 commit comments