Compare commits
No commits in common. "9adc0d77ce6852e90c6013635bbe346b73b16041" and "9e14ce27394c9dc0349a8b66f79fd0f4864070ef" have entirely different histories.
9adc0d77ce
...
9e14ce2739
0
app/middlewares/__init__.py
Normal file
0
app/middlewares/__init__.py
Normal file
13
app/middlewares/check_token.py
Normal file
13
app/middlewares/check_token.py
Normal file
@ -0,0 +1,13 @@
|
||||
import fastapi
|
||||
import os
|
||||
|
||||
|
||||
QUEUES_TOKEN = os.getenv('QUEUES_TOKEN')
|
||||
|
||||
class CheckToken:
|
||||
async def __call__(self, request: fastapi.Request, call_next):
|
||||
if QUEUES_TOKEN:
|
||||
token = request.headers.get('X-Queues-Token')
|
||||
if not token or token != QUEUES_TOKEN:
|
||||
raise fastapi.HTTPException(403)
|
||||
return await call_next(request)
|
15
main.py
15
main.py
@ -1,6 +1,7 @@
|
||||
import fastapi
|
||||
import uvicorn
|
||||
import os
|
||||
|
||||
from app.middlewares import check_token
|
||||
|
||||
from app.routers import take
|
||||
from app.routers import put
|
||||
@ -9,19 +10,9 @@ from app.routers import finish
|
||||
from app.storage import mongo
|
||||
|
||||
|
||||
QUEUES_TOKEN = os.getenv('QUEUES_TOKEN')
|
||||
|
||||
app = fastapi.FastAPI()
|
||||
|
||||
|
||||
@app.middleware('http')
|
||||
async def check_token(request: fastapi.Request, call_next):
|
||||
if QUEUES_TOKEN:
|
||||
token = request.headers.get('X-Queues-Token')
|
||||
if not token or token != QUEUES_TOKEN:
|
||||
raise fastapi.HTTPException(403)
|
||||
return await call_next(request)
|
||||
|
||||
app.add_middleware(check_token.CheckToken())
|
||||
|
||||
app.include_router(take.router)
|
||||
app.include_router(put.router)
|
||||
|
Loading…
Reference in New Issue
Block a user