-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement
AssociateContainerRegistryWithGroup
, `DisassociateC…
…ontainerRegistryWithGroup`
- Loading branch information
1 parent
52314a4
commit 29dec8a
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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
72 changes: 72 additions & 0 deletions
72
src/ai/backend/manager/models/gql_models/container_registry.py
This file contains 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,72 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from typing import Self | ||
|
||
import graphene | ||
import sqlalchemy as sa | ||
|
||
from ai.backend.common.logging_utils import BraceStyleAdapter | ||
from ai.backend.manager.models.association_container_registries_groups import ( | ||
AssociationContainerRegistriesGroupsRow, | ||
) | ||
from ai.backend.manager.models.base import simple_db_mutate | ||
|
||
from .user import UserRole | ||
|
||
log = BraceStyleAdapter(logging.getLogger(__spec__.name)) # type: ignore | ||
|
||
|
||
class AssociateContainerRegistryWithGroup(graphene.Mutation): | ||
"""Added in 24.12.0.""" | ||
|
||
allowed_roles = (UserRole.SUPERADMIN,) | ||
|
||
class Arguments: | ||
registry_id = graphene.String(required=True) | ||
group_id = graphene.String(required=True) | ||
|
||
ok = graphene.Boolean() | ||
msg = graphene.String() | ||
|
||
@classmethod | ||
async def mutate( | ||
cls, | ||
root, | ||
info: graphene.ResolveInfo, | ||
registry_id: str, | ||
group_id: str, | ||
) -> Self: | ||
insert_query = sa.insert(AssociationContainerRegistriesGroupsRow).values({ | ||
"registry_id": registry_id, | ||
"group_id": group_id, | ||
}) | ||
return await simple_db_mutate(cls, info.context, insert_query) | ||
|
||
|
||
class DisassociateContainerRegistryWithGroup(graphene.Mutation): | ||
"""Added in 24.12.0.""" | ||
|
||
allowed_roles = (UserRole.SUPERADMIN,) | ||
|
||
class Arguments: | ||
registry_id = graphene.String(required=True) | ||
group_id = graphene.String(required=True) | ||
|
||
ok = graphene.Boolean() | ||
msg = graphene.String() | ||
|
||
@classmethod | ||
async def mutate( | ||
cls, | ||
root, | ||
info: graphene.ResolveInfo, | ||
registry_id: str, | ||
group_id: str, | ||
) -> Self: | ||
delete_query = ( | ||
sa.delete(AssociationContainerRegistriesGroupsRow) | ||
.where(AssociationContainerRegistriesGroupsRow.registry_id == registry_id) | ||
.where(AssociationContainerRegistriesGroupsRow.group_id == group_id) | ||
) | ||
return await simple_db_mutate(cls, info.context, delete_query) |