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>
84 lines
2.8 KiB
Markdown
84 lines
2.8 KiB
Markdown
# Running and Managing Private Studio
|
|
|
|
Private Studio is a standard Django project. All administration goes through `manage.py`, which uses `privatestudio.settings.dev` unless `DJANGO_SETTINGS_MODULE` is set.
|
|
|
|
## Setup
|
|
|
|
```bash
|
|
python3 -m venv venv
|
|
source venv/bin/activate
|
|
pip install -e ".[dev]"
|
|
python manage.py migrate
|
|
```
|
|
|
|
## Access Model
|
|
|
|
- **Users** are standard `django.contrib.auth` users.
|
|
- **Studios** each own one unique `bucket_name` and point to one Django **Group**.
|
|
- A user can access a studio (its S3 bucket, profiles and jobs) when they are in that studio's group. Superusers can access every studio.
|
|
- **API keys** belong to a user and authenticate as that user. Only a SHA256 hash of each key is stored.
|
|
|
|
## Commands
|
|
|
|
### Create users
|
|
|
|
```bash
|
|
python manage.py createsuperuser # admin user
|
|
python manage.py shell -c "from django.contrib.auth.models import User; User.objects.create_user('alice')"
|
|
```
|
|
|
|
You can also create users in the admin at `/admin/`.
|
|
|
|
### create_studio
|
|
|
|
```bash
|
|
python manage.py create_studio <bucket_name> --group <group> [--name "Display Name"] [--add-user USER ...]
|
|
```
|
|
|
|
This creates the group if it doesn't exist, adds the given users to it, and creates the studio. Bucket names must be lowercase letters, digits and hyphens.
|
|
|
|
### create_key
|
|
|
|
```bash
|
|
python manage.py create_key <username>
|
|
```
|
|
|
|
This prints a new API key. The key is shown only once. Users can also create and revoke their own keys through `/api/keys`.
|
|
|
|
### Run the server
|
|
|
|
```bash
|
|
python manage.py runserver 0.0.0.0:8000
|
|
```
|
|
|
|
In production, set `DJANGO_SETTINGS_MODULE=privatestudio.settings.production` and serve `privatestudio.wsgi:application` or `privatestudio.asgi:application` with your WSGI/ASGI server of choice. See the configuration table in [README.md](README.md).
|
|
|
|
## Typical Workflow
|
|
|
|
```bash
|
|
python manage.py migrate
|
|
python manage.py createsuperuser --username admin
|
|
python manage.py shell -c "from django.contrib.auth.models import User; User.objects.create_user('alice')"
|
|
python manage.py create_studio demo --name "Demo Studio" --group demo-team --add-user alice
|
|
python manage.py create_key alice
|
|
python manage.py runserver
|
|
|
|
curl -H "Authorization: Bearer $KEY" http://localhost:8000/api/userinfo
|
|
curl -X PUT -H "Authorization: Bearer $KEY" --data-binary @video.mp4 http://localhost:8000/s3/demo/video.mp4
|
|
curl -H "Authorization: Bearer $KEY" http://localhost:8000/s3/demo
|
|
```
|
|
|
|
## Tests
|
|
|
|
```bash
|
|
pytest # all tests
|
|
pytest privatestudio/studio/tests/test_s3.py -k signature
|
|
pytest --cov=privatestudio
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
- **401 Unauthorized**: the API key is wrong or revoked, or the S3 credentials have expired (by default they last 1 hour, set by `S3_CREDENTIAL_TTL_HOURS`).
|
|
- **403 on a bucket**: the user isn't in the studio's group. Add them in the admin.
|
|
- **404 on a bucket**: no studio has that `bucket_name`.
|