Spaces:
Sleeping
Sleeping
Caner Giden commited on
Commit ·
5c6567b
1
Parent(s): 9be7131
Add: GET /admin/api-key endpoint to display seeded API key in UI
Browse files99 unmodified lines10010110299 unmodified linescreated_at=current_user.created_at.isoformat() + "Z")99 unmodified lines10010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515699 unmodified linescreated_at=current_user.created_at.isoformat() + "Z")@router.get("/admin/api-key")def get_admin_api_key():"""Get the seeded admin API key from file.This endpoint is only for initial setup. The API key is written toadmin_api_key.txt during seed. This endpoint reads and returns it."""import osfrom pathlib import Path# Try to read from project root firstkey_file_path = Path("admin_api_key.txt")if not key_file_path.exists():# Try /tmp as fallbackkey_file_path = Path("/tmp/admin_api_key.txt")if not key_file_path.exists():raise HTTPException(status_code=404,detail="Admin API key file not found. Seed may not have run yet.")try:with open(key_file_path, "r") as f:content = f.read().strip()lines = content.split("\n")api_key = Noneemail = Nonefor line in lines:if line.startswith("API Key:"):api_key = line.replace("API Key:", "").strip()elif line.startswith("Email:"):email = line.replace("Email:", "").strip()if not api_key:raise HTTPException(status_code=500,detail="API key not found in file")return {"email": email or "admin@forgeflow.local","api_key": api_key,"message": "⚠️ IMPORTANT: Copy this API key. It will not be shown again after you use it!"}except Exception as e:raise HTTPException(status_code=500,detail=f"Error reading API key file: {str(e)}")
app/api/auth.py+54