|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import uuid |
| 4 | +from enum import StrEnum |
4 | 5 | from typing import Self |
5 | 6 |
|
6 | 7 | import strawberry |
7 | 8 | from strawberry import ID, UNSET, Info |
8 | 9 |
|
| 10 | +from ai.backend.common.data.storage.types import ArtifactStorageType |
9 | 11 | from ai.backend.manager.data.artifact_storages.types import ( |
10 | 12 | ArtifactStorageData, |
11 | 13 | ArtifactStorageUpdaterSpec, |
|
20 | 22 | from .types import StrawberryGQLContext |
21 | 23 |
|
22 | 24 |
|
| 25 | +@strawberry.enum( |
| 26 | + name="ArtifactStorageType", |
| 27 | + description=( |
| 28 | + "Added in 26.2.0. The type of artifact storage backend. " |
| 29 | + "OBJECT_STORAGE: Object storage (e.g., S3-compatible). " |
| 30 | + "VFS_STORAGE: Virtual folder storage. " |
| 31 | + "GIT_LFS: Git LFS storage." |
| 32 | + ), |
| 33 | +) |
| 34 | +class ArtifactStorageTypeGQL(StrEnum): |
| 35 | + """Artifact storage type enum.""" |
| 36 | + |
| 37 | + OBJECT_STORAGE = "object_storage" |
| 38 | + VFS_STORAGE = "vfs_storage" |
| 39 | + GIT_LFS = "git_lfs" |
| 40 | + |
| 41 | + @classmethod |
| 42 | + def from_internal(cls, internal_type: ArtifactStorageType) -> ArtifactStorageTypeGQL: |
| 43 | + """Convert internal ArtifactStorageType to GraphQL enum.""" |
| 44 | + match internal_type: |
| 45 | + case ArtifactStorageType.OBJECT_STORAGE: |
| 46 | + return cls.OBJECT_STORAGE |
| 47 | + case ArtifactStorageType.VFS_STORAGE: |
| 48 | + return cls.VFS_STORAGE |
| 49 | + case ArtifactStorageType.GIT_LFS: |
| 50 | + return cls.GIT_LFS |
| 51 | + |
| 52 | + def to_internal(self) -> ArtifactStorageType: |
| 53 | + """Convert GraphQL enum to internal ArtifactStorageType.""" |
| 54 | + match self: |
| 55 | + case ArtifactStorageTypeGQL.OBJECT_STORAGE: |
| 56 | + return ArtifactStorageType.OBJECT_STORAGE |
| 57 | + case ArtifactStorageTypeGQL.VFS_STORAGE: |
| 58 | + return ArtifactStorageType.VFS_STORAGE |
| 59 | + case ArtifactStorageTypeGQL.GIT_LFS: |
| 60 | + return ArtifactStorageType.GIT_LFS |
| 61 | + |
| 62 | + |
23 | 63 | @strawberry.type(description="Added in 26.2.0. Artifact storage metadata") |
24 | 64 | class ArtifactStorage: |
25 | 65 | id: ID = strawberry.field(description="The ID of the artifact storage") |
26 | 66 | name: str = strawberry.field(description="The name of the artifact storage") |
27 | 67 | storage_id: ID = strawberry.field( |
28 | 68 | description="The ID of the underlying storage (ObjectStorage or VFSStorage)" |
29 | 69 | ) |
30 | | - type: str = strawberry.field(description="The type of the artifact storage") |
| 70 | + type: ArtifactStorageTypeGQL = strawberry.field(description="The type of the artifact storage") |
31 | 71 |
|
32 | 72 | @classmethod |
33 | 73 | def from_dataclass(cls, data: ArtifactStorageData) -> Self: |
34 | 74 | return cls( |
35 | 75 | id=ID(str(data.id)), |
36 | 76 | name=data.name, |
37 | 77 | storage_id=ID(str(data.storage_id)), |
38 | | - type=data.type.value, |
| 78 | + type=ArtifactStorageTypeGQL.from_internal(data.type), |
39 | 79 | ) |
40 | 80 |
|
41 | 81 |
|
|
0 commit comments