commit
382ab2da25
@ -1,4 +1,4 @@
|
|||||||
FROM python:3.10
|
FROM python:3.12
|
||||||
|
|
||||||
RUN mkdir /usr/src/app
|
RUN mkdir /usr/src/app
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
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,7 +1,6 @@
|
|||||||
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
|
||||||
@ -9,10 +8,22 @@ 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