27 lines
978 B
Python
27 lines
978 B
Python
"""Evidence-backed facility anchors; never match an operator's headquarters by name."""
|
|
|
|
import json
|
|
from copy import deepcopy
|
|
from functools import lru_cache
|
|
from pathlib import Path
|
|
|
|
|
|
@lru_cache(maxsize=1)
|
|
def _site_index() -> dict[tuple[str, str], dict]:
|
|
payload = json.loads(Path(__file__).with_suffix(".json").read_text(encoding="utf-8"))
|
|
index = {}
|
|
for site in payload["sites"]:
|
|
if not (-90 <= site["latitude"] <= 90 and -180 <= site["longitude"] <= 180):
|
|
raise ValueError("Invalid verified compute facility coordinate")
|
|
for source_id in site["source_ids"]:
|
|
key = (site["source"], source_id)
|
|
if key in index:
|
|
raise ValueError("Duplicate verified compute facility identity")
|
|
index[key] = site
|
|
return index
|
|
|
|
|
|
def get_verified_compute_site(source: str, source_id: str) -> dict | None:
|
|
site = _site_index().get((source, source_id))
|
|
return deepcopy(site) if site else None
|