Skip to content

Commit f673bc7

Browse files
committed
feat(schema): replace str field with enum class
1 parent 98cc938 commit f673bc7

File tree

4 files changed

+43
-20
lines changed

4 files changed

+43
-20
lines changed

.github/workflows/publish.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
name: Publishing
22

33
on:
4-
release:
5-
types: [created]
4+
push:
5+
tags:
6+
- "**[0-9]+.[0-9]+.[0-9]+*"
67
workflow_dispatch:
78

89
jobs:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ classifiers = [
4444
]
4545

4646
[build-system]
47-
requires = ["hatchling", "uv-dynamic-versioning"]
47+
requires = ["hatchling"]
4848
build-backend = "hatchling.build"
4949

5050
[project.urls]

src/pynetmito/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,3 @@
107107
"ShutdownReq",
108108
"RedisConnectionInfo",
109109
]
110-
111-
112-
c = MitoHttpClient("http://127.0.0.1:5000")
113-
c.connect(user="mitosis_admin", password="mitosis_admin", retain=True)
114-
c.user_auth()

src/pynetmito/schemas.py

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,35 @@ class TaskExecState(str, Enum):
204204
UNKNOWN = "Unknown"
205205

206206

207+
class UserState(str, Enum):
208+
ACTIVE = "Active"
209+
LOCKED = "Locked"
210+
DELETED = "Deleted"
211+
212+
213+
class GroupState(str, Enum):
214+
ACTIVE = "Active"
215+
LOCKED = "Locked"
216+
DELETED = "Deleted"
217+
218+
219+
class WorkerState(str, Enum):
220+
NORMAL = "Normal"
221+
GRACEFUL_SHUTDOWN = "GracefulShutdown"
222+
223+
224+
class UserGroupRole(str, Enum):
225+
READ = "Read"
226+
WRITE = "Write"
227+
ADMIN = "Admin"
228+
229+
230+
class GroupWorkerRole(str, Enum):
231+
READ = "Read"
232+
WRITE = "Write"
233+
ADMIN = "Admin"
234+
235+
207236
class TaskResultMessage(str, Enum):
208237
FETCH_RESOURCE_TIMEOUT = "FetchResourceTimeout"
209238
EXEC_TIMEOUT = "ExecTimeout"
@@ -593,7 +622,7 @@ class WorkerQueryInfo(BaseAPIModel):
593622
tags: list[str]
594623
created_at: datetime
595624
updated_at: datetime
596-
state: str # TODO: WorkerState enum
625+
state: WorkerState
597626
last_heartbeat: datetime
598627
assigned_task_id: Optional[UUID4] = Field(default=None)
599628

@@ -627,23 +656,23 @@ def serialize_last_heartbeat(self, last_heartbeat: datetime):
627656

628657
class WorkerQueryResp(BaseAPIModel):
629658
info: WorkerQueryInfo
630-
groups: Dict[str, str] # TODO: GroupWorkerRole
659+
groups: Dict[str, GroupWorkerRole]
631660

632661

633662
class WorkersQueryReq(BaseAPIModel):
634663
group_name: Optional[str] = Field(default=None)
635-
role: Optional[Set[str]] = Field(default=None) # TODO: GroupWorkerRole
664+
role: Optional[Set[GroupWorkerRole]] = Field(default=None)
636665
tags: Optional[Set[str]] = Field(default=None)
637666
creator_username: Optional[str] = Field(default=None)
638667
count: bool = Field(default=False)
639668

640669
@field_serializer("role")
641-
def serialize_role(self, role: Optional[Set[str]]):
670+
def serialize_role(self, role: Optional[Set[GroupWorkerRole]]):
642671
return list(role) if role else None
643672

644673
@field_validator("role", mode="before")
645674
@classmethod
646-
def deserialize_role(cls, role: Optional[list[str]]):
675+
def deserialize_role(cls, role: Optional[list[GroupWorkerRole]]):
647676
return set(role) if role else None
648677

649678
@field_serializer("tags")
@@ -667,14 +696,12 @@ class GroupQueryInfo(BaseAPIModel):
667696
creator_username: str
668697
created_at: datetime
669698
updated_at: datetime
670-
state: str # TODO: GroupState
699+
state: GroupState
671700
task_count: int
672701
storage_quota: int
673702
storage_used: int
674703
worker_count: int
675-
users_in_group: Optional[Dict[str, str]] = Field(
676-
default=None
677-
) # TODO: UserGroupRole
704+
users_in_group: Optional[Dict[str, UserGroupRole]] = Field(default=None)
678705

679706
@field_validator("created_at", mode="before")
680707
@classmethod
@@ -696,7 +723,7 @@ def serialize_updated_at(self, updated_at: datetime):
696723

697724

698725
class GroupsQueryResp(BaseAPIModel):
699-
groups: Dict[str, str] # TODO: UserGroupRole
726+
groups: Dict[str, UserGroupRole]
700727

701728

702729
class AttachmentQueryInfo(BaseAPIModel):
@@ -790,7 +817,7 @@ def deserialize_tags(cls, tags: list[str]):
790817

791818

792819
class UpdateGroupWorkerRoleReq(BaseAPIModel):
793-
relations: Dict[str, str] # TODO: GroupWorkerRole
820+
relations: Dict[str, GroupWorkerRole]
794821

795822

796823
class RemoveGroupWorkerRoleReq(BaseAPIModel):
@@ -807,7 +834,7 @@ def deserialize_groups(cls, groups: list[str]):
807834

808835

809836
class UpdateUserGroupRoleReq(BaseAPIModel):
810-
relations: Dict[str, str] # TODO: UserGroupRole
837+
relations: Dict[str, UserGroupRole]
811838

812839

813840
class RemoveUserGroupRoleReq(BaseAPIModel):

0 commit comments

Comments
 (0)