| 56 | |
| 57 | |
| 58 | class FileConnectionsStorage(ConnectionsStorage): |
| 59 | def __init__(self, path: Path | None = None) -> None: |
| 60 | self._path = path or (_DATA_DIR / "connections.json") |
| 61 | |
| 62 | def load(self) -> dict[str, Any]: |
| 63 | try: |
| 64 | if self._path.exists(): |
| 65 | data = json.loads(self._path.read_text()) |
| 66 | if isinstance(data, dict): |
| 67 | return data |
| 68 | except Exception: |
| 69 | pass |
| 70 | return {} |
| 71 | |
| 72 | def save(self, data: dict[str, Any]) -> None: |
| 73 | try: |
| 74 | self._path.parent.mkdir(parents=True, exist_ok=True, mode=0o700) |
| 75 | self._path.write_text(json.dumps(data, indent=2, sort_keys=True)) |
| 76 | self._path.chmod(0o600) |
| 77 | except Exception: |
| 78 | pass |
| 79 | |
| 80 | |
| 81 | class InMemoryConnectionsStorage(ConnectionsStorage): |
no outgoing calls