mcsmapi 0.1.5b2__py3-none-any.whl → 0.1.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mcsmapi/models/user.py CHANGED
@@ -1,37 +1,44 @@
1
- from typing import Any, List
1
+ from enum import IntEnum
2
+ from typing import Any
2
3
  from pydantic import BaseModel
3
4
  from mcsmapi.models.instance import InstanceDetail, UserInstancesList
4
5
 
5
6
 
7
+ class UserPermission(IntEnum):
8
+ BANNED = -1
9
+ USER = 1
10
+ ADMIN = 10
11
+
12
+
6
13
  class UserModel(BaseModel):
7
14
  """用户信息模型"""
8
15
 
9
- """用户唯一标识符 (UUID)"""
10
16
  uuid: str = ""
11
- """用户名"""
17
+ """用户唯一标识符 (UUID)"""
12
18
  userName: str = ""
13
- """用户密码 (存储加密后的字符串)"""
19
+ """用户名"""
14
20
  passWord: str = ""
15
- """密码类型 (0=默认类型)"""
21
+ """用户密码 (存储加密后的字符串)"""
16
22
  passWordType: int = 0
17
- """密码盐值 (用于加密)"""
23
+ """密码类型 (0=默认类型)"""
18
24
  salt: str = ""
19
- """用户权限级别 (1=用户, 10=管理员, -1=被封禁的用户)"""
20
- permission: int = 1
21
- """用户注册时间 (时间字符串格式)"""
25
+ """密码盐值 (用于加密)"""
26
+ permission: UserPermission = UserPermission.USER
27
+ """用户权限级别"""
22
28
  registerTime: str = ""
23
- """用户最后登录时间 (时间字符串格式)"""
29
+ """用户注册时间 (时间字符串格式)"""
24
30
  loginTime: str = ""
25
- """用户 API 密钥"""
31
+ """用户最后登录时间 (时间字符串格式)"""
26
32
  apiKey: str = ""
27
- """是否为初始化用户 (系统内置用户)"""
33
+ """用户 API 密钥"""
28
34
  isInit: bool = False
29
- """用户安全密钥 (可能用于额外的身份验证)"""
35
+ """是否为初始化用户 (系统内置用户)"""
30
36
  secret: str = ""
31
- """是否启用双因素认证 (2FA)"""
37
+ """用户安全密钥 (可能用于额外的身份验证)"""
32
38
  open2FA: bool = False
39
+ """是否启用双因素认证 (2FA)"""
40
+ instances: list[UserInstancesList] = []
33
41
  """用户关联的实例列表"""
34
- instances: List["UserInstancesList"] = []
35
42
 
36
43
  def delete(self) -> bool:
37
44
  """
@@ -56,16 +63,16 @@ class UserModel(BaseModel):
56
63
  """
57
64
  from mcsmapi.apis.user import User
58
65
 
59
- updated_config = self.dict()
66
+ updated_config = self.model_dump()
60
67
  updated_config.update(config)
61
68
  # 过滤用户信息中不需要的字段
62
69
  user_config_dict = {
63
70
  key: updated_config[key]
64
- for key in UserConfig.__fields__.keys()
71
+ for key in UserConfig.model_fields.keys()
65
72
  if key in updated_config
66
73
  }
67
74
 
68
- user_config = UserConfig(**user_config_dict).dict()
75
+ user_config = UserConfig(**user_config_dict).model_dump()
69
76
 
70
77
  return User().update(self.uuid, user_config)
71
78
 
@@ -73,38 +80,38 @@ class UserModel(BaseModel):
73
80
  class SearchUserModel(BaseModel):
74
81
  """用户搜索结果"""
75
82
 
76
- """匹配的用户总数"""
77
83
  total: int = 0
78
- """当前页码"""
84
+ """匹配的用户总数"""
79
85
  page: int = 0
80
- """每页返回的用户数量"""
86
+ """当前页码"""
81
87
  page_size: int = 0
82
- """最大可用页数"""
88
+ """每页返回的用户数量"""
83
89
  max_page: int = 0
90
+ """最大可用页数"""
91
+ data: list[UserModel] = []
84
92
  """用户信息列表"""
85
- data: List[UserModel] = []
86
93
 
87
94
 
88
95
  class UserConfig(BaseModel):
89
96
  """用户配置信息"""
90
97
 
91
- """用户唯一标识符 (UUID)"""
92
98
  uuid: str
