-
Notifications
You must be signed in to change notification settings - Fork 2
feat(management): add FastAPI routes and dependency injection (AIHCM-185) #303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jsell-rh
wants to merge
9
commits into
main
Choose a base branch
from
feature/AIHCM-185
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
954a84e
fix(management): add IntegrityError handling to DataSourceService cre…
jsell-rh d296a87
feat(management): support partial updates in KnowledgeGraphService.up…
jsell-rh 5103aa6
feat(management): add presentation layer with KG and DS routes (AIHCM…
jsell-rh 724aa0f
test(management): add integration tests for KG and DS API endpoints
jsell-rh cfce711
fix(management): fix HTTP status codes, add defensive error handling,…
jsell-rh 74e6ab0
fix(management): add catch-all error handlers and database-level pagi…
jsell-rh 634108b
fix(management): fix integration tests for pagination return type and…
jsell-rh 5b7d0a6
fix(management): use aggregate method for credential updates and add …
jsell-rh 800e749
fix(management): fix cascade delete loop and outbox cleanup case mism…
jsell-rh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| """Management presentation layer. | ||
|
|
||
| Aggregates sub-routers for knowledge graphs and data sources, | ||
| exporting a single management_router for registration in main.py. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from fastapi import APIRouter | ||
|
|
||
| from management.presentation.data_sources.routes import router as ds_router | ||
| from management.presentation.knowledge_graphs.routes import router as kg_router | ||
|
|
||
| management_router = APIRouter( | ||
| prefix="/management", | ||
| tags=["management"], | ||
| ) | ||
|
|
||
| management_router.include_router(kg_router) | ||
| management_router.include_router(ds_router) | ||
|
|
||
| __all__ = ["management_router"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Data source presentation sub-package.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| """Request and response models for Data Source API endpoints.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from datetime import datetime | ||
|
|
||
| from pydantic import BaseModel, Field | ||
|
|
||
| from management.domain.aggregates import DataSource | ||
| from management.domain.entities import DataSourceSyncRun | ||
|
|
||
|
|
||
| class CreateDataSourceRequest(BaseModel): | ||
| """Request to create a data source. | ||
|
|
||
| Attributes: | ||
| name: Data source name (1-100 characters) | ||
| adapter_type: Adapter type string (validated against DataSourceAdapterType in route) | ||
| connection_config: Key-value connection configuration | ||
| credentials: Optional write-only credentials (never returned in responses) | ||
| """ | ||
|
|
||
| name: str = Field(min_length=1, max_length=100) | ||
| adapter_type: str | ||
| connection_config: dict[str, str] | ||
| credentials: dict[str, str] | None = None | ||
|
|
||
|
|
||
| class UpdateDataSourceRequest(BaseModel): | ||
| """Request to partially update a data source. | ||
|
|
||
| Attributes: | ||
| name: Optional new name (1-100 characters) | ||
| connection_config: Optional new connection configuration | ||
| credentials: Optional new credentials (write-only) | ||
| """ | ||
|
|
||
| name: str | None = Field(default=None, min_length=1, max_length=100) | ||
| connection_config: dict[str, str] | None = None | ||
| credentials: dict[str, str] | None = None | ||
|
|
||
|
|
||
| class DataSourceResponse(BaseModel): | ||
| """Response containing data source details. | ||
|
|
||
| Credentials are never returned. Instead, has_credentials indicates | ||
| whether credentials have been configured. | ||
|
|
||
| Attributes: | ||
| id: Data source ID (ULID) | ||
| knowledge_graph_id: Parent knowledge graph ID | ||
| tenant_id: Tenant ID this data source belongs to | ||
| name: Data source name | ||
| adapter_type: Adapter type string | ||
| connection_config: Connection configuration key-value pairs | ||
| has_credentials: Whether credentials are configured | ||
| schedule_type: Schedule type (manual, cron, interval) | ||
| schedule_value: Schedule expression (None for manual) | ||
| last_sync_at: Last successful sync timestamp | ||
| created_at: Creation timestamp | ||
| updated_at: Last update timestamp | ||
| """ | ||
|
|
||
| id: str | ||
| knowledge_graph_id: str | ||
| tenant_id: str | ||
| name: str | ||
| adapter_type: str | ||
| connection_config: dict[str, str] | ||
| has_credentials: bool | ||
| schedule_type: str | ||
| schedule_value: str | None | ||
| last_sync_at: datetime | None | ||
| created_at: datetime | ||
| updated_at: datetime | ||
|
|
||
| @classmethod | ||
| def from_domain(cls, ds: DataSource) -> DataSourceResponse: | ||
| """Convert domain DataSource aggregate to API response. | ||
|
|
||
| Args: | ||
| ds: DataSource domain aggregate | ||
|
|
||
| Returns: | ||
| DataSourceResponse with data source details | ||
| """ | ||
| return cls( | ||
| id=ds.id.value, | ||
| knowledge_graph_id=ds.knowledge_graph_id, | ||
| tenant_id=ds.tenant_id, | ||
| name=ds.name, | ||
| adapter_type=ds.adapter_type.value, | ||
| connection_config=ds.connection_config, | ||
| has_credentials=ds.credentials_path is not None, | ||
| schedule_type=ds.schedule.schedule_type.value, | ||
| schedule_value=ds.schedule.value, | ||
| last_sync_at=ds.last_sync_at, | ||
| created_at=ds.created_at, | ||
| updated_at=ds.updated_at, | ||
| ) | ||
|
|
||
|
|
||
| class DataSourceListResponse(BaseModel): | ||
| """Response containing a paginated list of data sources. | ||
|
|
||
| Attributes: | ||
| items: List of data source details | ||
| total: Total number of data sources (before pagination) | ||
| offset: Number of items skipped | ||
| limit: Maximum number of items returned | ||
| """ | ||
|
|
||
| items: list[DataSourceResponse] | ||
| total: int | ||
| offset: int | ||
| limit: int | ||
|
|
||
|
|
||
| class SyncRunResponse(BaseModel): | ||
| """Response containing sync run details. | ||
|
|
||
| Attributes: | ||
| id: Sync run ID | ||
| data_source_id: Data source this sync belongs to | ||
| status: Sync run status (pending, running, completed, failed) | ||
| started_at: Sync start timestamp | ||
| completed_at: Sync completion timestamp (None if not complete) | ||
| created_at: Record creation timestamp | ||
| """ | ||
|
|
||
| id: str | ||
| data_source_id: str | ||
| status: str | ||
| started_at: datetime | ||
| completed_at: datetime | None | ||
| created_at: datetime | ||
|
|
||
| @classmethod | ||
| def from_domain(cls, sync_run: DataSourceSyncRun) -> SyncRunResponse: | ||
| """Convert domain DataSourceSyncRun entity to API response. | ||
|
|
||
| Args: | ||
| sync_run: DataSourceSyncRun domain entity | ||
|
|
||
| Returns: | ||
| SyncRunResponse with sync run details | ||
| """ | ||
| return cls( | ||
| id=sync_run.id, | ||
| data_source_id=sync_run.data_source_id, | ||
| status=sync_run.status, | ||
| started_at=sync_run.started_at, | ||
| completed_at=sync_run.completed_at, | ||
| created_at=sync_run.created_at, | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid writing secrets before the database write is known to succeed.
At Line 167 and Line 339,
_secret_store.store()runs before the database work has been flushed/committed. Ifsave()or commit then fails, create leaves an orphaned secret and update can rotate credentials even though the request returns an error. It also keeps the transaction open across external I/O. Flush first, then write the secret, and add compensation if anything after the secret write fails.Also applies to: 337-347
🤖 Prompt for AI Agents