Files
privatestudio/privatestudio/studio/management/commands/create_key.py
T
Shaun KrugerandClaude Opus 5.5 b3b51f6cc5 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>
2026-11-29 21:54:16 -07:00

24 lines
965 B
Python

from django.contrib.auth import get_user_model
from django.core.management.base import BaseCommand, CommandError
from privatestudio.studio.auth import create_api_key
class Command(BaseCommand):
help = "Create an API key for a user. The key is printed once and cannot be recovered."
def add_arguments(self, parser):
parser.add_argument("username", help="Username to create the key for")
def handle(self, *args, **options):
User = get_user_model()
try:
user = User.objects.get_by_natural_key(options["username"])
except User.DoesNotExist:
raise CommandError(f"User '{options['username']}' not found")
plain_key, api_key = create_api_key(user)
self.stdout.write(self.style.SUCCESS(f"API key {api_key.id} created for user {user.get_username()}"))
self.stdout.write(f"Key: {plain_key}")
self.stdout.write("Keep this key safe - you won't be able to see it again!")