93
- """用户名"""
99
+ """用户唯一标识符 (UUID)"""
94
100
  userName: str
95
- """最后登录时间"""
101
+ """用户名"""
96
102
  loginTime: str
97
- """注册时间"""
103
+ """最后登录时间"""
98
104
  registerTime: str
105
+ """注册时间"""
106
+ instances: list[InstanceDetail]
99
107
  """用户拥有的实例列表"""
100
- instances: List[InstanceDetail]
101
- """用户权限级别 (1=用户, 10=管理员, -1=被封禁的用户)"""
102
- permission: int
103
- """用户 API 密钥"""
108
+ permission: UserPermission
109
+ """用户权限级别"""
104
110
  apiKey: str
105
- """是否为初始化用户 (系统内置用户)"""
111
+ """用户 API 密钥"""
106
112
  isInit: bool
107
- """用户安全密钥 (可能用于额外的身份验证)"""
113
+ """是否为初始化用户 (系统内置用户)"""
108
114
  secret: str
109
- """是否启用双因素认证 (2FA)"""
115
+ """用户安全密钥 (可能用于额外的身份验证)"""
110
116
  open2FA: bool
117
+ """是否启用双因素认证 (2FA)"""
mcsmapi/pool.py CHANGED
@@ -12,3 +12,4 @@ class ApiPool(Enum):
12
12
  SERVICE = "api/service"
13
13
  FILE = "api/files"
14
14
  IMAGE = "api/environment"
15
+ LOG = "api/overview/operation_logs"
mcsmapi/request.py CHANGED
@@ -1,59 +1,65 @@
1
1
  from typing import Any
2
2
  import requests
3
3
  import urllib.parse
4
+
5
+ from mcsmapi.pool import ApiPool
4
6
  from .exceptions import MCSMError
5
7
 
6
8
 
7
9
  class Request:
8
- mcsm_url = ""
9
- timeout = 5
10
+ mcsm_url: str = ""
11
+ timeout: int = 5
10
12
  session = requests.Session()
11
- apikey = None
12
- token = None
13
+ apikey: str | None = None
14
+ token: str | None = None
13
15
 
14
16
  @classmethod
15
- def set_mcsm_url(cls, url):
17
+ def set_mcsm_url(cls, url: str):
16
18
  """设置类级别的 mcsm_url"""
17
19
  cls.mcsm_url = url
18
20
 
19
21
  @classmethod
20
- def set_timeout(cls, timeout):
22
+ def set_timeout(cls, timeout: int):
21
23
  """设置类级别的 timeout"""
22
24
  cls.timeout = timeout
23
25
 
24
26
  @classmethod
25
- def set_apikey(cls, apikey):
27
+ def set_apikey(cls, apikey: str):
26
28
  """设置类级别的 apikey"""
27
29
  cls.apikey = apikey
28
30
 
29
31
  @classmethod
30
- def set_token(cls, token):
32
+ def set_token(cls, token: str):
31
33
  """设置类级别的 token"""
32
34
  cls.token = token
33
35
 
34
36
  @classmethod
35
- def __init__(cls, mcsm_url=None, timeout=None):
37
+ def __init__(cls, mcsm_url: str | None = None, timeout: int | None = None):
36
38
  """初始化时使用类变量,或者使用传入的参数覆盖默认值"""
37
39
  cls.mcsm_url = mcsm_url or cls.mcsm_url
38
40
  cls.timeout = timeout or cls.timeout
39
41
 
40
42
  @classmethod
41
- def send(cls, method: str, endpoint: Any, params=None, data=None) -> Any:
43
+ def send(
44
+ cls,
45
+ method: str,
46
+ endpoint: str | ApiPool,
47
+ params: dict | None = None,
48
+ data: Any | None = None,
49
+ ) -> Any:
42
50
  """发送 HTTP 请求"""
43
51
  if params is None:
44
52
  params = {}
45
53
  if data is None:
46
54
  data = {}
47
- if not isinstance(endpoint, str):
48
- endpoint = str(endpoint)
55
+ if isinstance(endpoint, ApiPool):
56
+ endpoint = endpoint.value
49
57
 
50
58
  url = urllib.parse.urljoin(cls.mcsm_url, endpoint)
51
59
  if cls.apikey is not None:
52
60
  params["apikey"] = cls.apikey
53
- data["apikey"] = cls.apikey
54
61
  if cls.token is not None:
55
62
  params["token"] = cls.token
56
- data["token"] = cls.token
57
63
 
