A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.
feat(api): update key service
dextmorgn6494cee2d0f9
diff --git a/flowsint-api/app/api/routes/keys.py b/flowsint-api/app/api/routes/keys.pyindex 256a8989..6c09085c 100644--- a/flowsint-api/app/api/routes/keys.py+++ b/flowsint-api/app/api/routes/keys.py@@ -1,17 +1,18 @@-from uuid import UUID-from fastapi import APIRouter, HTTPException, Depends, statusfrom typing import List-from sqlalchemy.orm import Session+from uuid import UUID+from fastapi import APIRouter, Depends, HTTPException, status+from flowsint_core.core.models import Profile+from flowsint_core.core.postgre_db import get_dbfrom flowsint_core.core.services import (- create_key_service,- NotFoundError,DatabaseError,+ NotFoundError,+ create_key_service,)-from flowsint_core.core.postgre_db import get_db-from flowsint_core.core.models import Profile+from sqlalchemy.orm import Session+from app.api.deps import get_current_user-from app.api.schemas.key import KeyRead, KeyCreate+from app.api.schemas.key import KeyCreate, KeyExists, KeyReadrouter = APIRouter()@@ -33,6 +34,23 @@ def get_keys(][email protected]("/chat-key-exists", response_model=KeyExists)+def chat_key_exists(+ db: Session = Depends(get_db),+ current_user: Profile = Depends(get_current_user),+):+ """+ A simple util route to know if any ai chat key exists in the vault for this user+ """+ service = create_key_service(db)+ try:+ key_exists = service.chat_key_exist(current_user.id)+ return KeyExists(exists=key_exists)+ except NotFoundError as e:+ print(e)+ return KeyExists(exists=False)++@router.get("/{id}", response_model=KeyRead)def get_key_by_id(id: UUID,diff --git a/flowsint-api/app/api/routes/scan.py b/flowsint-api/app/api/routes/scan.pyindex 43df0d25..7323290a 100644--- a/flowsint-api/app/api/routes/scan.py+++ b/flowsint-api/app/api/routes/scan.py@@ -1,28 +1,31 @@-from uuid import UUID-from fastapi import APIRouter, HTTPException, Depends, statusfrom typing import List-from sqlalchemy.orm import Session+from uuid import UUID-from flowsint_core.core.postgre_db import get_db+from fastapi import APIRouter, Depends, HTTPException, statusfrom flowsint_core.core.models import Profile+from flowsint_core.core.postgre_db import get_dbfrom flowsint_core.core.services import (- create_scan_service,NotFoundError,PermissionDeniedError,+ create_scan_service,)+from sqlalchemy.orm import Session+from app.api.deps import get_current_userfrom app.api.schemas.scan import ScanReadrouter = APIRouter()[email protected]("", response_model=List[ScanRead])[email protected]("/sketch/{id}", response_model=List[ScanRead])def get_scans(- db: Session = Depends(get_db), current_user: Profile = Depends(get_current_user)+ id: UUID,+ db: Session = Depends(get_db),+ current_user: Profile = Depends(get_current_user),):- """Get all scans accessible to the current user."""+ """Get all scans accessible to the current user, linked to a sketch."""service = create_scan_service(db)- return service.get_accessible_scans(current_user.id)+ return service.get_accessible_scans_by_sketch_id(current_user.id, id)@router.get("/{id}", response_model=ScanRead)diff --git a/flowsint-api/app/api/schemas/key.py b/flowsint-api/app/api/schemas/key.pyindex 38785016..23cd178f 100644--- a/flowsint-api/app/api/schemas/key.py+++ b/flowsint-api/app/api/schemas/key.py@@ -1,7 +1,9 @@-from .base import ORMBase-from pydantic import UUID4, BaseModelfrom datetime import datetime+from pydantic import UUID4, BaseModel++from .base import ORMBase+class KeyCreate(BaseModel):key: str@@ -12,4 +14,8 @@ class KeyRead(ORMBase):id: UUID4owner_id: UUID4name: str- created_at: datetime+ created_at: datetime | str+++class KeyExists(BaseModel):+ exists: bool