dts-dance 0.1.5__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.
@@ -1,10 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dts-dance
3
- Version: 0.1.5
3
+ Version: 0.1.7
4
4
  Summary: dts dance lib
5
5
  Keywords: observation,tools
6
6
  Requires-Python: >=3.12
7
7
  Requires-Dist: loguru==0.7.3
8
+ Requires-Dist: pyyaml==6.0.3
8
9
  Requires-Dist: requests==2.32.5
9
10
  Description-Content-Type: text/markdown
10
11
 
@@ -1,12 +1,13 @@
1
1
  dtsdance/__init__.py,sha256=Yl_jEZ5weYfcrklnDvwB4wSgCOvMBLRRgWx0gHs3qfM,49
2
- dtsdance/bytecloud.py,sha256=_1CCzzSaWGwTxrdyXCYGa-c_EcJnYtwmaeGcafjLP-M,4684
3
- dtsdance/dflow.py,sha256=Ri2DFkitwwmnAUHUDseGfZIqFoTFbszqJ3jHX_CxRRc,3500
2
+ dtsdance/bytecloud.py,sha256=joixJEQxX9k3VqFDNrccTVSI2WVdxdZ1JyuWFVF9zjo,4998
3
+ dtsdance/dflow.py,sha256=pLhx9G3YTiCrz8VcycyTMedREShWN4RsxDmaRTwRhdA,3649
4
4
  dtsdance/dsyncer.py,sha256=1OateZLGekYP_EF9_oAHqsj4sdQm6ahIoRllEgT9Y3I,11142
5
5
  dtsdance/feishu_base.py,sha256=2j4ZM4PFqJ-9EhC6DQ1OmAg--3VBGZyyRuxyjL0j6OU,3733
6
6
  dtsdance/feishu_table.py,sha256=ZUeoKrM4nmm5hFhc3vWOVYeLP390orm-284Od92G4iQ,8424
7
7
  dtsdance/metrics_fe.py,sha256=uPdbjGaaYBOv-rK7lKUx6aVT5Sj6ZkW9m06NyqMrPf0,18990
8
8
  dtsdance/s3.py,sha256=EMY5uDnqRUuHnZQBkquLdQjLR5I51LuCpCPNsDz0Z0w,1340
9
9
  dtsdance/spacex.py,sha256=wgbuwDTLXopJnLn2puX-9MfeVXvi_nQ3C9uN8McoJf4,2113
10
- dts_dance-0.1.5.dist-info/METADATA,sha256=0PzqOGQYVgT3OFxcLnUqB5a5FdTUkn1R6VUyCBFrVJM,706
11
- dts_dance-0.1.5.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
12
- dts_dance-0.1.5.dist-info/RECORD,,
10
+ dtsdance/tcc.py,sha256=M_0cOVYyvUgjnC1uKWdz3YgRplafQUqX39gX_YEg8eE,6563
11
+ dts_dance-0.1.7.dist-info/METADATA,sha256=u1kzvSXzkE4j1olIgqAz3uXYSy8ZU2xIAcMt2sOUliQ,735
12
+ dts_dance-0.1.7.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
13
+ dts_dance-0.1.7.dist-info/RECORD,,
dtsdance/bytecloud.py CHANGED
@@ -100,9 +100,14 @@ class ByteCloudHelper:
100
100
  # 发送 GET 请求
101
101
  response = requests.get(url, headers=headers, timeout=60)
102
102
 
103
+ # 调试用途,输出返回内容,保存内容到本地文件
104
+ # logger.debug(f"获取JWT令牌响应: response.text={response.text}")
105
+ # with open("jwt_response.html", "w", encoding="utf-8") as f:
106
+ # f.write(response.text)
107
+
103
108
  # 检查响应状态码
104
109
  if response.status_code != 200:
105
- raise Exception(f"获取JWT令牌失败: 状态码 {response.status_code}")
110
+ raise Exception(f"获取JWT令牌失败。status_code: {response.status_code}, response.text: {response.text}")
106
111
 
107
112
  # 解析响应体
108
113
  response_json = response.json()
dtsdance/dflow.py CHANGED
@@ -69,7 +69,8 @@ class DFlowHelper:
69
69
  dict[str, Any]: DFlow 任务信息,包含 create_time 等字段
