feat: expose source registry admin reads
This commit is contained in:
@@ -13,6 +13,7 @@ from .methods_capabilities import register_methods as register_capability_method
|
||||
from .methods_deployments import register_methods as register_deployment_methods
|
||||
from .methods_drafts import register_methods as register_draft_methods
|
||||
from .methods_runs import register_methods as register_run_methods
|
||||
from .methods_source_registry import register_methods as register_source_registry_methods
|
||||
from .methods_sources import register_methods as register_source_methods
|
||||
|
||||
|
||||
@@ -46,6 +47,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_source_registry_methods(entrypoint, server)
|
||||
register_admin_methods(entrypoint, server)
|
||||
|
||||
app.bind_entrypoint(entrypoint)
|
||||
|
||||
@@ -11,6 +11,7 @@ from .client_capabilities import RpcCapabilityClientMixin
|
||||
from .client_deployments import RpcDeploymentClientMixin
|
||||
from .client_drafts import RpcDraftClientMixin
|
||||
from .client_runs import RpcRunClientMixin
|
||||
from .client_source_registry import RpcSourceRegistryClientMixin
|
||||
from .client_sources import RpcSourceAdminClientMixin
|
||||
|
||||
|
||||
@@ -23,6 +24,7 @@ class RpcWorkflowApiClient(
|
||||
RpcDeploymentClientMixin,
|
||||
RpcRunClientMixin,
|
||||
RpcSourceAdminClientMixin,
|
||||
RpcSourceRegistryClientMixin,
|
||||
RpcAdminClientMixin,
|
||||
):
|
||||
"""WorkflowApiSurface implementation backed by JSON-RPC HTTP calls.
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
|
||||
class RpcSourceRegistryClientMixin:
|
||||
"""JSON-RPC implementation of read-only desired source registry surface methods."""
|
||||
|
||||
async def _call(self, method: str, params: dict[str, Any]) -> dict[str, Any]: ...
|
||||
|
||||
async def list_registry_entries(
|
||||
self,
|
||||
*,
|
||||
cursor: str | None = None,
|
||||
limit: int = 50,
|
||||
) -> dict[str, Any]:
|
||||
return await self._call(
|
||||
"workflow.admin.source_registry.list",
|
||||
{"cursor": cursor, "limit": limit},
|
||||
)
|
||||
|
||||
async def inspect_registry_entry(
|
||||
self,
|
||||
*,
|
||||
source_id: str,
|
||||
) -> dict[str, Any]:
|
||||
return await self._call(
|
||||
"workflow.admin.source_registry.inspect",
|
||||
{"source_id": source_id},
|
||||
)
|
||||
@@ -0,0 +1,64 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from fastapi import Body
|
||||
import fastapi_jsonrpc as jsonrpc
|
||||
from fastapi_jsonrpc import Params
|
||||
|
||||
from wf_server import WorkflowServer
|
||||
|
||||
from .errors import WorkflowRpcError, raise_workflow_rpc_error
|
||||
from .models import InspectRegistryEntryParams, ListRegistryEntriesParams
|
||||
|
||||
|
||||
def register_methods(
|
||||
entrypoint: jsonrpc.Entrypoint,
|
||||
server: WorkflowServer,
|
||||
) -> None:
|
||||
"""Register read-only desired source registry JSON-RPC methods."""
|
||||
|
||||
@entrypoint.method(
|
||||
name="workflow.admin.source_registry.list",
|
||||
errors=[WorkflowRpcError],
|
||||
)
|
||||
async def workflow_admin_source_registry_list(
|
||||
params: ListRegistryEntriesParams = Body(
|
||||
default_factory=ListRegistryEntriesParams,
|
||||
),
|
||||
) -> dict[str, Any]:
|
||||
if server.source_registry_admin is None:
|
||||
raise WorkflowRpcError(
|
||||
data={
|
||||
"code": "source_registry_unavailable",
|
||||
"message": "source registry admin reads are not available for this server",
|
||||
}
|
||||
)
|
||||
try:
|
||||
return await server.source_registry_admin.list_registry_entries(
|
||||
cursor=params.cursor,
|
||||
limit=params.limit,
|
||||
)
|
||||
except (ValueError, KeyError, LookupError, FileNotFoundError) as exc:
|
||||
raise_workflow_rpc_error(exc)
|
||||
|
||||
@entrypoint.method(
|
||||
name="workflow.admin.source_registry.inspect",
|
||||
errors=[WorkflowRpcError],
|
||||
)
|
||||
async def workflow_admin_source_registry_inspect(
|
||||
params: InspectRegistryEntryParams = Params(...), # type: ignore[reportArgumentType]
|
||||
) -> dict[str, Any]:
|
||||
if server.source_registry_admin is None:
|
||||
raise WorkflowRpcError(
|
||||
data={
|
||||
"code": "source_registry_unavailable",
|
||||
"message": "source registry admin reads are not available for this server",
|
||||
}
|
||||
)
|
||||
try:
|
||||
return await server.source_registry_admin.inspect_registry_entry(
|
||||
source_id=params.source_id,
|
||||
)
|
||||
except (ValueError, KeyError, LookupError, FileNotFoundError) as exc:
|
||||
raise_workflow_rpc_error(exc)
|
||||
@@ -179,3 +179,12 @@ class ResumeRunParams(RpcParamsModel):
|
||||
resume_payload: dict[str, Any] = Field(default_factory=dict)
|
||||
resume_outcome: str = Field(default="submitted", min_length=1)
|
||||
trace_range: TraceRangeParams | None = None
|
||||
|
||||
|
||||
class ListRegistryEntriesParams(RpcParamsModel):
|
||||
cursor: str | None = Field(default=None)
|
||||
limit: int = Field(default=50, ge=1, le=100)
|
||||
|
||||
|
||||
class InspectRegistryEntryParams(RpcParamsModel):
|
||||
source_id: str = Field(min_length=1)
|
||||
|
||||
Reference in New Issue
Block a user