feat: add read-only resource and route discovery
This commit is contained in:
@@ -11,7 +11,8 @@ from typing import Any
|
||||
from urllib import error, parse, request
|
||||
|
||||
from archive_clients.config import ServiceConfig
|
||||
from archive_control.v1 import common_pb2
|
||||
from archive_clients.routes import discover_routes
|
||||
from archive_control.v1 import common_pb2, route_pb2
|
||||
|
||||
|
||||
_MAX_RESPONSE_BYTES = 1024 * 1024
|
||||
@@ -28,6 +29,7 @@ class ServiceProbe:
|
||||
detail: str = ""
|
||||
device_id: str = ""
|
||||
libtorrent_version: str = ""
|
||||
routes: tuple[route_pb2.LocalRoute, ...] = ()
|
||||
|
||||
|
||||
class _NoRedirect(request.HTTPRedirectHandler):
|
||||
@@ -95,7 +97,9 @@ def probe_qbittorrent(
|
||||
|
||||
|
||||
def probe_syncthing(
|
||||
config: ServiceConfig, timeout: float = 10
|
||||
config: ServiceConfig,
|
||||
timeout: float = 10,
|
||||
sparse_supported: bool = False,
|
||||
) -> ServiceProbe:
|
||||
checked_at = datetime.now(timezone.utc)
|
||||
try:
|
||||
@@ -107,15 +111,23 @@ def probe_syncthing(
|
||||
status = _json_get(
|
||||
opener, config.endpoint, "/rest/system/status", timeout, headers
|
||||
)
|
||||
configuration = _json_get(
|
||||
opener, config.endpoint, "/rest/config", timeout, headers
|
||||
)
|
||||
service_version = version.get("longVersion") or version.get("version")
|
||||
device_id = status.get("myID")
|
||||
if not isinstance(service_version, str) or not service_version:
|
||||
raise ValueError("Syncthing returned no version")
|
||||
if not isinstance(device_id, str) or not device_id:
|
||||
raise ValueError("Syncthing returned no device ID")
|
||||
routes = discover_routes(
|
||||
configuration, device_id, config.roots, sparse_supported,
|
||||
checked_at,
|
||||
)
|
||||
return ServiceProbe(
|
||||
"syncthing", common_pb2.HEALTH_STATE_HEALTHY, checked_at,
|
||||
version=service_version, device_id=device_id,
|
||||
routes=tuple(routes),
|
||||
)
|
||||
except error.HTTPError as exc:
|
||||
detail = (
|
||||
|
||||
Reference in New Issue
Block a user