feat(frontends,security,api,ui): a frontend can hold a token scope of its own

This commit is contained in:
hh committed 2026-09-06 23:26:26 +02:00
1 parent 60782d6276
commit e79e9fc149
11 files changed
+245 -21

No files matched your search

+16 -2
View File
@@ -35,7 +35,7 @@ from beaver_gateway.frontends.sse import (
)
from beaver_gateway.frontends.urls import frontend_url
from beaver_gateway.security import audit
from beaver_gateway.security.auth import VALID_SCOPES, hash_token
from beaver_gateway.security.auth import hash_token
from beaver_gateway.storage import (
create_token,
list_audit_records,
@@ -217,6 +217,7 @@ def build_app( # noqa: PLR0915
k: fe.agent_for(k) for k in fe.kinds if fe.agent_for(k)
},
"path": fe.path,
"scope": fe.scope,
"url": frontend_url(request, runtime, fe),
}
for fe in runtime.frontends
@@ -814,6 +815,19 @@ def build_app( # noqa: PLR0915
"content": content,
}
@app.get("/scopes")
async def scopes(request: Request) -> dict[str, Any]:
await require_token(request, runtime, scope=ADMIN_SCOPE)
by_frontend = {
fe.scope: fe.name or fe.path or "" for fe in runtime.frontends if fe.scope
}
return {
"scopes": [
{"scope": s, "frontend": by_frontend.get(s)}
for s in sorted(runtime.scopes)
]
}
@app.get("/tokens")
async def tokens(request: Request) -> dict[str, Any]:
await require_token(request, runtime, scope=ADMIN_SCOPE)
@@ -828,7 +842,7 @@ def build_app( # noqa: PLR0915
data = await body_of(request)
name = text_of(data, "name").strip()
scope = str(data.get("scope") or "*")
if scope not in VALID_SCOPES:
if scope not in runtime.scopes:
raise HTTPException(status.HTTP_400_BAD_REQUEST, f"invalid scope {scope!r}")
plaintext = secrets.token_urlsafe(32)
async with runtime.db.session() as session: