feat: expose read-only admin surface
This commit is contained in:
@@ -4,6 +4,7 @@ from .app import create_rpc_app
|
||||
from .client import RpcWorkflowApiClient
|
||||
from .errors import WorkflowRpcError
|
||||
from .models import (
|
||||
AdminEmptyParams,
|
||||
CreateArtifactFromWorkspaceParams,
|
||||
CreateDraftFromCapabilityParams,
|
||||
CreateWrapperFromWorkspaceParams,
|
||||
@@ -35,6 +36,7 @@ from .models import (
|
||||
|
||||
__all__ = [
|
||||
"CreateArtifactFromWorkspaceParams",
|
||||
"AdminEmptyParams",
|
||||
"CreateDraftFromCapabilityParams",
|
||||
"CreateWrapperFromWorkspaceParams",
|
||||
"DeleteDeploymentParams",
|
||||
|
||||
@@ -7,6 +7,7 @@ import fastapi_jsonrpc as jsonrpc
|
||||
from wf_server import WorkflowServer
|
||||
|
||||
from .errors import WorkflowRpcError
|
||||
from .methods_admin import register_methods as register_admin_methods
|
||||
from .methods_artifacts import register_methods as register_artifact_methods
|
||||
from .methods_capabilities import register_methods as register_capability_methods
|
||||
from .methods_deployments import register_methods as register_deployment_methods
|
||||
@@ -45,6 +46,7 @@ def create_rpc_app(server: WorkflowServer, *, rpc_path: str = "/rpc") -> jsonrpc
|
||||
register_deployment_methods(entrypoint, server)
|
||||
register_run_methods(entrypoint, server)
|
||||
register_source_methods(entrypoint, server)
|
||||
register_admin_methods(entrypoint, server)
|
||||
|
||||
app.bind_entrypoint(entrypoint)
|
||||
return app
|
||||
|
||||
@@ -5,6 +5,7 @@ from dataclasses import dataclass
|
||||
import httpx # noqa: F401 # Backcompat for tests patching client.httpx.AsyncClient.
|
||||
|
||||
from .client_artifacts import RpcArtifactClientMixin
|
||||
from .client_admin import RpcAdminClientMixin
|
||||
from .client_base import RpcClientTransport
|
||||
from .client_capabilities import RpcCapabilityClientMixin
|
||||
from .client_deployments import RpcDeploymentClientMixin
|
||||
@@ -22,6 +23,7 @@ class RpcWorkflowApiClient(
|
||||
RpcDeploymentClientMixin,
|
||||
RpcRunClientMixin,
|
||||
RpcSourceAdminClientMixin,
|
||||
RpcAdminClientMixin,
|
||||
):
|
||||
"""WorkflowApiSurface implementation backed by JSON-RPC HTTP calls.
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
|
||||
class RpcAdminClientMixin:
|
||||
"""JSON-RPC implementation of read-only admin/config surface methods."""
|
||||
|
||||
async def _call(self, method: str, params: dict[str, Any]) -> dict[str, Any]: ...
|
||||
|
||||
async def list_connections(self) -> dict[str, Any]:
|
||||
return await self._call("workflow.admin.connections.list", {})
|
||||
|
||||
async def get_connection_statuses(self) -> dict[str, Any]:
|
||||
return await self._call("workflow.admin.connection_statuses.list", {})
|
||||
|
||||
async def list_events(self) -> dict[str, Any]:
|
||||
return await self._call("workflow.admin.events.list", {})
|
||||
@@ -0,0 +1,51 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from fastapi import Body
|
||||
import fastapi_jsonrpc as jsonrpc
|
||||
|
||||
from wf_server import WorkflowServer
|
||||
|
||||
from .errors import WorkflowRpcError, raise_workflow_rpc_error
|
||||
from .models import AdminEmptyParams
|
||||
|
||||
|
||||
def register_methods(
|
||||
entrypoint: jsonrpc.Entrypoint,
|
||||
server: WorkflowServer,
|
||||
) -> None:
|
||||
"""Register read-only admin/config JSON-RPC methods."""
|
||||
|
||||
@entrypoint.method(
|
||||
name="workflow.admin.connections.list",
|
||||
errors=[WorkflowRpcError],
|
||||
)
|
||||
async def workflow_admin_connections_list(
|
||||
params: AdminEmptyParams = Body(default_factory=AdminEmptyParams),
|
||||
) -> dict[str, Any]:
|
||||
try:
|
||||
return await server.admin.list_connections()
|
||||
except (ValueError, KeyError, LookupError, FileNotFoundError) as exc:
|
||||
raise_workflow_rpc_error(exc)
|
||||
|
||||
@entrypoint.method(
|
||||
name="workflow.admin.connection_statuses.list",
|
||||
errors=[WorkflowRpcError],
|
||||
)
|
||||
async def workflow_admin_connection_statuses_list(
|
||||
params: AdminEmptyParams = Body(default_factory=AdminEmptyParams),
|
||||
) -> dict[str, Any]:
|
||||
try:
|
||||
return await server.admin.get_connection_statuses()
|
||||
except (ValueError, KeyError, LookupError, FileNotFoundError) as exc:
|
||||
raise_workflow_rpc_error(exc)
|
||||
|
||||
@entrypoint.method(name="workflow.admin.events.list", errors=[WorkflowRpcError])
|
||||
async def workflow_admin_events_list(
|
||||
params: AdminEmptyParams = Body(default_factory=AdminEmptyParams),
|
||||
) -> dict[str, Any]:
|
||||
try:
|
||||
return await server.admin.list_events()
|
||||
except (ValueError, KeyError, LookupError, FileNotFoundError) as exc:
|
||||
raise_workflow_rpc_error(exc)
|
||||
@@ -30,6 +30,10 @@ class HealthParams(RpcParamsModel):
|
||||
pass
|
||||
|
||||
|
||||
class AdminEmptyParams(RpcParamsModel):
|
||||
pass
|
||||
|
||||
|
||||
class ListCapabilitiesParams(RpcParamsModel):
|
||||
query: str | None = Field(default=None)
|
||||
source_id: str | None = Field(default=None)
|
||||
|
||||
Reference in New Issue
Block a user