mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-14 13:40:54 +00:00
feat: Add dbgpt client and add api v2
This commit is contained in:
@@ -2,7 +2,7 @@ import uuid
|
||||
from functools import cache
|
||||
from typing import List, Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Request
|
||||
from fastapi.security.http import HTTPAuthorizationCredentials, HTTPBearer
|
||||
|
||||
from dbgpt.component import SystemApp
|
||||
@@ -45,6 +45,7 @@ def _parse_api_keys(api_keys: str) -> List[str]:
|
||||
|
||||
async def check_api_key(
|
||||
auth: Optional[HTTPAuthorizationCredentials] = Depends(get_bearer_token),
|
||||
request: Request = None,
|
||||
service: Service = Depends(get_service),
|
||||
) -> Optional[str]:
|
||||
"""Check the api key
|
||||
@@ -63,6 +64,9 @@ async def check_api_key(
|
||||
assert res.status_code == 200
|
||||
|
||||
"""
|
||||
if request.url.path.startswith(f"/api/v1"):
|
||||
return None
|
||||
|
||||
if service.config.api_keys:
|
||||
api_keys = _parse_api_keys(service.config.api_keys)
|
||||
if auth is None or (token := auth.credentials) not in api_keys:
|
||||
|
Reference in New Issue
Block a user