Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- app/main.py +1 -1
- app/routes/predict.py +6 -2
app/main.py
CHANGED
|
@@ -52,7 +52,7 @@ entraîné sur des données RH pour prédire la probabilité qu'un employé quit
|
|
| 52 |
### Authentification
|
| 53 |
Toutes les routes protégées nécessitent un header `X-API-Key`.
|
| 54 |
""",
|
| 55 |
-
version="1.
|
| 56 |
lifespan=lifespan,
|
| 57 |
)
|
| 58 |
|
|
|
|
| 52 |
### Authentification
|
| 53 |
Toutes les routes protégées nécessitent un header `X-API-Key`.
|
| 54 |
""",
|
| 55 |
+
version="1.1.0",
|
| 56 |
lifespan=lifespan,
|
| 57 |
)
|
| 58 |
|
app/routes/predict.py
CHANGED
|
@@ -6,6 +6,8 @@ from app.schemas.prediction import PredictionInput, PredictionOutput
|
|
| 6 |
from sqlalchemy.orm import Session
|
| 7 |
from app.db.session import get_db
|
| 8 |
from app.db import crud
|
|
|
|
|
|
|
| 9 |
|
| 10 |
router = APIRouter()
|
| 11 |
|
|
@@ -13,9 +15,11 @@ api_key_header = APIKeyHeader(name="X-API-Key", auto_error=False)
|
|
| 13 |
|
| 14 |
|
| 15 |
async def verify_api_key(request: Request, api_key: str = Security(api_key_header)):
|
| 16 |
-
if not api_key
|
|
|
|
|
|
|
|
|
|
| 17 |
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Clé API manquante ou invalide")
|
| 18 |
-
|
| 19 |
|
| 20 |
@router.get("/", tags=["Général"], summary="Accueil de l'API", description="Retourne les informations générales de l'API.")
|
| 21 |
def root(request: Request):
|
|
|
|
| 6 |
from sqlalchemy.orm import Session
|
| 7 |
from app.db.session import get_db
|
| 8 |
from app.db import crud
|
| 9 |
+
import hashlib
|
| 10 |
+
import hmac
|
| 11 |
|
| 12 |
router = APIRouter()
|
| 13 |
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
async def verify_api_key(request: Request, api_key: str = Security(api_key_header)):
|
| 18 |
+
if not api_key:
|
| 19 |
+
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Clé API manquante ou invalide")
|
| 20 |
+
hashed = hashlib.sha256(api_key.encode()).hexdigest()
|
| 21 |
+
if not hmac.compare_digest(hashed, request.app.state.settings.api_key):
|
| 22 |
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Clé API manquante ou invalide")
|
|
|
|
| 23 |
|
| 24 |
@router.get("/", tags=["Général"], summary="Accueil de l'API", description="Retourne les informations générales de l'API.")
|
| 25 |
def root(request: Request):
|