Skip to content

Commit

Permalink
Update app.py
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinebou12 authored Mar 2, 2024
1 parent 8eaf93b commit 1a0d001
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from fastapi.security import HTTPBasic, HTTPBasicCredentials
import hashlib
from cachetools import LRUCache
from cachetools.sync import RLock
import os

import asyncio
Expand Down Expand Up @@ -693,7 +696,7 @@ class APIResponse(BaseModel):
data: Optional[dict] = None


user_instances_cache = {}
user_instances_cache = LRUCache(maxsize=100, lock=RLock())

async def get_user_hash(credentials: HTTPBasicCredentials):
"""
Expand All @@ -719,7 +722,7 @@ async def get_current_user(credentials: HTTPBasicCredentials = Depends(security)
# Store the authenticated user instance in the cache
user_instances_cache[user_hash] = user
except Exception as e:
__LOGGER.error(f"Authentication failed: {e}")
print(f"Authentication failed: {e}") # Adjust the logging mechanism as needed
raise HTTPException(status_code=401, detail="Authentication failed")

return user
Expand Down

0 comments on commit 1a0d001

Please sign in to comment.