Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /InferiaAI_InferiaLLM /src /api_gateway /audit /router.py
| from fastapi import APIRouter, Depends, Query, HTTPException, status, Security | |
| from fastapi.security import APIKeyHeader | |
| from sqlalchemy.ext.asyncio import AsyncSession | |
| from typing import List, Optional | |
| from datetime import datetime | |
| from api_gateway.db.database import get_db | |
| from api_gateway.audit.service import audit_service | |
| from api_gateway.config import settings | |
| from api_gateway.models import ( | |
| AuditLogResponse, | |
| AuditLogFilter, | |
| AuditLogCreate, | |
| PermissionEnum, | |
| ) | |
| from api_gateway.rbac.middleware import get_current_user_from_request | |
| from api_gateway.rbac.authorization import authz_service | |
| router = APIRouter(prefix="/audit", tags=["Audit"]) | |
| async def get_audit_logs( | |
| user_id: Optional[str] = None, | |
| action: Optional[str] = None, | |
| category: Optional[str] = None, | |
| start_date: Optional[datetime] = None, | |
| end_date: Optional[datetime] = None, | |
| limit: int = Query(100, le=1000), | |
| skip: int = 0, | |
| db: AsyncSession = Depends(get_db), | |
| user_ctx=Depends(get_current_user_from_request), | |
| ): | |
| """ | |
| Retrieve audit logs. Supports filtering by category (auth, deployment, etc.) | |
| """ | |
| authz_service.require_permission(user_ctx, PermissionEnum.AUDIT_LOG_LIST) | |
| filters = AuditLogFilter( | |
| user_id=user_id, | |
| action=action, | |
| category=category, | |
| start_date=start_date, | |
| end_date=end_date, | |
| limit=limit, | |
| skip=skip, | |
| org_id=user_ctx.org_id, | |
| ) | |
| logs = await audit_service.get_logs(db, filters) | |
| return logs | |
| # Internal endpoint for testing or manual logging if needed | |
| async def create_internal_log( | |
| log_data: AuditLogCreate, | |
| db: AsyncSession = Depends(get_db), | |
| api_key: str = Security(APIKeyHeader(name="X-Internal-API-Key")), | |
| ): | |
| """ | |
| Manually create an audit log (Internal Only). | |
| """ | |
| expected_key = settings.internal_api_key | |
| if not expected_key: | |
| raise HTTPException( | |
| status_code=status.HTTP_503_SERVICE_UNAVAILABLE, | |
| detail="Internal API key not configured" | |
| ) | |
| if api_key != expected_key: | |
| raise HTTPException( | |
| status_code=status.HTTP_403_FORBIDDEN, | |
| detail="Invalid Internal API Key" | |
| ) | |
| return await audit_service.log_event_sync(db, log_data) | |
Xet Storage Details
- Size:
- 2.4 kB
- Xet hash:
- a1024dea63b79d78612ded80c60826e59df3359dd5244378d9b8ba7c0b84d354
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.