Compare commits
No commits in common. "382ab2da25c2185cdfb80430f30dc0264f757d84" and "ef3c8c800609eadf11399432c813bdd6bda369a3" have entirely different histories.
382ab2da25
...
ef3c8c8006
@ -1,4 +1,4 @@
|
|||||||
FROM python:3.12
|
FROM python:3.10
|
||||||
|
|
||||||
RUN mkdir /usr/src/app
|
RUN mkdir /usr/src/app
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
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)
|
17
main.py
17
main.py
@ -1,6 +1,7 @@
|
|||||||
import fastapi
|
import fastapi
|
||||||
import uvicorn
|
import uvicorn
|
||||||
import os
|
|
||||||
|
from app.middlewares import check_token
|
||||||
|
|
||||||
from app.routers import take
|
from app.routers import take
|
||||||
from app.routers import put
|
from app.routers import put
|
||||||
@ -8,22 +9,10 @@ from app.routers import finish
|
|||||||
|
|
||||||
from app.storage import mongo
|
from app.storage import mongo
|
||||||
|
|
||||||
from fastapi import responses
|
|
||||||
|
|
||||||
|
|
||||||
QUEUES_TOKEN = os.getenv('QUEUES_TOKEN')
|
|
||||||
|
|
||||||
app = fastapi.FastAPI()
|
app = fastapi.FastAPI()
|
||||||
|
|
||||||
|
app.add_middleware(check_token.CheckToken)
|
||||||
@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:
|
|
||||||
return responses.JSONResponse(status_code=403, content={'message': 'token is not provided or incorrect'})
|
|
||||||
return await call_next(request)
|
|
||||||
|
|
||||||
|
|
||||||
app.include_router(take.router)
|
app.include_router(take.router)
|
||||||
app.include_router(put.router)
|
app.include_router(put.router)
|
||||||
|
Loading…
Reference in New Issue
Block a user