Implement podman-compatible commands
All checks were successful
Build and push image / build-containers (push) Successful in 8m46s

This commit is contained in:
2025-06-10 10:28:17 +02:00
parent 782ec19137
commit 0eaa913e35
8 changed files with 414 additions and 61 deletions

View File

@ -130,6 +130,7 @@ class ClientOperations:
if not db_client:
raise HTTPException(status_code=404, detail="Client not found.")
if db_client.is_deleted:
LOG.warning("Client %r was already deleted!", client)
return
db_client.is_deleted = True
db_client.deleted_at = datetime.now(timezone.utc)
@ -271,7 +272,12 @@ async def get_clients(
filter_query: ClientListParams,
) -> ClientQueryResult:
"""Get Clients."""
count_statement = select(func.count("*")).select_from(Client).where(Client.is_deleted.is_not(True)).where(Client.is_active.is_not(False))
count_statement = (
select(func.count("*"))
.select_from(Client)
.where(Client.is_deleted.is_not(True))
.where(Client.is_active.is_not(False))
)
count_statement = cast(
Select[tuple[int]],
filter_client_statement(count_statement, filter_query, True),

View File

@ -40,7 +40,9 @@ class ClientView(BaseModel):
return responses
@classmethod
def from_client(cls, client: models.Client) -> Self:
def from_client(
cls, client: models.Client, include_deleted_secrets: bool = False
) -> Self:
"""Instantiate from a client."""
view = cls(
id=client.id,
@ -54,7 +56,12 @@ class ClientView(BaseModel):
is_deleted=client.is_deleted,
)
if client.secrets:
view.secrets = [secret.name for secret in client.secrets]
if include_deleted_secrets:
view.secrets = [secret.name for secret in client.secrets]
else:
view.secrets = [
secret.name for secret in client.secrets if not secret.deleted
]
if client.policies:
view.policies = [policy.source for policy in client.policies]

View File

@ -116,24 +116,18 @@ async def resolve_client_id(
return None
async def get_client_by_id(session: AsyncSession, id: uuid.UUID) -> Client | None:
async def get_client_by_id(
session: AsyncSession, id: uuid.UUID, include_deleted: bool = False
) -> Client | None:
"""Get client by ID."""
client_filter = client_with_relationships().where(Client.id == id)
if include_deleted:
client_filter = client_with_relationships().where(Client.id == id)
else:
client_filter = query_active_clients().where(Client.id == id)
client_results = await session.execute(client_filter)
return client_results.scalars().first()
async def get_client_by_id_or_name(
session: AsyncSession, id_or_name: str
) -> Client | None:
"""Get client either by id or name."""
if RE_UUID.match(id_or_name):
id = uuid.UUID(id_or_name)
return await get_client_by_id(session, id)
return await get_client_by_name(session, id_or_name)
def query_active_clients() -> Select[tuple[Client]]:
"""Get all active clients."""
client_filter = (
@ -144,22 +138,6 @@ def query_active_clients() -> Select[tuple[Client]]:
return client_filter
async def get_client_by_name(session: AsyncSession, name: str) -> Client | None:
"""Get client by name.
This will get the latest client version, unless it's deleted.
"""
client_filter = (
client_with_relationships()
.where(Client.is_active.is_(True))
.where(Client.is_deleted.is_not(True))
.where(Client.name == name)
.order_by(Client.version.desc())
)
client_result = await session.execute(client_filter)
return client_result.scalars().first()
async def refresh_client(session: AsyncSession, client: Client) -> None:
"""Refresh the client and load in all relationships."""
await session.refresh(

View File

@ -182,8 +182,10 @@ class ClientSecretOperations:
async def delete_client_secret(self, secret_identifier: FlexID) -> None:
"""Delete a client secret."""
LOG.debug("delete_client_secret called with identifier %r", secret_identifier)
client_secret = await self._get_client_secret(secret_identifier)
if not client_secret:
LOG.warning("Could not find any secret matching client secret.")
return
client_secret.deleted = True