Spaces:
Sleeping
Sleeping
Caner Giden commited on
Commit ·
bf0f173
1
Parent(s): 35d03a1
Fix: Use lifespan instead of deprecated on_event, reduce API key length for bcrypt
Browse files123456740 unmodified lines4849505051515253545522 unmodified lines7879808182838485868788899091921 unmodified line94959697989910010 unmodified lines111112113103104105106107114115116import sysimport secretsimport loggingfrom contextlib import asynccontextmanagerfrom pathlib import Path
# Add the project root to Python path40 unmodified lines db.add(admin_user) db.flush() # Get the user ID # Generate API key api_key_plain = f"ff_{secrets.token_urlsafe(32)}" # Generate API key (24 chars random + prefix = ~30 chars, well under 72 byte limit) api_key_plain = f"ff_{secrets.token_urlsafe(24)}" api_key_hash = hash_api_key(api_key_plain) # Create API key22 unmodified lines db.close()
@asynccontextmanagerasync def lifespan(app: FastAPI): """Lifespan context manager for startup and shutdown events.""" # Startup seed_admin_user() yield # Shutdown (if needed in future)
def create_app() -> FastAPI: app = FastAPI( title=settings.APP_NAME,1 unmodified line docs_url="/", redoc_url=None, openapi_url="/openapi.json", lifespan=lifespan, )
origins = ["*"] if settings.CORS_ORIGINS == "*" else [o.strip() for o in settings.CORS_ORIGINS.split(",")]10 unmodified lines app.include_router(health_router) app.include_router(auth_router) app.include_router(flows_router) # Seed admin user on startup @app.on_event("startup") async def startup_event(): seed_admin_user()
return app
main.py+13-7