🐛 fix(endpoints.py): add check for missing api_key and raise HTTPException with status code 401 and detail message "Invalid API Key"
🐛 fix(crud.py): remove unnecessary return statement and update_total_uses function call if api_key_object is None
This commit is contained in:
parent
2d22737c31
commit
f922214d2a
2 changed files with 14 additions and 11 deletions
|
|
@ -100,6 +100,11 @@ async def process_flow(
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if api_key is None:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
|
detail="Invalid API Key",
|
||||||
|
)
|
||||||
api_key_user = api_key.user
|
api_key_user = api_key.user
|
||||||
# Get the flow that matches the flow_id and belongs to the user
|
# Get the flow that matches the flow_id and belongs to the user
|
||||||
flow = (
|
flow = (
|
||||||
|
|
|
||||||
|
|
@ -50,17 +50,15 @@ def check_key(session: Session, api_key: str) -> Optional[ApiKey]:
|
||||||
"""Check if the API key is valid."""
|
"""Check if the API key is valid."""
|
||||||
query = select(ApiKey).where(ApiKey.api_key == api_key)
|
query = select(ApiKey).where(ApiKey.api_key == api_key)
|
||||||
api_key_object: Optional[ApiKey] = session.exec(query).first()
|
api_key_object: Optional[ApiKey] = session.exec(query).first()
|
||||||
if api_key_object is None:
|
if api_key_object is not None:
|
||||||
return api_key_object
|
threading.Thread(
|
||||||
|
target=update_total_uses,
|
||||||
threading.Thread(
|
args=(
|
||||||
target=update_total_uses,
|
session,
|
||||||
args=(
|
api_key_object,
|
||||||
session,
|
),
|
||||||
api_key_object,
|
).start()
|
||||||
),
|
return api_key_object
|
||||||
).start()
|
|
||||||
return api_key_object.user
|
|
||||||
|
|
||||||
|
|
||||||
def update_total_uses(session, api_key: ApiKey):
|
def update_total_uses(session, api_key: ApiKey):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue