Spaces:
Build error
Build error
Hkoradiya123
feat: Initialize frontend with Zustand for state management, Tailwind CSS for styling, and TypeScript for type safety
4854e2b Download backend/app/api/api_key_routes.py from jinksQspider/fmproService: direct link, hf CLI and curl.
- Browser
- Download file 2.65 kB
-
https://huggingface.co/spaces/jinksQspider/fmproService/resolve/main/backend/app/api/api_key_routes.py
- Command line
-
hf download hf://spaces/jinksQspider/fmproService/backend/app/api/api_key_routes.py
-
curl -L -o api_key_routes.py https://huggingface.co/spaces/jinksQspider/fmproService/resolve/main/backend/app/api/api_key_routes.py
2.65 kB
| """User API key management routes""" | |
| from uuid import UUID | |
| from fastapi import APIRouter, Depends, HTTPException, status, Request | |
| from sqlalchemy.orm import Session | |
| from app.core.database import get_db | |
| from app.core.security import get_current_tenant_id, get_current_user_id | |
| from app.core.rate_limit import limiter, RATE_LIMIT_VALUE | |
| from app.schemas import APIKeyCreateRequest, APIKeyCreateResponse, APIKeyResponse | |
| from app.services.api_key_service import APIKeyService | |
| router = APIRouter(prefix="/api/keys", tags=["api-keys"]) | |
| async def create_api_key( | |
| request: Request, | |
| payload: APIKeyCreateRequest, | |
| user_id: str = Depends(get_current_user_id), | |
| tenant_id: str = Depends(get_current_tenant_id), | |
| db: Session = Depends(get_db), | |
| ): | |
| try: | |
| api_key, plain_key = APIKeyService.create_api_key( | |
| db=db, | |
| tenant_id=UUID(tenant_id), | |
| key_name=payload.key_name, | |
| user_id=UUID(user_id), | |
| ) | |
| return APIKeyCreateResponse( | |
| id=api_key.id, | |
| key_name=api_key.key_name, | |
| is_active=api_key.is_active, | |
| created_at=api_key.created_at, | |
| last_used_at=api_key.last_used_at, | |
| api_key=plain_key, | |
| ) | |
| except Exception as exc: | |
| raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(exc)) | |
| async def list_api_keys( | |
| request: Request, | |
| user_id: str = Depends(get_current_user_id), | |
| tenant_id: str = Depends(get_current_tenant_id), | |
| db: Session = Depends(get_db), | |
| ): | |
| try: | |
| keys = APIKeyService.list_user_api_keys(db, UUID(tenant_id), UUID(user_id)) | |
| return keys | |
| except Exception as exc: | |
| raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(exc)) | |
| async def revoke_api_key( | |
| request: Request, | |
| api_key_id: str, | |
| user_id: str = Depends(get_current_user_id), | |
| tenant_id: str = Depends(get_current_tenant_id), | |
| db: Session = Depends(get_db), | |
| ): | |
| try: | |
| revoked = APIKeyService.deactivate_user_api_key(db, UUID(tenant_id), UUID(user_id), UUID(api_key_id)) | |
| return revoked | |
| except ValueError as exc: | |
| raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(exc)) | |
| except Exception as exc: | |
| raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(exc)) | |