Files
wehub-resource-sync 4b6817381b
Benchmark image — build + push to ECR (any adapter) / build + push (push) Waiting to run
CI / quality (ubuntu-latest) (push) Waiting to run
CI / test (tools-runtime) (push) Waiting to run
CI / test (e2e-general) (push) Waiting to run
CI / test (cli-runtime) (push) Waiting to run
CI / test (e2e-provider-and-openclaw) (push) Waiting to run
CI / test (integrations-and-misc) (push) Waiting to run
CI / coverage-report (push) Blocked by required conditions
CI / test-kubernetes (push) Waiting to run
CI / should-run-thorough (push) Waiting to run
CI / test-thorough (cloudwatch-demo) (push) Blocked by required conditions
CI / test-thorough (flink-ecs) (push) Blocked by required conditions
CI / test-thorough (upstream-lambda) (push) Blocked by required conditions
CI / test-thorough (prefect-ecs-fargate) (push) Blocked by required conditions
CodeQL / Analyze (python) (push) Waiting to run
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Blocked by required conditions
Release / publish-release (push) Blocked by required conditions
Release / publish-main-release (push) Blocked by required conditions
Release / prepare (push) Waiting to run
Release / verify (push) Blocked by required conditions
Release / build-python-dist (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Blocked by required conditions
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Waiting to run
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:10:45 +08:00

74 lines
2.5 KiB
Python

"""Read access to the persisted remote-agent config — usable from layers below ``surfaces/``.
The wizard JSON file lives at the path returned by
:func:`config.constants.get_store_path`. Several layers below ``surfaces/`` —
notably ``platform/deployment/`` — need to *read* the persisted remote URLs and
the remote ops scope. They cannot import from ``surfaces.cli.wizard.store``
without violating the layering contract in ``surfaces/__init__.py``.
This module hosts the read-side functions in ``config/`` so the layering
holds. ``surfaces.cli.wizard.store`` re-exports them under their original
names so existing callers (and unit-test mocks that patch the surfaces path)
keep working.
The write-side wizard helpers stay in ``surfaces/cli/wizard/store.py`` because
they belong to the wizard surface workflow.
"""
from __future__ import annotations
import json
from copy import deepcopy
from pathlib import Path
from typing import Any
from config.constants import get_store_path
_VERSION = 1
_EMPTY_CONFIG: dict[str, Any] = {
"version": _VERSION,
"wizard": {},
"targets": {},
"probes": {},
}
def _load_raw(path: Path | None = None) -> dict[str, Any]:
"""Read the wizard JSON safely; return an empty config on any failure."""
store_path = path or get_store_path()
if not store_path.exists():
return deepcopy(_EMPTY_CONFIG)
try:
data = json.loads(store_path.read_text(encoding="utf-8"))
except (json.JSONDecodeError, OSError):
return deepcopy(_EMPTY_CONFIG)
if not isinstance(data, dict):
return deepcopy(_EMPTY_CONFIG)
return data
def load_named_remotes(path: Path | None = None) -> dict[str, str]:
"""Return all named remotes as ``{name: url}``."""
data = _load_raw(path)
remotes: dict[str, Any] = data.get("remote", {}).get("remotes", {})
return {k: str(v.get("url", "")) for k, v in remotes.items() if v.get("url")}
def load_remote_ops_config(path: Path | None = None) -> dict[str, str | None]:
"""Return persisted remote ops config values."""
data = _load_raw(path)
remote_data = data.get("remote", {})
if not isinstance(remote_data, dict):
return {"provider": None, "project": None, "service": None}
return {
"provider": str(remote_data.get("provider") or "") or None,
"project": str(remote_data.get("project") or "") or None,
"service": str(remote_data.get("service") or "") or None,
}
__all__ = [
"load_named_remotes",
"load_remote_ops_config",
]