58
64
  response = cls.session.request(
59
65
  method.upper(),
@@ -1,15 +1,17 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mcsmapi
3
- Version: 0.1.5b2
3
+ Version: 0.1.7
4
4
  Summary: Shortcut the pypi package of MCSM./快捷操作MCSM的pypi包
5
5
  Author-email: molanp <molanpp@outlook.com>
6
6
  License-Expression: MIT
7
7
  Project-URL: Source, https://github.com/molanp/mcsmapi
8
8
  Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Requires-Python: >=3.10
9
11
  Description-Content-Type: text/markdown
10
12
  License-File: LICENSE
11
13
  Requires-Dist: requests
12
- Requires-Dist: pydantic
14
+ Requires-Dist: pydantic>=2.0.0
13
15
  Dynamic: license-file
14
16
 
15
17
  # MCSM API
@@ -26,7 +28,13 @@ English|[Chinese Simplified](README_zh-cn.md)
26
28
 
27
29
  ## Documentation
28
30
 
29
- The documentation is not yet complete, if you need it, please visit [https://deepwiki.com/molanp/mcsmapi](https://deepwiki.com/molanp/mcsmapi)
31
+ The documentation is not yet complete, if you need it, please visit [deepwiki-mcsmapi](https://deepwiki.com/molanp/mcsmapi)
32
+
33
+ You can also find:
34
+
35
+ 📄 Work-in-progress docs: [docs](docs)
36
+
37
+ 💡 Example: [example](example)
30
38
 
31
39
  ## Introduction
32
40
 
@@ -43,7 +51,7 @@ pip install mcsmapi
43
51
  ```
44
52
 
45
53
  If you need the latest build files (untested), please visit
46
- [Actions](https://github.com/molanp/mcsmapi/actions)
54
+ [Actions](https://github.com/molanp/mcsmapi/actions/workflows/auto-build.yml)
47
55
 
48
56
  ## Supported Features
49
57
 
@@ -0,0 +1,24 @@
1
+ mcsmapi/__init__.py,sha256=TxBjQPMtwR_Eh0N7nZAoKinONAgnDsSbt47-cLvbeLk,1418
2
+ mcsmapi/exceptions.py,sha256=mHsAHyoX9SiFDGBMEhesA_ao9hhZZ38EGTp97K7VDp8,184
3
+ mcsmapi/pool.py,sha256=Xa1DvBdfn5zTZ-eB50BFbYxhKX8j-4vfus9QOGO_FQE,348
4
+ mcsmapi/request.py,sha256=G6O4Q3oXidmauyraUgoMTkms5XFlY-iHPhZ3s0k9TmM,2743
5
+ mcsmapi/apis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ mcsmapi/apis/daemon.py,sha256=4kGWkVHsT7wgMGaTOei3daUe8qJ3_LGJ12hjq9j6OaE,2759
7
+ mcsmapi/apis/file.py,sha256=uoO6PSlbSfleMQnopc4Ajmf_Z4dMN4IkunXBzv9rvvQ,10955
8
+ mcsmapi/apis/image.py,sha256=Onb_yciTyybB4r2TxyvW04Z6-nnTSDO2HanhtRbA3m4,2968
9
+ mcsmapi/apis/instance.py,sha256=RHvR7dyKgOlIuKbQzemWVXw17jEUmLILZ0J-gFu6538,11117
10
+ mcsmapi/apis/overview.py,sha256=MqLmEyLh3i9VsQRFn7WI_02yRBt6eqZvusOkhHFIgFw,518
11
+ mcsmapi/apis/user.py,sha256=XdoIgT9j87fhp0FPO4UusPYDPf59WlvzRaeLAdMhikM,3022
12
+ mcsmapi/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
+ mcsmapi/models/common.py,sha256=2KiqbGiBRuipIoeSNPH9_p7sGyKOy406JtBhWR4K0dQ,598
14
+ mcsmapi/models/daemon.py,sha256=FTt10oYFnGXG1WAXMJ4roPGLCX5R5U3YGIzeEu-2F4E,4344
15
+ mcsmapi/models/file.py,sha256=0BltWCHZC0Mlic1_xaPRys0HyNdKScGNxui4_tzREUI,5976
16
+ mcsmapi/models/image.py,sha256=jlEbLF6uEwBTRShOGI0vWYN7WAZyJoiMa1gw_UjKINw,5447
17
+ mcsmapi/models/instance.py,sha256=vixAknesy-lop5BI8lKIHaDsSpa5xJtycAfX3zz0PGs,8810
18
+ mcsmapi/models/overview.py,sha256=kGDvHtsur1iA0wbeT-QkZPf04wkmo6YsrFSLtGZpsd0,4583
19
+ mcsmapi/models/user.py,sha256=OnELhHdnoJYvfJUH55QwAHsZDu1vwigYIjAdbZFyMnk,3182
20
+ mcsmapi-0.1.7.dist-info/licenses/LICENSE,sha256=bMKDPsvaybvY-4TTlSZtCXPPtxb7KPpDVqXgDA8Ogo0,1068
21
+ mcsmapi-0.1.7.dist-info/METADATA,sha256=7lsyKuG4FBPFGpyb0L3CpuNcW4zvuBpPECOEjhBzZEg,2989
22
+ mcsmapi-0.1.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
+ mcsmapi-0.1.7.dist-info/top_level.txt,sha256=8MUYHd1Or4cbSCd93IaqLA72w0weEuKieopVwIfVlWo,8
24
+ mcsmapi-0.1.7.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.4.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,23 +0,0 @@
1
- mcsmapi/__init__.py,sha256=Xm0gsQMecMZwD1of9UGOkTan25l_jqrWkG-7mg0YgF4,1514
2
- mcsmapi/exceptions.py,sha256=mHsAHyoX9SiFDGBMEhesA_ao9hhZZ38EGTp97K7VDp8,184
3
- mcsmapi/pool.py,sha256=CoOYbyECp4FoXkzwFN7WgtS3vgZtvWO8e93i18vhOEI,308
4
- mcsmapi/request.py,sha256=5mCzKgrh4OPFKvBo22kIDpX_D1zqCza1nglYUeGWveg,2618
5
- mcsmapi/apis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- mcsmapi/apis/daemon.py,sha256=2Se5ViwaePg6_CGI9qKeI823FMF0qzlemn2yCt92SPs,4488
7
- mcsmapi/apis/file.py,sha256=Qh3kOtU2mj9PS2nN4s6WufZ149pM0sbkM37aG-LlY5A,10778
8
- mcsmapi/apis/image.py,sha256=UwVH2LPfPBEADZuoSyyiMrlEc9LL858Z3oidRPaKrvs,2908
9
- mcsmapi/apis/instance.py,sha256=zibACXlhsMAWW5QjvGCFO5iN0wNEVlnecdnFvLeQTUg,10986
10
- mcsmapi/apis/overview.py,sha256=4bS3RGSykdQ1JyBTM-I9na6v0SCijEG1CN-WxqabfUo,625
11
- mcsmapi/apis/user.py,sha256=CBLNWxxNfvnmzoMa1YV3Q33POitYDGyN-hRORoe2JEc,2968
12
- mcsmapi/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- mcsmapi/models/daemon.py,sha256=EV0nlUe6pUETbLIoUGn2HPWoNYClIyS2ABrRA70IjQk,5079
14
- mcsmapi/models/file.py,sha256=m75zhMkBA7KQm-870Ph3DfE9unSlOLWgMmwdl8H-vSc,6097
15
- mcsmapi/models/image.py,sha256=pjwSJ79rYMuDTLlazevpjqdnnc0Mqvea9bp-BepUhio,5484
16
- mcsmapi/models/instance.py,sha256=oNXw0q3FDTu2bG_crWPgUtLXxM2yL7eRwo9H2RFzmDA,8850
17
- mcsmapi/models/overview.py,sha256=yRERCPRA3vBceKjISBClngvmKaQlo0HowC859nm15Nc,2859
18
- mcsmapi/models/user.py,sha256=sduOS8MWoxUfvTseK7nShuBOYzei3dEM8eP45PuIZ3g,3130
19
- mcsmapi-0.1.5b2.dist-info/licenses/LICENSE,sha256=bMKDPsvaybvY-4TTlSZtCXPPtxb7KPpDVqXgDA8Ogo0,1068
20
- mcsmapi-0.1.5b2.dist-info/METADATA,sha256=IFV6TW-2aLuZydebLlPN1mSRbzsFCtRpRAbWa7kaDlc,2805
21
- mcsmapi-0.1.5b2.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
22
- mcsmapi-0.1.5b2.dist-info/top_level.txt,sha256=8MUYHd1Or4cbSCd93IaqLA72w0weEuKieopVwIfVlWo,8
23
- mcsmapi-0.1.5b2.dist-info/RECORD,,