feat: add source registry mutations

This commit is contained in:
lda
2026-06-04 15:14:31 +07:00 Unverified
parent c0a885f050
commit 9ca81fedf2
15 changed files with 1689 additions and 80 deletions
@@ -4,7 +4,7 @@ from typing import Any
class RpcSourceRegistryClientMixin:
"""JSON-RPC implementation of read-only desired source registry surface methods."""
"""JSON-RPC implementation of source registry surface methods."""
async def _call(self, method: str, params: dict[str, Any]) -> dict[str, Any]: ...
@@ -28,3 +28,54 @@ class RpcSourceRegistryClientMixin:
"workflow.admin.source_registry.inspect",
{"source_id": source_id},
)
async def add_registry_entry(
self,
*,
entry: dict[str, Any],
) -> dict[str, Any]:
return await self._call(
"workflow.admin.source_registry.add",
{"entry": entry},
)
async def update_registry_entry(
self,
*,
source_id: str,
patch: dict[str, Any],
) -> dict[str, Any]:
return await self._call(
"workflow.admin.source_registry.update",
{"source_id": source_id, "patch": patch},
)
async def enable_registry_entry(
self,
*,
source_id: str,
) -> dict[str, Any]:
return await self._call(
"workflow.admin.source_registry.enable",
{"source_id": source_id},
)
async def disable_registry_entry(
self,
*,
source_id: str,
) -> dict[str, Any]:
return await self._call(
"workflow.admin.source_registry.disable",
{"source_id": source_id},
)
async def remove_registry_entry(
self,
*,
source_id: str,
) -> dict[str, Any]:
return await self._call(
"workflow.admin.source_registry.remove",
{"source_id": source_id},
)
@@ -9,14 +9,20 @@ from fastapi_jsonrpc import Params
from wf_server import WorkflowServer
from .errors import WorkflowRpcError, raise_workflow_rpc_error
from .models import InspectRegistryEntryParams, ListRegistryEntriesParams
from .models import (
AddRegistryEntryParams,
InspectRegistryEntryParams,
ListRegistryEntriesParams,
RegistryEntryIdParams,
UpdateRegistryEntryParams,
)
def register_methods(
entrypoint: jsonrpc.Entrypoint,
server: WorkflowServer,
) -> None:
"""Register read-only desired source registry JSON-RPC methods."""
"""Register source registry JSON-RPC methods."""
@entrypoint.method(
name="workflow.admin.source_registry.list",
@@ -62,3 +68,109 @@ def register_methods(
)
except (ValueError, KeyError, LookupError, FileNotFoundError) as exc:
raise_workflow_rpc_error(exc)
@entrypoint.method(
name="workflow.admin.source_registry.add",
errors=[WorkflowRpcError],
)
async def workflow_admin_source_registry_add(
params: AddRegistryEntryParams = 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 mutations are not available for this server",
}
)
try:
return await server.source_registry_admin.add_registry_entry(
entry=params.entry,
)
except (ValueError, KeyError, LookupError, FileNotFoundError) as exc:
raise_workflow_rpc_error(exc)
@entrypoint.method(
name="workflow.admin.source_registry.update",
errors=[WorkflowRpcError],
)
async def workflow_admin_source_registry_update(
params: UpdateRegistryEntryParams = 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 mutations are not available for this server",
}
)
try:
return await server.source_registry_admin.update_registry_entry(
source_id=params.source_id,
patch=params.patch,
)
except (ValueError, KeyError, LookupError, FileNotFoundError) as exc:
raise_workflow_rpc_error(exc)
@entrypoint.method(
name="workflow.admin.source_registry.enable",
errors=[WorkflowRpcError],
)
async def workflow_admin_source_registry_enable(
params: RegistryEntryIdParams = 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 mutations are not available for this server",
}
)
try:
return await server.source_registry_admin.enable_registry_entry(
source_id=params.source_id,
)
except (ValueError, KeyError, LookupError, FileNotFoundError) as exc:
raise_workflow_rpc_error(exc)
@entrypoint.method(
name="workflow.admin.source_registry.disable",
errors=[WorkflowRpcError],
)
async def workflow_admin_source_registry_disable(
params: RegistryEntryIdParams = 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 mutations are not available for this server",
}
)
try:
return await server.source_registry_admin.disable_registry_entry(
source_id=params.source_id,
)
except (ValueError, KeyError, LookupError, FileNotFoundError) as exc:
raise_workflow_rpc_error(exc)
@entrypoint.method(
name="workflow.admin.source_registry.remove",
errors=[WorkflowRpcError],
)
async def workflow_admin_source_registry_remove(
params: RegistryEntryIdParams = 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 mutations are not available for this server",
}
)
try:
return await server.source_registry_admin.remove_registry_entry(
source_id=params.source_id,
)
except (ValueError, KeyError, LookupError, FileNotFoundError) as exc:
raise_workflow_rpc_error(exc)
+13
View File
@@ -188,3 +188,16 @@ class ListRegistryEntriesParams(RpcParamsModel):
class InspectRegistryEntryParams(RpcParamsModel):
source_id: str = Field(min_length=1)
class AddRegistryEntryParams(RpcParamsModel):
entry: dict[str, Any]
class UpdateRegistryEntryParams(RpcParamsModel):
source_id: str = Field(min_length=1)
patch: dict[str, Any]
class RegistryEntryIdParams(RpcParamsModel):
source_id: str = Field(min_length=1)