fix: key schemas
This commit is contained in:
parent
1fe6a06a5f
commit
833df786a8
3 changed files with 13 additions and 9 deletions
|
|
@ -3,7 +3,7 @@
|
|||
# Set up router
|
||||
import logging
|
||||
from fastapi import APIRouter
|
||||
from fastapi import Depends
|
||||
from fastapi import Security
|
||||
|
||||
from src.dataprocessor.schemas import UpdateDbResponse
|
||||
from src.dependencies import require_pp_api_key
|
||||
|
|
@ -16,7 +16,7 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
@router.post("/update-db")
|
||||
async def update_db(*, _: None = Depends(require_pp_api_key)) -> UpdateDbResponse:
|
||||
async def update_db(_: None = Security(require_pp_api_key)) -> UpdateDbResponse:
|
||||
"""Endpoint to update the AI-database."""
|
||||
service = await DataProcessorService.create()
|
||||
await service.update_database()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
"""Router for data query endpoints."""
|
||||
|
||||
import logging
|
||||
from fastapi import APIRouter, Depends, Path
|
||||
from fastapi import APIRouter
|
||||
from fastapi import Path
|
||||
from fastapi import Security
|
||||
|
||||
from src.dataquery.schemas import (
|
||||
DatabaseSchemaResponse,
|
||||
|
|
@ -21,7 +23,7 @@ logger = logging.getLogger(__name__)
|
|||
@router.post("/query", response_model=SqlQueryResponse)
|
||||
async def execute_sql_query(
|
||||
request: SqlQueryRequest,
|
||||
_: None = Depends(require_db_api_key),
|
||||
_: None = Security(require_db_api_key),
|
||||
) -> SqlQueryResponse:
|
||||
"""Execute a SELECT SQL query against the database.
|
||||
|
||||
|
|
@ -44,7 +46,7 @@ async def execute_sql_query(
|
|||
|
||||
@router.get("/schema", response_model=DatabaseSchemaResponse)
|
||||
async def get_database_schema(
|
||||
_: None = Depends(require_db_api_key),
|
||||
_: None = Security(require_db_api_key),
|
||||
) -> DatabaseSchemaResponse:
|
||||
"""Get information about all tables in the database.
|
||||
|
||||
|
|
@ -64,7 +66,7 @@ async def get_database_schema(
|
|||
@router.get("/schema/{table_name}", response_model=TableSchemaResponse)
|
||||
async def get_table_schema(
|
||||
table_name: str = Path(..., description="Name of the table to inspect"),
|
||||
_: None = Depends(require_db_api_key),
|
||||
_: None = Security(require_db_api_key),
|
||||
) -> TableSchemaResponse:
|
||||
"""Get detailed information about a specific table.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""Dependencies for FastAPI routers."""
|
||||
|
||||
from fastapi import Depends
|
||||
from fastapi import HTTPException
|
||||
from fastapi import Security
|
||||
from fastapi import status
|
||||
from fastapi.security import APIKeyHeader
|
||||
from fastapi.security.base import SecurityBase
|
||||
|
|
@ -13,10 +13,11 @@ from src.settings import settings
|
|||
api_key_header: SecurityBase = APIKeyHeader(
|
||||
name="X-PP-API-Key",
|
||||
description="API key for preprocessor access",
|
||||
scheme_name="PreprocessorKey",
|
||||
)
|
||||
|
||||
|
||||
def require_pp_api_key(api_key: str = Depends(api_key_header)) -> None:
|
||||
def require_pp_api_key(api_key: str = Security(api_key_header)) -> None:
|
||||
"""Validate the preprocessor API key.
|
||||
|
||||
Args:
|
||||
|
|
@ -37,10 +38,11 @@ def require_pp_api_key(api_key: str = Depends(api_key_header)) -> None:
|
|||
db_api_key_header: SecurityBase = APIKeyHeader(
|
||||
name="X-DB-API-Key",
|
||||
description="API key for database query access",
|
||||
scheme_name="DatabaseKey",
|
||||
)
|
||||
|
||||
|
||||
def require_db_api_key(api_key: str = Depends(db_api_key_header)) -> None:
|
||||
def require_db_api_key(api_key: str = Security(db_api_key_header)) -> None:
|
||||
"""Validate the database API key.
|
||||
|
||||
Args:
|
||||
|
|
|
|||
Loading…
Reference in a new issue