Flows and dashboards are created by POST under an issued or superuser-pinned id; PUT only updates; deleted flows leave a tombstone with their key; the controller stores by id and runs by key, hooks live under /hooks/<flow id>; a key with state or queued work behind it is refused until cleared
This commit is contained in:
@@ -4,7 +4,7 @@ from typing import Annotated, Any
|
||||
from urllib.parse import unquote
|
||||
|
||||
import jwt
|
||||
from fastapi import Depends, HTTPException, Request, status
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
||||
from fastapi.security import OAuth2PasswordBearer
|
||||
from jwt.exceptions import InvalidTokenError
|
||||
from pydantic import ValidationError
|
||||
@@ -615,3 +615,33 @@ def get_code_author(current_user: CurrentUser) -> User:
|
||||
if not current_user.is_superuser:
|
||||
raise HTTPException(status_code=403, detail=CODE_IS_SUPERUSERS)
|
||||
return current_user
|
||||
|
||||
|
||||
def check_pin(pin: str, user: User, *routers: APIRouter) -> None:
|
||||
"""Refuse a pinned id from anyone but a superuser, or one a route shadows.
|
||||
|
||||
Creating a flow or a dashboard gives it an opaque id. A pinned one is how
|
||||
the Demo, a test or a restore keeps the id it already knows. *routers* are
|
||||
the ones serving that kind's paths: a pin equal to one of their literal
|
||||
segments, such as ``graph``, would be unreachable behind that route.
|
||||
"""
|
||||
if not pin:
|
||||
return
|
||||
if not user.is_superuser:
|
||||
raise HTTPException(status_code=403, detail="Only a superuser can choose an id")
|
||||
shadowed = {
|
||||
segment
|
||||
for router in routers
|
||||
for route in router.routes
|
||||
if "{"
|
||||
not in (
|
||||
segment := getattr(route, "path", "")[len(router.prefix) :]
|
||||
.strip("/")
|
||||
.split("/")[0]
|
||||
)
|
||||
}
|
||||
if pin in shadowed:
|
||||
raise HTTPException(
|
||||
status_code=422,
|
||||
detail=f"'{pin}' is a path of the API, so it cannot be an id",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user