Convert web service from FastAPI to Django 6.1
Replace the FastAPI/SQLAlchemy/Alembic web service with a Django project
laid out like cumorah-build: manage.py at the root, settings in the
privatestudio.settings package (base/dev/production), and a
privatestudio.studio app.
- Studio model owns a unique bucket_name; access is granted through
membership in the studio's auth Group. Assets, profiles and jobs are
scoped to a studio; API keys and S3 credentials stay per user.
- JSON API via Django Ninja under /api/ (profiles and transcode jobs now
live under /api/studios/{bucket}/).
- S3-compatible interface as plain class-based views under /s3/,
supporting bearer tokens and AWS v4 signatures.
- create_studio and create_key management commands replace ps-serve.
- Fresh Django initial migration; tests ported to Django TestCase.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
46adddd50a
commit
b3b51f6cc5
@@ -0,0 +1,51 @@
|
||||
"""API key management endpoints."""
|
||||
from django.shortcuts import get_object_or_404
|
||||
from ninja import Router, Schema
|
||||
from ninja.errors import HttpError
|
||||
|
||||
from privatestudio.studio.auth import create_api_key, revoke_api_key
|
||||
from privatestudio.studio.models import APIKey
|
||||
|
||||
router = Router()
|
||||
|
||||
|
||||
class APIKeyCreateResponse(Schema):
|
||||
id: int
|
||||
key: str
|
||||
created_at: str
|
||||
|
||||
|
||||
class APIKeyListItem(Schema):
|
||||
id: int
|
||||
created_at: str
|
||||
is_active: bool
|
||||
|
||||
|
||||
class MessageResponse(Schema):
|
||||
message: str
|
||||
|
||||
|
||||
@router.post("/keys", response=APIKeyCreateResponse)
|
||||
def create_api_key_endpoint(request):
|
||||
"""Create a new API key for the authenticated user."""
|
||||
plain_key, api_key = create_api_key(request.auth)
|
||||
return {"id": api_key.id, "key": plain_key, "created_at": api_key.created_at.isoformat()}
|
||||
|
||||
|
||||
@router.get("/keys", response=list[APIKeyListItem])
|
||||
def list_api_keys(request):
|
||||
"""List all API keys for the authenticated user."""
|
||||
return [
|
||||
{"id": key.id, "created_at": key.created_at.isoformat(), "is_active": key.is_active}
|
||||
for key in APIKey.objects.filter(user=request.auth).order_by("id")
|
||||
]
|
||||
|
||||
|
||||
@router.delete("/keys/{key_id}", response=MessageResponse)
|
||||
def revoke_api_key_endpoint(request, key_id: int):
|
||||
"""Revoke an API key (mark it as inactive)."""
|
||||
api_key = get_object_or_404(APIKey, pk=key_id)
|
||||
if api_key.user_id != request.auth.id:
|
||||
raise HttpError(403, "Cannot revoke someone else's API key")
|
||||
revoke_api_key(api_key)
|
||||
return {"message": "API key revoked"}
|
||||
Reference in New Issue
Block a user