Publish curated ITWorx_MCP_Hub source from 6c7434368ce2a594005983c5a6601a31a639e7f1
This commit is contained in:
1 parent
77946d62c4
commit
6d40ab975c
86 files changed
+6784
-1478
No files matched your search
@@ -9,7 +9,13 @@ from uuid import UUID
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
from packages.hub_clients import BootstrapHandle, ClientConfig, ClientKind, ClientRecord
|
||||
from packages.hub_clients import (
|
||||
BootstrapHandle,
|
||||
ClientConfig,
|
||||
ClientKind,
|
||||
ClientRecord,
|
||||
ClientStatus,
|
||||
)
|
||||
|
||||
from .service import ClientService
|
||||
|
||||
@@ -50,6 +56,9 @@ def build_client_router(
|
||||
*,
|
||||
authenticate: Callable[[Request], Any] = _deny_by_default,
|
||||
authorize: Callable[[Any, str], None] = _deny_all_actions,
|
||||
onboarding_status: Callable[[UUID], dict[str, Any]] | None = None,
|
||||
verify_onboarding: Callable[[UUID, Any], dict[str, Any]] | None = None,
|
||||
transition_client: Callable[[UUID, ClientStatus, Any], ClientRecord] | None = None,
|
||||
prefix: str = "/clients",
|
||||
token_endpoint: str = "https://auth.example.invalid/application/o/token/", # noqa: S107
|
||||
oauth_client_id: str = "itworx-mcp-hub",
|
||||
@@ -112,6 +121,28 @@ def build_client_router(
|
||||
except KeyError as exc:
|
||||
raise HTTPException(status_code=404, detail="client not found") from exc
|
||||
|
||||
@router.get("/{client_id}/onboarding-status")
|
||||
def onboarding(client_id: UUID, principal: Any = authenticated) -> dict[str, Any]:
|
||||
authorize(principal, "client.read")
|
||||
if onboarding_status is None:
|
||||
raise HTTPException(status_code=404, detail="client onboarding status is unavailable")
|
||||
try:
|
||||
return onboarding_status(client_id)
|
||||
except KeyError as exc:
|
||||
raise HTTPException(status_code=404, detail="onboarding client not found") from exc
|
||||
|
||||
@router.post("/{client_id}/verify")
|
||||
def verify(client_id: UUID, principal: Any = authenticated) -> dict[str, Any]:
|
||||
authorize(principal, "client.verify")
|
||||
if verify_onboarding is None:
|
||||
raise HTTPException(
|
||||
status_code=404, detail="client onboarding verification is unavailable"
|
||||
)
|
||||
try:
|
||||
return verify_onboarding(client_id, principal)
|
||||
except KeyError as exc:
|
||||
raise HTTPException(status_code=404, detail="onboarding client not found") from exc
|
||||
|
||||
@router.post("/{client_id}/bootstrap", response_model=BootstrapHandle)
|
||||
def bootstrap(client_id: UUID, principal: Any = authenticated) -> BootstrapHandle:
|
||||
authorize(principal, "client.bootstrap")
|
||||
@@ -126,15 +157,25 @@ def build_client_router(
|
||||
def disable(client_id: UUID, principal: Any = authenticated) -> ClientRecord:
|
||||
authorize(principal, "client.disable")
|
||||
try:
|
||||
return service.disable(client_id)
|
||||
return (
|
||||
transition_client(client_id, ClientStatus.DISABLED, principal)
|
||||
if transition_client is not None
|
||||
else service.disable(client_id)
|
||||
)
|
||||
except KeyError as exc:
|
||||
raise HTTPException(status_code=404, detail="client not found") from exc
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=409, detail=str(exc)) from exc
|
||||
|
||||
@router.post("/{client_id}/revoke", response_model=ClientRecord)
|
||||
def revoke(client_id: UUID, principal: Any = authenticated) -> ClientRecord:
|
||||
authorize(principal, "client.revoke")
|
||||
try:
|
||||
return service.revoke(client_id)
|
||||
return (
|
||||
transition_client(client_id, ClientStatus.REVOKED, principal)
|
||||
if transition_client is not None
|
||||
else service.revoke(client_id)
|
||||
)
|
||||
except KeyError as exc:
|
||||
raise HTTPException(status_code=404, detail="client not found") from exc
|
||||
|
||||
|
||||
Reference in new issue
Block a user