Files
hub-core/hub_core/routers/policy.py
tegwick 986ac4d40b Add hub-core package, docs, and State Hub integration scaffold
Extract the first reusable slice (models, schemas, routers, MCP, migrations)
from state-hub with INTENT/SCOPE, agent instructions, workplan, and aligned
inter_hub capability registry index.
2026-06-16 02:39:36 +02:00

31 lines
931 B
Python

from collections.abc import Callable
from fastapi import APIRouter, HTTPException
from hub_core.schemas.policy import PolicyRead, PolicyUpdate
PolicyLoader = Callable[[str], PolicyRead | None]
PolicyUpdater = Callable[[str, str], PolicyRead]
def create_policy_router(
load_policy: PolicyLoader,
update_policy: PolicyUpdater | None = None,
) -> APIRouter:
router = APIRouter(prefix="/policy", tags=["policy"])
@router.get("/{name}", response_model=PolicyRead)
def get_policy(name: str) -> PolicyRead:
policy = load_policy(name)
if policy is None:
raise HTTPException(status_code=404, detail=f"Policy '{name}' not found")
return policy
if update_policy is not None:
@router.put("/{name}", response_model=PolicyRead)
def put_policy(name: str, body: PolicyUpdate) -> PolicyRead:
return update_policy(name, body.content)
return router