DELETE /artifacts/{digest}: superuser only, 409 while referenced

The keep-set the hourly sweep uses is now referenced_artifacts, shared by
the sweep and the route. The volatile ring is not touched.
This commit is contained in:
2026-10-15 10:48:59 +02:00
parent 599e01b0bf
commit 7ea53ccf17
7 changed files with 144 additions and 15 deletions
+38 -2
View File
@@ -10,17 +10,23 @@ import tempfile
from pathlib import Path
from typing import Any
from fastapi import APIRouter, Depends, HTTPException, Query, Request
from fastapi import APIRouter, Depends, HTTPException, Query, Request, Response
from fastapi.responses import FileResponse
from jwt.exceptions import InvalidTokenError
from pydantic import BaseModel
from sqlmodel import Session
from starlette.concurrency import run_in_threadpool
from fluksio.api.deps import user_from_token, worker_claims
from fluksio.api.deps import (
FlowControllerDep,
get_current_active_superuser,
user_from_token,
worker_claims,
)
from fluksio.core.config import settings
from fluksio.core.db import engine
from fluksio.flow.artifacts import ArtifactStore
from fluksio.flow.runs import referenced_artifacts
#: What may be echoed back as a response content type. The caller holds the
#: reference and passes its media type, so this guards a header rather than
@@ -153,3 +159,33 @@ def get_artifact(
headers["Content-Security-Policy"] = "sandbox"
headers["X-Content-Type-Options"] = "nosniff"
return FileResponse(path, media_type=media_type, headers=headers)
@router.delete(
"/{digest}",
status_code=204,
dependencies=[Depends(get_current_active_superuser)],
)
def delete_artifact(
digest: str, request: Request, controller: FlowControllerDep
) -> Response:
"""Remove one artifact's bytes from the store.
A superuser's call, because the store records no uploader and identical
content from two callers is one file, so nobody else can be said to own
it. Refused while anything still names the digest, the same references the
hourly sweep keeps, so a reference that exists never answers 404. The
volatile ring is left alone: its frames fall out on their own.
"""
store = _store(request)
if digest in referenced_artifacts(controller.state, controller.store):
raise HTTPException(
status_code=409,
detail=(
"The artifact is still referenced by a run, a current message or "
"a flow input's initial value"
),
)
if not store.delete(digest):
raise HTTPException(status_code=404, detail="No such artifact")
return Response(status_code=204)