Spaces:
Running
Running
add type hints
Browse files- src/main.py +3 -3
src/main.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import logging
|
| 3 |
import secrets
|
| 4 |
-
from typing import Generator, Optional, Annotated, List, Dict
|
| 5 |
from datetime import datetime
|
| 6 |
from contextlib import asynccontextmanager
|
| 7 |
from fastapi import (
|
|
@@ -69,7 +69,7 @@ if os.getenv("REDIS_URL"):
|
|
| 69 |
TENNIS_ML_API = os.getenv("TENNIS_ML_API")
|
| 70 |
|
| 71 |
@asynccontextmanager
|
| 72 |
-
async def lifespan(app: FastAPI):
|
| 73 |
if not TENNIS_ML_API:
|
| 74 |
yield
|
| 75 |
return
|
|
@@ -105,7 +105,7 @@ safe_clients = ['127.0.0.1']
|
|
| 105 |
|
| 106 |
api_key_header = APIKeyHeader(name='Authorization', auto_error=False)
|
| 107 |
|
| 108 |
-
async def validate_api_key(request: Request, key: str = Security(api_key_header)):
|
| 109 |
'''
|
| 110 |
Check if the API key is valid
|
| 111 |
|
|
|
|
| 1 |
import os
|
| 2 |
import logging
|
| 3 |
import secrets
|
| 4 |
+
from typing import Generator, Optional, Annotated, List, Dict, AsyncGenerator
|
| 5 |
from datetime import datetime
|
| 6 |
from contextlib import asynccontextmanager
|
| 7 |
from fastapi import (
|
|
|
|
| 69 |
TENNIS_ML_API = os.getenv("TENNIS_ML_API")
|
| 70 |
|
| 71 |
@asynccontextmanager
|
| 72 |
+
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
|
| 73 |
if not TENNIS_ML_API:
|
| 74 |
yield
|
| 75 |
return
|
|
|
|
| 105 |
|
| 106 |
api_key_header = APIKeyHeader(name='Authorization', auto_error=False)
|
| 107 |
|
| 108 |
+
async def validate_api_key(request: Request, key: str = Security(api_key_header)) -> None:
|
| 109 |
'''
|
| 110 |
Check if the API key is valid
|
| 111 |
|