Download app/api/deps.py from GodRad/rag_saas: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/spaces/GodRad/rag_saas/resolve/main/app/api/deps.py
- Command line
-
hf download hf://spaces/GodRad/rag_saas/app/api/deps.py
-
curl -L -o deps.py https://huggingface.co/spaces/GodRad/rag_saas/resolve/main/app/api/deps.py
1.2 kB
| from typing import Generator, Optional | |
| from fastapi import Depends, HTTPException, status, Header | |
| from sqlalchemy.orm import Session | |
| from app.core.config import settings | |
| from app.models.orm import TenantModel | |
| from app.models.database import get_db | |
| def get_tenant_id( | |
| x_tenant_id: Optional[str] = Header(None), | |
| db: Session = Depends(get_db) | |
| ) -> str: | |
| # Use provided ID or fallback to 'default' | |
| requested_id = x_tenant_id or "default" | |
| tenant = db.query(TenantModel).filter(TenantModel.id == requested_id).first() | |
| if not tenant: | |
| if requested_id == "default": | |
| # Auto-create default tenant if it doesn't exist | |
| tenant = TenantModel(id="default", name="Default Tenant", config={}) | |
| db.add(tenant) | |
| db.commit() | |
| db.refresh(tenant) | |
| else: | |
| raise HTTPException( | |
| status_code=status.HTTP_404_NOT_FOUND, | |
| detail=f"Tenant '{requested_id}' not found. Please create it first.", | |
| ) | |
| return requested_id | |
| def get_current_user_tenant( | |
| tenant_id: str = Depends(get_tenant_id) | |
| ) -> str: | |
| return tenant_id | |