codosdk 1.0.18__tar.gz → 1.0.20__tar.gz
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.
- {codosdk-1.0.18 → codosdk-1.0.20}/PKG-INFO +1 -1
- {codosdk-1.0.18 → codosdk-1.0.20}/codosdk.egg-info/PKG-INFO +1 -1
- {codosdk-1.0.18 → codosdk-1.0.20}/setup.py +1 -1
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/crud_utils.py +33 -6
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/sqlalchemy_pagination.py +0 -20
- {codosdk-1.0.18 → codosdk-1.0.20}/LICENSE +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/README.md +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/codosdk.egg-info/SOURCES.txt +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/codosdk.egg-info/dependency_links.txt +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/codosdk.egg-info/requires.txt +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/codosdk.egg-info/top_level.txt +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/opssdk/__init__.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/opssdk/utils/__init__.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/pyproject.toml +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/setup.cfg +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/__init__.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/api_set.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/apis/__init__.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/apis/admin_apis.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/apis/agent_apis.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/apis/cmdb_apis.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/apis/kerrigan_apis.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/apis/mgv4_apis.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/apis/task_apis.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/application.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/base_handler.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/cache.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/cache_context.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/client.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/cloud/__init__.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/cloud/qcloud_api.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/cloud/ucloud_api.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/cloud_utils.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/configs.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/consts.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/db_context.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/error.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/fetch_coroutine.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/jwt_token.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/ldap.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/logger.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/model_utils.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/mqhelper.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/program.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/salt_api.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/tools.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/utils/__init__.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/utils/cc_crypto.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/utils/date_format.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/utils/pydantic_utils.py +0 -0
- {codosdk-1.0.18 → codosdk-1.0.20}/websdk2/web_logs.py +0 -0
|
@@ -9,7 +9,7 @@ desc : CODO SDK
|
|
|
9
9
|
import sys
|
|
10
10
|
from setuptools import setup, find_packages
|
|
11
11
|
|
|
12
|
-
VERSION = '1.0.
|
|
12
|
+
VERSION = '1.0.20'
|
|
13
13
|
|
|
14
14
|
if sys.version_info < (2, 7) or (3, 0) <= sys.version_info < (3, 6):
|
|
15
15
|
print('This program requires at least Python 2.7 or 3.6 to run.')
|
|
@@ -5,14 +5,16 @@ Author : shenshuo
|
|
|
5
5
|
Date : 2025年02月08日
|
|
6
6
|
Desc : 存储类
|
|
7
7
|
"""
|
|
8
|
-
|
|
8
|
+
import json
|
|
9
9
|
import time
|
|
10
10
|
import logging
|
|
11
11
|
from sqlalchemy import true
|
|
12
12
|
from sqlalchemy.exc import IntegrityError
|
|
13
|
+
from typing import List, Union, Optional
|
|
13
14
|
from .db_context import DBContextV2 as DBContext
|
|
14
15
|
from .utils.pydantic_utils import sqlalchemy_to_pydantic, ValidationError, PydanticDelList
|
|
15
16
|
from .sqlalchemy_pagination import paginate
|
|
17
|
+
from .model_utils import model_to_dict
|
|
16
18
|
|
|
17
19
|
|
|
18
20
|
def get_millisecond_timestamp() -> int:
|
|
@@ -32,6 +34,28 @@ class ModelCRUDView:
|
|
|
32
34
|
def prepare(self):
|
|
33
35
|
pass
|
|
34
36
|
|
|
37
|
+
@staticmethod
|
|
38
|
+
def parse_id_list(id_list: Union[str, List[int]]) -> Optional[List[int]]:
|
|
39
|
+
"""
|
|
40
|
+
解析和验证 id_list 参数。
|
|
41
|
+
"""
|
|
42
|
+
if isinstance(id_list, str):
|
|
43
|
+
try:
|
|
44
|
+
id_list = json.loads(id_list)
|
|
45
|
+
except json.JSONDecodeError as e:
|
|
46
|
+
logging.error(f"Failed to parse id_list: {e}, input: {id_list}")
|
|
47
|
+
return None
|
|
48
|
+
if isinstance(id_list, list):
|
|
49
|
+
try:
|
|
50
|
+
# 尝试将所有元素转换为整数
|
|
51
|
+
id_list = [int(i) for i in id_list]
|
|
52
|
+
return id_list
|
|
53
|
+
except Exception as e:
|
|
54
|
+
logging.error(f"Invalid id_list element: {e}, input: {id_list}")
|
|
55
|
+
return None
|
|
56
|
+
logging.error(f"Invalid id_list format: {id_list}")
|
|
57
|
+
return None
|
|
58
|
+
|
|
35
59
|
@staticmethod
|
|
36
60
|
def del_data(data) -> dict:
|
|
37
61
|
for key in ['_index', '_rowKey', 'update_time']:
|
|
@@ -53,7 +77,7 @@ class ModelCRUDView:
|
|
|
53
77
|
msg='获取成功',
|
|
54
78
|
reason="",
|
|
55
79
|
timestamp=get_millisecond_timestamp(),
|
|
56
|
-
data={'item': _info
|
|
80
|
+
data={'item': model_to_dict(_info)}
|
|
57
81
|
)
|
|
58
82
|
except Exception as e:
|
|
59
83
|
logging.error(f"Database query failed: {e}")
|
|
@@ -81,8 +105,8 @@ class ModelCRUDView:
|
|
|
81
105
|
try:
|
|
82
106
|
# 调用 get_by_val_func 生成过滤条件
|
|
83
107
|
filter_condition = get_by_val_func(value)
|
|
84
|
-
if not isinstance(filter_condition, (bool, type(true()))):
|
|
85
|
-
|
|
108
|
+
# if not isinstance(filter_condition, (bool, type(true()))):
|
|
109
|
+
# raise ValueError("The `get_by_val_func` must return a SQLAlchemy filter condition or a boolean.")
|
|
86
110
|
|
|
87
111
|
except Exception as e:
|
|
88
112
|
raise ValueError(f"Error while executing `get_by_val_func`: {e}")
|
|
@@ -90,8 +114,10 @@ class ModelCRUDView:
|
|
|
90
114
|
try:
|
|
91
115
|
with DBContext('r') as session:
|
|
92
116
|
query = session.query(self.model).filter(filter_condition).filter_by(**filter_map)
|
|
93
|
-
|
|
117
|
+
id_list = self.parse_id_list(id_list)
|
|
118
|
+
if id_list:
|
|
94
119
|
query = query.filter(self.model.id.in_(id_list))
|
|
120
|
+
|
|
95
121
|
page = paginate(query, **params)
|
|
96
122
|
except Exception as e:
|
|
97
123
|
return dict(code=2, msg='查询失败', data=None, reason=str(e), timestamp=get_millisecond_timestamp())
|
|
@@ -103,7 +129,6 @@ class ModelCRUDView:
|
|
|
103
129
|
timestamp=get_millisecond_timestamp(),
|
|
104
130
|
data={
|
|
105
131
|
'items': page.items,
|
|
106
|
-
'current_page': page.page, # 当前页
|
|
107
132
|
'total_pages': page.pages, # 总页数
|
|
108
133
|
'count': page.total # 总数
|
|
109
134
|
}
|
|
@@ -117,6 +142,8 @@ class ModelCRUDView:
|
|
|
117
142
|
except ValidationError as e:
|
|
118
143
|
return dict(code=-1, msg='数据格式出错', reason=str(e), data=None, timestamp=get_millisecond_timestamp())
|
|
119
144
|
|
|
145
|
+
data.pop("id", None)
|
|
146
|
+
|
|
120
147
|
try:
|
|
121
148
|
with DBContext('w', None, True) as db:
|
|
122
149
|
__record = self.model(**data)
|
|
@@ -28,26 +28,6 @@ class Page(object):
|
|
|
28
28
|
self.pages = int(math.ceil(total / float(page_size)))
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
# def paginate(query, order_by: str = None, **query_params):
|
|
32
|
-
# page = int(query_params.get('page', 1)) if 'page' in query_params else int(query_params.get('page_number', 1))
|
|
33
|
-
# page_size = int(query_params.get('limit')) if 'limit' in query_params else int(query_params.get('page_size', 10))
|
|
34
|
-
#
|
|
35
|
-
# if 'order_by' in query_params: order_by = query_params.get('order_by')
|
|
36
|
-
# items_not_to_list = query_params.get('items_not_to_list') # 如果不序列化要额外加参数,主要为了连表查询
|
|
37
|
-
#
|
|
38
|
-
# if page <= 0: raise AttributeError('page needs to be >= 1')
|
|
39
|
-
# if page_size <= 0: raise AttributeError('page_size needs to be >= 1')
|
|
40
|
-
# if order_by:
|
|
41
|
-
# items = query.order_by(order_by).all() if page_size >= 200 else query.order_by(order_by).limit(
|
|
42
|
-
# page_size).offset((page - 1) * page_size).all()
|
|
43
|
-
# else:
|
|
44
|
-
# items = query.all() if page_size >= 200 else query.limit(page_size).offset((page - 1) * page_size).all()
|
|
45
|
-
#
|
|
46
|
-
# total = query.order_by(order_by).count()
|
|
47
|
-
# if not items_not_to_list: items = queryset_to_list(items)
|
|
48
|
-
# return Page(items, page, page_size, total)
|
|
49
|
-
|
|
50
|
-
|
|
51
31
|
def paginate(query, order_by: str = None, **query_params):
|
|
52
32
|
page = int(query_params.get('page', 1)) if 'page' in query_params else int(query_params.get('page_number', 1))
|
|
53
33
|
page_size = int(query_params.get('limit')) if 'limit' in query_params else int(query_params.get('page_size', 10))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|