- Add FastAPI app with CORS and auth middleware (Bearer token) - Add POST /api/v1/transactions/upload endpoint (multipart/form-data) - Add MinIO storage service with date-partitioned object keys - Add PostgreSQL database service for transaction metadata - Add Dockerfile and docker-compose.yml for deployment - Add config.example.yaml template Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
from fastapi import Request
|
|
from fastapi.responses import JSONResponse
|
|
from starlette.middleware.base import BaseHTTPMiddleware
|
|
|
|
from app.config import settings
|
|
|
|
|
|
class AuthMiddleware(BaseHTTPMiddleware):
|
|
async def dispatch(self, request: Request, call_next):
|
|
if not request.url.path.startswith("/api/v1"):
|
|
return await call_next(request)
|
|
|
|
token = settings.api.token
|
|
if not token:
|
|
return JSONResponse(
|
|
status_code=500,
|
|
content={"success": False, "error": "Server configuration error"},
|
|
)
|
|
|
|
auth_header = request.headers.get("Authorization")
|
|
if not auth_header or not auth_header.startswith("Bearer "):
|
|
return JSONResponse(
|
|
status_code=401,
|
|
content={"success": False, "error": "Missing authentication token"},
|
|
)
|
|
|
|
if auth_header.removeprefix("Bearer ") != token:
|
|
return JSONResponse(
|
|
status_code=403,
|
|
content={"success": False, "error": "Invalid authentication token"},
|
|
)
|
|
|
|
return await call_next(request)
|