fix: key schemas

This commit is contained in:
Christopher Gondek 2025-10-17 10:53:09 +02:00
parent 1fe6a06a5f
commit 833df786a8
3 changed files with 13 additions and 9 deletions

View file

@ -3,7 +3,7 @@
# Set up router # Set up router
import logging import logging
from fastapi import APIRouter from fastapi import APIRouter
from fastapi import Depends from fastapi import Security
from src.dataprocessor.schemas import UpdateDbResponse from src.dataprocessor.schemas import UpdateDbResponse
from src.dependencies import require_pp_api_key from src.dependencies import require_pp_api_key
@ -16,7 +16,7 @@ logger = logging.getLogger(__name__)
@router.post("/update-db") @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.""" """Endpoint to update the AI-database."""
service = await DataProcessorService.create() service = await DataProcessorService.create()
await service.update_database() await service.update_database()

View file

@ -1,7 +1,9 @@
"""Router for data query endpoints.""" """Router for data query endpoints."""
import logging 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 ( from src.dataquery.schemas import (
DatabaseSchemaResponse, DatabaseSchemaResponse,
@ -21,7 +23,7 @@ logger = logging.getLogger(__name__)
@router.post("/query", response_model=SqlQueryResponse) @router.post("/query", response_model=SqlQueryResponse)
async def execute_sql_query( async def execute_sql_query(
request: SqlQueryRequest, request: SqlQueryRequest,
_: None = Depends(require_db_api_key), _: None = Security(require_db_api_key),
) -> SqlQueryResponse: ) -> SqlQueryResponse:
"""Execute a SELECT SQL query against the database. """Execute a SELECT SQL query against the database.
@ -44,7 +46,7 @@ async def execute_sql_query(
@router.get("/schema", response_model=DatabaseSchemaResponse) @router.get("/schema", response_model=DatabaseSchemaResponse)
async def get_database_schema( async def get_database_schema(
_: None = Depends(require_db_api_key), _: None = Security(require_db_api_key),
) -> DatabaseSchemaResponse: ) -> DatabaseSchemaResponse:
"""Get information about all tables in the database. """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) @router.get("/schema/{table_name}", response_model=TableSchemaResponse)
async def get_table_schema( async def get_table_schema(
table_name: str = Path(..., description="Name of the table to inspect"), table_name: str = Path(..., description="Name of the table to inspect"),
_: None = Depends(require_db_api_key), _: None = Security(require_db_api_key),
) -> TableSchemaResponse: ) -> TableSchemaResponse:
"""Get detailed information about a specific table. """Get detailed information about a specific table.

View file

@ -1,7 +1,7 @@
"""Dependencies for FastAPI routers.""" """Dependencies for FastAPI routers."""
from fastapi import Depends
from fastapi import HTTPException from fastapi import HTTPException
from fastapi import Security
from fastapi import status from fastapi import status
from fastapi.security import APIKeyHeader from fastapi.security import APIKeyHeader
from fastapi.security.base import SecurityBase from fastapi.security.base import SecurityBase
@ -13,10 +13,11 @@ from src.settings import settings
api_key_header: SecurityBase = APIKeyHeader( api_key_header: SecurityBase = APIKeyHeader(
name="X-PP-API-Key", name="X-PP-API-Key",
description="API key for preprocessor access", 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. """Validate the preprocessor API key.
Args: Args:
@ -37,10 +38,11 @@ def require_pp_api_key(api_key: str = Depends(api_key_header)) -> None:
db_api_key_header: SecurityBase = APIKeyHeader( db_api_key_header: SecurityBase = APIKeyHeader(
name="X-DB-API-Key", name="X-DB-API-Key",
description="API key for database query access", 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. """Validate the database API key.
Args: Args: