generated from coulomb/repo-seed
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.
This commit is contained in:
30
hub_core/routers/policy.py
Normal file
30
hub_core/routers/policy.py
Normal file
@@ -0,0 +1,30 @@
|
||||
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
|
||||
Reference in New Issue
Block a user