forked from Ivan-Feofanov/github-release-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
23 lines (16 loc) · 801 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from fastapi import FastAPI, HTTPException, Depends
from starlette import status
from starlette.requests import Request
import settings
from router import api_router
from utils import check_auth
docs_kwargs = {} # noqa: pylint=invalid-name
if settings.ENVIRONMENT == 'production':
docs_kwargs = dict(docs_url=None, redoc_url=None) # noqa: pylint=invalid-name
app = FastAPI(**docs_kwargs) # noqa: pylint=invalid-name
async def check_auth_middleware(request: Request):
if settings.ENVIRONMENT in ('production', 'test'):
body = await request.body()
if not check_auth(body, request.headers.get('X-Hub-Signature', '')):
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
app.include_router(api_router, dependencies=[Depends(check_auth_middleware)])