llmproxy/backend/setup_admin.py
Oliver Hofmann c8235ec274 Refactor to flat APIKey model with quota, admin UI, .env config, and Berlin timezone
- Remove User/Quota models; quota fields now live directly on APIKey
- Admin UI: login, API key management, settings (Ollama URL/model), proxy info display
- .env/.env.example: ADMIN_PASSWORD, PROXY_HOST/PORT, DATABASE_URL, APP_TZ
- Admin API runs on 127.0.0.1 only; proxy host/port configurable
- API keys support optional expires_at; verified against Europe/Berlin timezone
- Daily/monthly quota resets use Europe/Berlin midnight boundary
- Fix all tests to use new flat model; add expiry tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-28 08:21:42 +02:00

25 lines
707 B
Python

#!/usr/bin/env python3
from database import Base, engine, SessionLocal
from models import APIKey
from crud import create_api_key
def setup_admin():
Base.metadata.create_all(bind=engine)
db = SessionLocal()
existing = db.query(APIKey).filter(APIKey.name == "default").first()
if not existing:
_, raw_key = create_api_key(
db,
name="default",
daily_tokens=1_000_000,
monthly_tokens=10_000_000,
daily_requests=1000,
monthly_requests=10000,
)
print(f"API Key created: {raw_key}")
else:
print("Default API key already exists")
db.close()
if __name__ == "__main__":
setup_admin()