mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-09-11 11:50:17 +08:00
Merge branch 'v1_db_schema' into main
This commit is contained in:
+10
-18
@@ -1,9 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from typing import Generator
|
||||
|
||||
from uuid import UUID
|
||||
from app.config import settings
|
||||
from app.database import engine
|
||||
from app.models import ServiceClient
|
||||
from app.models import ApiClient
|
||||
from fastapi import HTTPException, Security
|
||||
from fastapi.security.api_key import APIKey, APIKeyHeader, APIKeyQuery
|
||||
from sqlmodel import Session
|
||||
@@ -32,24 +32,16 @@ async def get_api_key(
|
||||
def api_auth(
|
||||
api_key: APIKey,
|
||||
db: Session,
|
||||
create: bool = False,
|
||||
read: bool = True,
|
||||
update: bool = False,
|
||||
delete: bool = False,
|
||||
) -> ServiceClient:
|
||||
) -> ApiClient:
|
||||
|
||||
if api_key is not None:
|
||||
if settings.ALLOW_ANY_API_KEY:
|
||||
return ServiceClient(
|
||||
api_key=api_key, name=api_key, can_append=True, can_read=True, can_write=True, can_delete=True
|
||||
return ApiClient(
|
||||
id=UUID('00000000-1111-2222-3333-444444444444'),
|
||||
api_key=api_key, name=api_key
|
||||
)
|
||||
api_client = db.query(ServiceClient).filter(ServiceClient.api_key == api_key).first()
|
||||
if api_client is not None:
|
||||
if (
|
||||
(create is False or api_client.can_append)
|
||||
and (read is False or api_client.can_read)
|
||||
and (update is False or api_client.can_write)
|
||||
and (delete is False or api_client.can_delete)
|
||||
):
|
||||
return api_client
|
||||
api_client = db.query(ApiClient).filter(ApiClient.api_key == api_key).first()
|
||||
if api_client is not None and api_client.enabled:
|
||||
return api_client
|
||||
|
||||
raise HTTPException(status_code=HTTP_403_FORBIDDEN, detail="Could not validate credentials")
|
||||
|
||||
Reference in New Issue
Block a user