Refactor: Clean main.py
This commit is contained in:
21
app/api/deps.py
Normal file
21
app/api/deps.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import os
|
||||
from fastapi import Depends, HTTPException, Security
|
||||
from fastapi.security import APIKeyHeader
|
||||
from starlette.status import HTTP_403_FORBIDDEN
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
API_KEY = os.getenv("IGNIS_API_KEY")
|
||||
API_KEY_NAME = "X-API-Key"
|
||||
api_key_header = APIKeyHeader(name=API_KEY_NAME, auto_error=False)
|
||||
|
||||
|
||||
async def verify_token(header_value: str = Depends(api_key_header)):
|
||||
if not API_KEY:
|
||||
return None
|
||||
if header_value == API_KEY:
|
||||
return header_value
|
||||
raise HTTPException(
|
||||
status_code=HTTP_403_FORBIDDEN, detail="Could not validate credentials"
|
||||
)
|
||||
Reference in New Issue
Block a user