"""User-installed services persist in /data/services-overrides.yaml. Format: custom: - key: my-riva kind: stt host: user: container: riva-asr port: 8001 health_path: /health image: nvcr.io/nim/nvidia/riva-multilingual:latest """ from __future__ import annotations import os from pathlib import Path import yaml def _path() -> str: return os.environ.get("SERVICES_OVERRIDES", "/data/services-overrides.yaml") def load_custom_services() -> list[dict]: try: with open(_path()) as f: data = yaml.safe_load(f) or {} except FileNotFoundError: return [] return data.get("custom") or [] def add_custom_service(entry: dict) -> None: p = _path() Path(p).parent.mkdir(parents=True, exist_ok=True) data: dict = {} try: with open(p) as f: data = yaml.safe_load(f) or {} except FileNotFoundError: pass custom = data.get("custom") or [] custom = [c for c in custom if c.get("key") != entry["key"]] custom.append(entry) data["custom"] = custom with open(p, "w") as f: yaml.safe_dump(data, f, sort_keys=False) def delete_custom_service(key: str) -> None: p = _path() try: with open(p) as f: data = yaml.safe_load(f) or {} except FileNotFoundError: return data["custom"] = [c for c in (data.get("custom") or []) if c.get("key") != key] with open(p, "w") as f: yaml.safe_dump(data, f, sort_keys=False)