master #7
@ -20,4 +20,4 @@ services:
|
||||
|
||||
networks:
|
||||
common-infra-nginx:
|
||||
external: true
|
||||
external: true
|
||||
|
@ -41,4 +41,4 @@ jobs:
|
||||
env:
|
||||
MONGO_PASSWORD_DEV: ${{ secrets.MONGO_PASSWORD_DEV }}
|
||||
QUEUES_TOKEN_DEV: ${{ secrets.QUEUES_TOKEN_DEV }}
|
||||
run: docker stack deploy --with-registry-auth -c ./.deploy/deploy-dev.yaml infra
|
||||
run: docker stack deploy --with-registry-auth -c ./.deploy/deploy-dev.yaml infra
|
||||
|
@ -1,4 +1,4 @@
|
||||
FROM python:3.10
|
||||
FROM python:3.12
|
||||
|
||||
RUN mkdir /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 uvicorn
|
||||
|
||||
from app.middlewares import check_token
|
||||
import os
|
||||
|
||||
from app.routers import take
|
||||
from app.routers import put
|
||||
@ -9,10 +8,22 @@ from app.routers import finish
|
||||
|
||||
from app.storage import mongo
|
||||
|
||||
from fastapi import responses
|
||||
|
||||
|
||||
QUEUES_TOKEN = os.getenv('QUEUES_TOKEN')
|
||||
|
||||
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(put.router)
|
||||
|
Loading…
Reference in New Issue
Block a user