minor: renames and error messages
This commit is contained in:
parent
94cf6c5258
commit
c8024daa97
3 changed files with 12 additions and 11 deletions
|
|
@ -9,6 +9,7 @@ from typing import Annotated
|
|||
from src.service.models import Service
|
||||
from src.database import db_dependency
|
||||
from src.schemas import ResourceName
|
||||
from src.auth.exceptions import UnauthorizedException
|
||||
|
||||
from fastapi import HTTPException, status, Request, Depends
|
||||
|
||||
|
|
@ -16,11 +17,11 @@ from fastapi import HTTPException, status, Request, Depends
|
|||
def valid_service_key(db: db_dependency, request: Request, rn: ResourceName) -> bool:
|
||||
api_key = request.headers.get("X-API-Key", None)
|
||||
if not api_key:
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
|
||||
raise UnauthorizedException("Missing API key")
|
||||
service = rn.service
|
||||
result = db.query(Service).filter(Service.name == service).filter(Service.api_key == api_key).first()
|
||||
if result is None:
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
|
||||
raise UnauthorizedException("Invalid API key")
|
||||
|
||||
return True
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue