-
Notifications
You must be signed in to change notification settings - Fork 175
feat(BA-5119): add Strawberry GQL node type for ContainerRegistry #10093
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
64308b4
feat(BA-5119): add Strawberry GQL node type for ContainerRegistry
fregataa dd58fad
changelog: add news fragment for PR #10093
fregataa c6a69bf
fix(BA-5119): set enum name and fix password masking condition
fregataa 646a9ab
chore(BA-5119): apply ruff formatting
fregataa 943edd4
fix(BA-5119): rename GQL type to ContainerRegistryV2 to avoid supergr…
fregataa ae58e9b
chore: update api schema dump
fregataa c1e9aa1
test(BA-5119): add enum sync guard for ContainerRegistryTypeGQL
fregataa 2041cb6
feat(BA-5119): add extra field to ContainerRegistryGQL node
fregataa 5141c04
feat(BA-5119): add CONTAINER_REGISTRY case to PermissionGQL.scope() r…
fregataa 4ab2123
chore(BA-5119): update version annotation to 26.4.0 for ContainerRegi…
fregataa 3804ebe
chore: update api schema dump
fregataa 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add Strawberry GraphQL node type for ContainerRegistry to support RBAC entity resolution |
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
11 changes: 11 additions & 0 deletions
11
src/ai/backend/manager/api/gql/container_registry/__init__.py
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,11 @@ | ||
| """GraphQL container registry module.""" | ||
|
|
||
| from .types import ( | ||
| ContainerRegistryGQL, | ||
| ContainerRegistryTypeGQL, | ||
| ) | ||
|
|
||
| __all__ = ( | ||
| "ContainerRegistryGQL", | ||
| "ContainerRegistryTypeGQL", | ||
| ) |
96 changes: 96 additions & 0 deletions
96
src/ai/backend/manager/api/gql/container_registry/types.py
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,96 @@ | ||
| """GraphQL types for container registry.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Iterable | ||
| from enum import StrEnum | ||
| from typing import Self | ||
| from uuid import UUID | ||
|
|
||
| import strawberry | ||
| from strawberry import Info | ||
| from strawberry.relay import Node, NodeID | ||
| from strawberry.scalars import JSON | ||
|
|
||
| from ai.backend.common.container_registry import ContainerRegistryType | ||
| from ai.backend.manager.api.gql.types import StrawberryGQLContext | ||
| from ai.backend.manager.data.container_registry.types import ContainerRegistryData | ||
| from ai.backend.manager.defs import PASSWORD_PLACEHOLDER | ||
|
|
||
|
|
||
| @strawberry.enum( | ||
| name="ContainerRegistryType", description="Added in 26.4.0. Container registry type." | ||
| ) | ||
| class ContainerRegistryTypeGQL(StrEnum): | ||
| DOCKER = "docker" | ||
| HARBOR = "harbor" | ||
| HARBOR2 = "harbor2" | ||
| GITHUB = "github" | ||
| GITLAB = "gitlab" | ||
| ECR = "ecr" | ||
| ECR_PUB = "ecr-public" | ||
| LOCAL = "local" | ||
| OCP = "ocp" | ||
|
|
||
| @classmethod | ||
| def from_enum(cls, value: ContainerRegistryType) -> ContainerRegistryTypeGQL: | ||
| return cls(value.value) | ||
|
|
||
|
|
||
| @strawberry.type( | ||
| name="ContainerRegistryV2", | ||
| description="Added in 26.4.0. Container registry node.", | ||
| ) | ||
| class ContainerRegistryGQL(Node): | ||
| id: NodeID[str] = strawberry.field( | ||
| description="Relay-style global node identifier for the container registry" | ||
| ) | ||
| url: str = strawberry.field(description="URL of the container registry") | ||
| registry_name: str = strawberry.field(description="Name of the container registry") | ||
| type: ContainerRegistryTypeGQL = strawberry.field(description="Type of the container registry") | ||
| project: str | None = strawberry.field( | ||
| description="Project or namespace within the registry", default=None | ||
| ) | ||
| username: str | None = strawberry.field( | ||
| description="Username for registry authentication", default=None | ||
| ) | ||
| password: str | None = strawberry.field( | ||
| description="Masked password for registry authentication", default=None | ||
| ) | ||
| ssl_verify: bool | None = strawberry.field( | ||
| description="Whether SSL verification is enabled", default=None | ||
| ) | ||
| is_global: bool | None = strawberry.field( | ||
| description="Whether this registry is globally accessible", default=None | ||
| ) | ||
| extra: JSON | None = strawberry.field( | ||
| description="Extra metadata for the container registry", default=None | ||
| ) | ||
|
|
||
| @classmethod | ||
| async def resolve_nodes( # type: ignore[override] # Strawberry Node uses AwaitableOrValue overloads incompatible with async def | ||
| cls, | ||
| *, | ||
| info: Info[StrawberryGQLContext], | ||
| node_ids: Iterable[str], | ||
| required: bool = False, | ||
| ) -> Iterable[Self | None]: | ||
| results = await info.context.data_loaders.container_registry_loader.load_many([ | ||
| UUID(nid) for nid in node_ids | ||
| ]) | ||
| return [cls.from_data(data) if data is not None else None for data in results] | ||
|
|
||
| @classmethod | ||
| def from_data(cls, data: ContainerRegistryData) -> Self: | ||
| return cls( | ||
| id=str(data.id), | ||
| url=data.url, | ||
| registry_name=data.registry_name, | ||
| type=ContainerRegistryTypeGQL.from_enum(data.type), | ||
| project=data.project, | ||
| username=data.username, | ||
| password=PASSWORD_PLACEHOLDER if data.password is not None else None, | ||
| ssl_verify=data.ssl_verify, | ||
| is_global=data.is_global, | ||
| extra=data.extra, | ||
| ) |
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
26 changes: 26 additions & 0 deletions
26
tests/unit/manager/api/gql/test_container_registry_type_sync.py
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,26 @@ | ||
| """Sync guard: ContainerRegistryTypeGQL must cover all ContainerRegistryType members. | ||
|
|
||
| Prevents enum drift between the internal ContainerRegistryType and its GraphQL | ||
| mirror from silently reaching production as a runtime ValueError. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from ai.backend.common.container_registry import ContainerRegistryType | ||
| from ai.backend.manager.api.gql.container_registry.types import ContainerRegistryTypeGQL | ||
|
|
||
|
|
||
| class TestContainerRegistryTypeEnumSync: | ||
| def test_gql_enum_covers_all_internal_members(self) -> None: | ||
| internal_values = {member.value for member in ContainerRegistryType} | ||
| gql_values = {member.value for member in ContainerRegistryTypeGQL} | ||
| missing = internal_values - gql_values | ||
| assert not missing, ( | ||
| f"ContainerRegistryTypeGQL is missing members present in ContainerRegistryType: {missing}. " | ||
| f"Add them to ContainerRegistryTypeGQL to keep the enums in sync." | ||
| ) | ||
|
|
||
| def test_from_enum_roundtrip_for_all_members(self) -> None: | ||
| for member in ContainerRegistryType: | ||
| gql_member = ContainerRegistryTypeGQL.from_enum(member) | ||
| assert gql_member.value == member.value |
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.
Uh oh!
There was an error while loading. Please reload this page.