70
70
  """
71
71
  # 构建 API URL
72
- url = "https://cloud.bytedance.net/api/v1/bytedts/api/bytedts/v3/DescribeTaskInfo"
72
+ env_info = self.bytecloud_helper.get_env_info(env)
73
+ url = f"{env_info.endpoint}/api/v1/bytedts/api/bytedts/v3/DescribeTaskInfo"
73
74
 
74
75
  # 准备请求头
75
76
  headers = self._build_headers(env)
@@ -88,6 +89,7 @@ class DFlowHelper:
88
89
  filtered_data = {
89
90
  "task_id": task.get("id", ""),
90
91
  "status": task.get("status", ""),
92
+ "desc": task.get("desc", ""),
91
93
  "create_time": task.get("create_time", 0),
92
94
  }
93
95
 
@@ -108,4 +110,5 @@ class DFlowHelper:
108
110
  str: DFlow 任务详情页面的 URL
109
111
  """
110
112
  # 根据环境生成对应的 scope 参数
111
- return f"https://cloud.bytedance.net/bytedts/datasync/detail/{task_id}?scope={env}"
113
+ env_info = self.bytecloud_helper.get_env_info(env)
114
+ return f"{env_info.endpoint}/bytedts/datasync/detail/{task_id}?scope={env}"
dtsdance/tcc.py ADDED
@@ -0,0 +1,234 @@
1
+ """TCE (Toutiao Cloud Engine) API client."""
2
+
3
+ from dataclasses import dataclass
4
+ from typing import Any
5
+ import requests
6
+
7
+
8
+ @dataclass
9
+ class TCCConfigItem:
10
+ """Single TCC configuration item."""
11
+
12
+ conf_name: str
13
+ value: str
14
+ description: str
15
+ data_type: str
16
+
17
+
18
+ class TCCError(Exception):
19
+ """TCC API error."""
20
+
21
+ pass
22
+
23
+
24
+ class TCCClient:
25
+ """Client for TCC OpenAPI."""
26
+
27
+ def __init__(self, svc_account: str, svc_secret: str, base_url: str):
28
+ self.svc_account = svc_account
29
+ self.base_url = base_url
30
+ self.headers = {
31
+ "Authorization": f"Bearer {svc_secret}",
32
+ }
33
+
34
+ def publish_config(
35
+ self,
36
+ ns_name: str,
37
+ region: str,
38
+ conf_name: str,
39
+ value: str,
40
+ dir: str,
41
+ description: str,
42
+ data_type: str,
43
+ ) -> dict[str, Any]:
44
+ """
45
+ Create or update TCC configuration.
46
+
47
+ Returns:
48
+ Response data containing config_id and deployment_id
49
+
50
+ Raises:
51
+ TCCError: If API call fails
52
+ """
53
+ url = f"{self.base_url}/api/v1/tcc_v3_openapi/bcc/open/config/update"
54
+
55
+ payload = {
56
+ "ns_name": ns_name,
57
+ "dir": dir,
58
+ "conf_name": conf_name,
59
+ "value": str(value),
60
+ "data_type": data_type,
61
+ "region": region,
62
+ "description": description,
63
+ "operator": self.svc_account,
64
+ "update_strategy": "modify_and_deploy",
65
+ "auto_create": "auto_create_dir_config", # 自动创建还未存在的目录和配置
66
+ }
67
+
68
+ try:
69
+ # print(f"writing tcc config, payload: {payload}")
70
+ response = requests.post(url, headers=self.headers, json=payload, timeout=30)
71
+ if response.status_code != 200:
72
+ raise TCCError(f"TCC API request failed with status {response.status_code}\n" f"Response: {response.text}")
73
+
74
+ result = response.json()
75
+
76
+ # Check for errors in response
77
+ base_resp = result.get("base_resp", {})
78
+ if base_resp.get("error_code", 0) != 0:
79
+ raise TCCError(f"TCC API error: {base_resp.get('error_message', 'Unknown error')}")
80
+
81
+ return result.get("data", {})
82
+
83
+ except requests.RequestException as e:
84
+ raise TCCError(f"Failed to create TCC config: {str(e)}") from e
85
+
86
+ def _list(
87
+ self,
88
+ ns_name: str,
89
+ region: str,
90
+ dir: str,
91
+ page: int = 1,
92
+ page_size: int = 100,
93
+ with_value: bool = True,
94
+ ) -> dict[str, Any]:
95
+ """
96
+ List TCC configurations.
97
+
98
+ Args:
99
+ ns_name: Namespace name
100
+ region: Region (default: "China-BOE")
101
+ dir: Directory path (default: "/default")
102
+ page: Page number (default: 1)
103
+ page_size: Page size (default: 100)
104
+
105
+ Returns:
106
+ Configuration data
107
+
108
+ Raises:
109
+ TCCError: If API call fails
110
+ """
111
+ url = f"{self.base_url}/api/v1/tcc_v3_openapi/bcc/open/config/list"
112
+
113
+ params = {
114
+ "ns_name": ns_name,
115
+ "dir": dir,
116
+ "region": region,
117
+ "with_value": with_value,
118
+ "page": page,
119
+ "page_size": page_size,
120
+ }
121
+
122
+ try:
123
+ response = requests.post(url, headers=self.headers, params=params, timeout=30)
124
+ response.raise_for_status()
125
+ result = response.json()
126
+
127
+ # Check for errors in response
128
+ base_resp = result.get("base_resp", {})
129
+ if base_resp.get("error_code", 0) != 0:
130
+ raise TCCError(f"TCC API error: {base_resp.get('error_message', 'Unknown error')}")
131
+
132
+ return result
133
+
134
+ except requests.RequestException as e:
135
+ raise TCCError(f"Failed to get TCC config: {str(e)}") from e
136
+
137
+ def list_all(
138
+ self,
139
+ ns_name: str,
140
+ region: str,
141
+ dir: str,
142
+ with_value: bool = True,
143
+ ) -> list[dict[str, Any]]:
144
+ """
145
+ List all TCC configurations across all pages.
146
+
147
+ Args:
148
+ ns_name: Namespace name
149
+ region: Region (default: "China-BOE")
150
+ dir: Directory path (default: "/default")
151
+
152
+ Returns:
153
+ List of all configuration items
154
+
155
+ Raises:
156
+ TCCError: If API call fails
157
+ """
158
+ all_items = []
159
+ page = 1
160
+ page_size = 100
161
+
162
+ while True:
163
+ result = self._list(region=region, ns_name=ns_name, dir=dir, page=page, page_size=page_size, with_value=with_value)
164
+
165
+ # Extract items from current page
166
+ data = result.get("data", {})
167
+ items = data.get("items", [])
168
+ all_items.extend(items)
169
+
170
+ # Check if there are more pages
171
+ page_info = result.get("page_info", {})
172
+ total_page = page_info.get("total_page", 1)
173
+
174
+ if page >= total_page:
175
+ break
176
+
177
+ page += 1
178
+
179
+ return all_items
180
+
181
+ def list_all_names(
182
+ self,
183
+ ns_name: str,
184
+ region: str,
185
+ dir: str,
186
+ ) -> list[str]:
187
+ items = self.list_all(ns_name, region, dir, False)
188
+ return [item.get("conf_name", "") for item in items]
189
+
190
+ def get_config(
191
+ self,
192
+ ns_name: str,
193
+ region: str,
194
+ conf_name: str,
195
+ dir: str,
196
+ ) -> dict[str, Any]:
197
+ """
198
+ Get TCC configuration.
199
+
200
+ Args:
201
+ ns_name: Namespace name
202
+ region: Region (default: "China-BOE")
203
+ conf_name: Configuration name
204
+ dir: Directory path (default: "/default")
205
+
206
+ Returns:
207
+ Configuration data
208
+
209
+ Raises:
210
+ TCCError: If API call fails
211
+ """
212
+ url = f"{self.base_url}/api/v1/tcc_v3_openapi/bcc/open/config/get"
213
+
214
+ params = {
215
+ "ns_name": ns_name,
216
+ "dir": dir,
217
+ "region": region,
218
+ "conf_name": conf_name,
219
+ }
220
+
221
+ try:
222
+ response = requests.get(url, headers=self.headers, params=params, timeout=30)
223
+ response.raise_for_status()
224
+ result = response.json()
225
+
226
+ # Check for errors in response
227
+ base_resp = result.get("base_resp", {})
228
+ if base_resp.get("error_code", 0) != 0:
229
+ raise TCCError(f"TCC API error: {base_resp.get('error_message', 'Unknown error')}")
230
+
231
+ return result.get("data", {})
232
+
233
+ except requests.RequestException as e:
234
+ raise TCCError(f"Failed to get TCC config: {str(e)}") from e