diff --git a/packages/sshecret-backend/src/sshecret_backend/api/audit.py b/packages/sshecret-backend/src/sshecret_backend/api/audit.py index 14706db..517bf57 100644 --- a/packages/sshecret-backend/src/sshecret_backend/api/audit.py +++ b/packages/sshecret-backend/src/sshecret_backend/api/audit.py @@ -4,7 +4,7 @@ import logging from typing import Any -from fastapi import APIRouter, Depends, Request +from fastapi import APIRouter, Depends from pydantic import BaseModel, Field, TypeAdapter from sqlalchemy import select, func, and_ from sqlalchemy.ext.asyncio import AsyncSession diff --git a/packages/sshecret-backend/src/sshecret_backend/api/secrets.py b/packages/sshecret-backend/src/sshecret_backend/api/secrets.py index 5fca3c2..d77ef5c 100644 --- a/packages/sshecret-backend/src/sshecret_backend/api/secrets.py +++ b/packages/sshecret-backend/src/sshecret_backend/api/secrets.py @@ -22,7 +22,7 @@ from sshecret_backend.view_models import ( ) from sshecret_backend import audit from sshecret_backend.types import AsyncDBSessionDep -from .common import get_client_by_id_or_name +from .common import get_client_by_id_or_name, get_client_by_name LOG = logging.getLogger(__name__) @@ -146,7 +146,7 @@ def get_secrets_api(get_db_session: AsyncDBSessionDep) -> APIRouter: session: Annotated[AsyncSession, Depends(get_db_session)], ) -> None: """Delete a secret.""" - client = await get_client_by_id_or_name(session, name) + client = await get_client_by_name(session, name) if not client: raise HTTPException( status_code=404, detail="Cannot find a client with the given name." @@ -217,8 +217,10 @@ def get_secrets_api(get_db_session: AsyncDBSessionDep) -> APIRouter: clients: list[str] = [] client_secrets = await session.scalars( select(ClientSecret) + .join(ClientSecret.client) .options(selectinload(ClientSecret.client)) .where(ClientSecret.name == name) + .where(Client.is_active.is_(True)) ) for client_secret in client_secrets.all(): if not client_secret.client: @@ -235,7 +237,10 @@ def get_secrets_api(get_db_session: AsyncDBSessionDep) -> APIRouter: """Get a list of which clients has a named secret.""" detail_list = ClientSecretDetailList(name=name) client_secrets = await session.scalars( - select(ClientSecret).where(ClientSecret.name == name) + select(ClientSecret) + .options(selectinload(ClientSecret.client)) + .where(ClientSecret.name == name) + .where(ClientSecret.client.is_(Client.is_active)) ) for client_secret in client_secrets.all(): if not client_secret.client: diff --git a/packages/sshecret-backend/src/sshecret_backend/db.py b/packages/sshecret-backend/src/sshecret_backend/db.py index 0719503..f7c2f13 100644 --- a/packages/sshecret-backend/src/sshecret_backend/db.py +++ b/packages/sshecret-backend/src/sshecret_backend/db.py @@ -6,7 +6,7 @@ import sqlite3 from collections.abc import AsyncIterator, Generator, Callable from contextlib import asynccontextmanager -from typing import Any, Literal +from typing import Literal from sqlalchemy import create_engine, Engine, event, select from sqlalchemy.ext.asyncio import AsyncConnection, AsyncSession, async_sessionmaker, create_async_engine, AsyncEngine diff --git a/packages/sshecret-backend/src/sshecret_backend/types.py b/packages/sshecret-backend/src/sshecret_backend/types.py index d9df5e7..d683778 100644 --- a/packages/sshecret-backend/src/sshecret_backend/types.py +++ b/packages/sshecret-backend/src/sshecret_backend/types.py @@ -2,7 +2,7 @@ from collections.abc import AsyncGenerator, Callable, Generator -from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession +from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.orm import Session