bkflow-sdk 0.0.42__py2.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.

Potentially problematic release.


This version of bkflow-sdk might be problematic. Click here for more details.

bkflow/__init__.py ADDED
@@ -0,0 +1,11 @@
1
+ """
2
+ Tencent is pleased to support the open source community by making 蓝鲸智云 - PaaS平台 (BlueKing - PaaS System) available.
3
+ Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved.
4
+ Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://opensource.org/licenses/MIT
7
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9
+ specific language governing permissions and limitations under the License.
10
+ """
11
+ __version__ = "0.0.42"
@@ -0,0 +1,10 @@
1
+ """
2
+ Tencent is pleased to support the open source community by making 蓝鲸智云 - PaaS平台 (BlueKing - PaaS System) available.
3
+ Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved.
4
+ Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://opensource.org/licenses/MIT
7
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9
+ specific language governing permissions and limitations under the License.
10
+ """
@@ -0,0 +1,10 @@
1
+ """
2
+ Tencent is pleased to support the open source community by making 蓝鲸智云 - PaaS平台 (BlueKing - PaaS System) available.
3
+ Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved.
4
+ Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://opensource.org/licenses/MIT
7
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9
+ specific language governing permissions and limitations under the License.
10
+ """
@@ -0,0 +1,348 @@
1
+ """
2
+ TencentBlueKing is pleased to support the open source community by making
3
+ 蓝鲸流程引擎服务 (BlueKing Flow Engine Service) available.
4
+ Copyright (C) 2024 THL A29 Limited,
5
+ a Tencent company. All rights reserved.
6
+ Licensed under the MIT License (the "License");
7
+ you may not use this file except in compliance with the License.
8
+ You may obtain a copy of the License at http://opensource.org/licenses/MIT
9
+ Unless required by applicable law or agreed to in writing,
10
+ software distributed under the License is distributed on
11
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12
+ either express or implied. See the License for the
13
+ specific language governing permissions and limitations under the License.
14
+
15
+ We undertake not to change the open source license (MIT license) applicable
16
+
17
+ to the current version of the project delivered to anyone in the future.
18
+ """
19
+
20
+ from bkflow.config.default import bkflow_sdk_settings
21
+
22
+ from ..base import RequestAPI
23
+
24
+
25
+ class CollectionsBKFlow:
26
+ def __init__(self, client):
27
+ self.client = client
28
+ self.host = bkflow_sdk_settings.BKFLOW_SDK_APIGW_HOST
29
+ self.apply_token = RequestAPI(
30
+ client=self.client,
31
+ method="POST",
32
+ host=self.host,
33
+ path="/{stage}/space/{space_id}/apply_token/",
34
+ description="申请访问token",
35
+ )
36
+ self.admin_create_template = RequestAPI(
37
+ client=self.client,
38
+ method="POST",
39
+ host=self.host,
40
+ path="/{stage}/sdk/template/admin/create_default_template/{space_id}/",
41
+ description="Admin创建流程",
42
+ )
43
+ self.create_template = RequestAPI(
44
+ client=self.client,
45
+ method="POST",
46
+ host=self.host,
47
+ path="/{stage}/space/{space_id}/create_template/",
48
+ description="后台创建流程",
49
+ )
50
+ self.copy_template = RequestAPI(
51
+ client=self.client,
52
+ method="POST",
53
+ host=self.host,
54
+ path="/{stage}/sdk/template/admin/template_copy/",
55
+ description="创建流程",
56
+ )
57
+ self.list_templates = RequestAPI(
58
+ client=self.client,
59
+ method="GET",
60
+ host=self.host,
61
+ path="/{stage}/space/{space_id}/get_template_list/",
62
+ description="获取模板列表",
63
+ )
64
+ self.fetch_template = RequestAPI(
65
+ client=self.client,
66
+ method="GET",
67
+ host=self.host,
68
+ path="/{stage}/sdk/template/{template_id}/",
69
+ description="获取流程详情",
70
+ token_required=True,
71
+ )
72
+ self.update_template = RequestAPI(
73
+ client=self.client,
74
+ method="PUT",
75
+ host=self.host,
76
+ path="/{stage}/sdk/template/{template_id}/",
77
+ description="更新模板",
78
+ token_required=True,
79
+ )
80
+ self.delete_template = RequestAPI(
81
+ client=self.client,
82
+ method="POST",
83
+ host=self.host,
84
+ path="/{stage}/space/{space_id}/delete_template/{template_id}/",
85
+ description="删除模板",
86
+ )
87
+ self.system_variables = RequestAPI(
88
+ client=self.client,
89
+ method="GET",
90
+ host=self.host,
91
+ path="/{stage}/sdk/template/variable/system_variable/",
92
+ description="获取系统变量",
93
+ token_required=True,
94
+ )
95
+ self.get_space_related_configs = RequestAPI(
96
+ client=self.client,
97
+ method="GET",
98
+ host=self.host,
99
+ path="/{stage}/sdk/template/{template_id}/get_space_related_configs/",
100
+ description="获取空间相关配置",
101
+ token_required=True,
102
+ )
103
+ self.list_inner_plugins = RequestAPI(
104
+ client=self.client,
105
+ method="GET",
106
+ host=self.host,
107
+ path="/{stage}/sdk/plugin/",
108
+ description="获取插件",
109
+ token_required=True,
110
+ )
111
+ self.get_inner_plugin_detail = RequestAPI(
112
+ client=self.client,
113
+ method="GET",
114
+ host=self.host,
115
+ path="/{stage}/sdk/plugin/{code}/",
116
+ description="获取插件详情",
117
+ token_required=True,
118
+ )
119
+ self.list_plugin_tags = RequestAPI(
120
+ client=self.client,
121
+ method="GET",
122
+ host=self.host,
123
+ path="/{stage}/sdk/plugin_service/tags/",
124
+ description="获取第三方插件Tags",
125
+ )
126
+ self.list_plugin = RequestAPI(
127
+ client=self.client,
128
+ method="GET",
129
+ host=self.host,
130
+ path="/{stage}/sdk/bk_plugin/",
131
+ description="获取第三方插件",
132
+ )
133
+ self.get_plugin_meta = RequestAPI(
134
+ client=self.client,
135
+ method="GET",
136
+ host=self.host,
137
+ path="/{stage}/sdk/plugin_service/meta/",
138
+ description="获取第三方插件元信息",
139
+ )
140
+ self.get_plugin_app_detail = RequestAPI(
141
+ client=self.client,
142
+ method="GET",
143
+ host=self.host,
144
+ path="/{stage}/sdk/plugin_service/app_detail/",
145
+ description="获取插件服务App详情",
146
+ )
147
+ self.get_service_plugin_detail = RequestAPI(
148
+ client=self.client,
149
+ method="GET",
150
+ host=self.host,
151
+ path="/{stage}/sdk/plugin_service/detail/",
152
+ description="获取第三方插件详情",
153
+ )
154
+ self.analysis_constants_ref = RequestAPI(
155
+ client=self.client,
156
+ method="POST",
157
+ host=self.host,
158
+ path="/{stage}/sdk/template/analysis_constants_ref/",
159
+ description="变量引用统计",
160
+ token_required=True,
161
+ )
162
+ self.list_decision = RequestAPI(
163
+ client=self.client,
164
+ method="GET",
165
+ host=self.host,
166
+ path="/{stage}/sdk/decision_table/user/",
167
+ description="获取用户决策表插件列表",
168
+ token_required=True,
169
+ )
170
+ self.uniform_api = RequestAPI(
171
+ client=self.client,
172
+ method="GET",
173
+ host=self.host,
174
+ path="/{stage}/sdk/plugin_query/uniform_api/category_list/{space_id}/",
175
+ description="获取uniform_api插件列表",
176
+ token_required=True,
177
+ )
178
+ self.create_task = RequestAPI(
179
+ client=self.client,
180
+ method="POST",
181
+ host=self.host,
182
+ path="/{stage}/space/{space_id}/create_task/",
183
+ description="创建任务",
184
+ )
185
+ self.front_operate_task = RequestAPI(
186
+ client=self.client,
187
+ method="POST",
188
+ host=self.host,
189
+ path="/{stage}/sdk/task/operate_task/{task_id}/{action}/",
190
+ description="操作任务",
191
+ token_required=True,
192
+ )
193
+ self.operation_record = RequestAPI(
194
+ client=self.client,
195
+ method="GET",
196
+ host=self.host,
197
+ path="/{stage}/sdk/template/{template_id}/get_template_operation_record/",
198
+ description="操作记录",
199
+ token_required=True,
200
+ )
201
+ self.variable_class_list = RequestAPI(
202
+ client=self.client,
203
+ method="GET",
204
+ host=self.host,
205
+ path="/{stage}/sdk/template/variable/",
206
+ description="自定义变量列表",
207
+ )
208
+ self.variable_class_detail = RequestAPI(
209
+ client=self.client,
210
+ method="GET",
211
+ host=self.host,
212
+ path="/{stage}/sdk/template/variable/{variable_id}/",
213
+ description="自定义变量详情",
214
+ )
215
+ self.check_variable_key = RequestAPI(
216
+ client=self.client,
217
+ method="GET",
218
+ host=self.host,
219
+ path="/{stage}/sdk/template/variable/check_variable_key/",
220
+ description="检查变量key是否规范合法",
221
+ )
222
+ self.get_constant_preview_result = RequestAPI(
223
+ client=self.client,
224
+ method="POST",
225
+ host=self.host,
226
+ path="/{stage}/sdk/template/variable/get_constant_preview_result/",
227
+ description="流程常量预览结果",
228
+ )
229
+ self.get_task_mock_data = RequestAPI(
230
+ client=self.client,
231
+ method="GET",
232
+ host=self.host,
233
+ path="/{stage}/sdk/task/get_task_mock_data/{task_id}/",
234
+ description="获取任务的mock数据",
235
+ token_required=True,
236
+ )
237
+ self.get_task_list = RequestAPI(
238
+ client=self.client,
239
+ method="GET",
240
+ host=self.host,
241
+ path="/{stage}/space/{space_id}/get_task_list/",
242
+ description="获取任务列表",
243
+ )
244
+ self.get_task_states = RequestAPI(
245
+ client=self.client,
246
+ method="GET",
247
+ host=self.host,
248
+ path="/{stage}/space/{space_id}/task/{task_id}/get_task_states/",
249
+ description="获取任务状态",
250
+ )
251
+ self.get_task_detail = RequestAPI(
252
+ client=self.client,
253
+ method="GET",
254
+ host=self.host,
255
+ path="/{stage}/space/{space_id}/task/{task_id}/get_task_detail/",
256
+ description="获取任务详情",
257
+ )
258
+ self.get_tasks_states = RequestAPI(
259
+ client=self.client,
260
+ method="POST",
261
+ host=self.host,
262
+ path="/{stage}/space/{space_id}/get_tasks_states/",
263
+ description="批量获取任务状态",
264
+ )
265
+ self.get_template_detail = RequestAPI(
266
+ client=self.client,
267
+ method="GET",
268
+ host=self.host,
269
+ path="/{stage}/space/{space_id}/template/{template_id}/get_template_detail/",
270
+ description="获取模板详情",
271
+ )
272
+ self.operate_task = RequestAPI(
273
+ client=self.client,
274
+ method="POST",
275
+ host=self.host,
276
+ path="/{stage}/space/{space_id}/task/{task_id}/operate_task/{operation}/",
277
+ description="操作任务",
278
+ )
279
+ self.get_draft_template = RequestAPI(
280
+ client=self.client,
281
+ method="GET",
282
+ host=self.host,
283
+ path="/{stage}/sdk/template/{template_id}/get_draft_template/",
284
+ description="获取草稿模板",
285
+ token_required=True,
286
+ )
287
+ self.calculate_version = RequestAPI(
288
+ client=self.client,
289
+ method="GET",
290
+ host=self.host,
291
+ path="/{stage}/sdk/template/{template_id}/calculate_version/",
292
+ description="计算版本号",
293
+ token_required=True,
294
+ )
295
+ self.release_template = RequestAPI(
296
+ client=self.client,
297
+ method="POST",
298
+ host=self.host,
299
+ path="/{stage}/space/{space_id}/template/{template_id}/release_template/",
300
+ description="发布模板",
301
+ )
302
+ self.front_release_template = RequestAPI(
303
+ client=self.client,
304
+ method="POST",
305
+ host=self.host,
306
+ path="/{stage}/sdk/template/{template_id}/release_template/",
307
+ description="发布模板(用于画布对接)",
308
+ token_required=True,
309
+ )
310
+ self.rollback_template = RequestAPI(
311
+ client=self.client,
312
+ method="POST",
313
+ host=self.host,
314
+ path="/{stage}/space/{space_id}/template/{template_id}/rollback_template/",
315
+ description="回滚模板",
316
+ )
317
+ self.front_rollback_template = RequestAPI(
318
+ client=self.client,
319
+ method="POST",
320
+ host=self.host,
321
+ path="/{stage}/sdk/template/{template_id}/rollback_template/",
322
+ description="回滚模板(用于画布对接)",
323
+ token_required=True,
324
+ )
325
+ self.preview_task_tree = RequestAPI(
326
+ client=self.client,
327
+ method="POST",
328
+ host=self.host,
329
+ path="/{stage}/sdk/template/{template_id}/preview_task_tree/",
330
+ description="预览任务树",
331
+ token_required=True,
332
+ )
333
+ self.list_snapshot = RequestAPI(
334
+ client=self.client,
335
+ method="GET",
336
+ host=self.host,
337
+ path="/{stage}/sdk/template/snapshot/list_snapshot/",
338
+ description="获取模板快照列表",
339
+ token_required=True,
340
+ )
341
+ self.delete_snapshot = RequestAPI(
342
+ client=self.client,
343
+ method="POST",
344
+ host=self.host,
345
+ path="/{stage}/sdk/template/snapshot/{snapshot_id}/delete_snapshot/",
346
+ description="删除模板快照",
347
+ token_required=True,
348
+ )
bkflow/client/base.py ADDED
@@ -0,0 +1,124 @@
1
+ """
2
+ Tencent is pleased to support the open source community by making 蓝鲸智云 - PaaS平台 (BlueKing - PaaS System) available.
3
+ Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved.
4
+ Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://opensource.org/licenses/MIT
7
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9
+ specific language governing permissions and limitations under the License.
10
+ """
11
+ import logging
12
+
13
+ from bkflow.common.exceptions import APIException
14
+ from bkflow.config.default import API_TOKEN_HEADER_KEY
15
+ from bkflow.interface.utils import get_space_id
16
+
17
+ logger = logging.getLogger(__name__)
18
+
19
+
20
+ def render_string(tmpl, context):
21
+ return tmpl.format(**context)
22
+
23
+
24
+ class RequestAPI:
25
+ """Single request api"""
26
+
27
+ HTTP_STATUS_OK = 200
28
+
29
+ def __init__(self, client, method, host=None, path=None, description="", token_required=False):
30
+ self.host = host
31
+ self.path = path
32
+ self.client = client
33
+ self.method = method
34
+ self.token_required = token_required
35
+
36
+ def __call__(self, *args, path_params=None, headers=None, **kwargs):
37
+ try:
38
+ return self._call(*args, path_params=path_params, headers=headers, **kwargs)
39
+ except APIException as e:
40
+ # Combine log message
41
+ log_message = [
42
+ e.error_message,
43
+ ]
44
+ log_message.append("url=%s" % e.url)
45
+ if e.resp:
46
+ log_message.append("content=%s" % e.resp.text)
47
+
48
+ logger.exception("\n".join(log_message))
49
+
50
+ # Try return error message from remote service
51
+ if e.resp is not None:
52
+ try:
53
+ return e.resp.json()
54
+ except Exception:
55
+ pass
56
+ return {"result": False, "message": e.error_message, "data": None}
57
+
58
+ def _call(self, *args, path_params=None, headers=None, space_id=None, **kwargs):
59
+ if not path_params:
60
+ path_params = {"stage": self.client.stage, "bk_apigw_ver": self.client.bk_apigw_ver}
61
+ else:
62
+ path_params.update({"stage": self.client.stage, "bk_apigw_ver": self.client.bk_apigw_ver})
63
+
64
+ params, data = {}, {}
65
+ for arg in args:
66
+ if isinstance(arg, dict):
67
+ params.update(arg)
68
+ params.update(kwargs)
69
+
70
+ # 获取 space_id(如果未通过关键字参数传递,则自动获取)
71
+ space_id = params.get("space_id") or path_params.get("space_id")
72
+ if space_id is None:
73
+ # 尝试从 params 中获取 scope_type 和 scope_value
74
+ scope_type = params.get("scope_type")
75
+ scope_value = params.get("scope_value")
76
+ space_id = get_space_id(scope_type=scope_type, scope_value=scope_value)
77
+
78
+ # 如果路径中包含 {space_id},添加到 path_params
79
+ if "{space_id}" in self.path and "space_id" not in path_params:
80
+ path_params["space_id"] = space_id
81
+
82
+ if self.token_required:
83
+ if not headers or API_TOKEN_HEADER_KEY not in headers:
84
+ raise APIException(f"当前接口需要token,请在请求头中添加${API_TOKEN_HEADER_KEY}")
85
+
86
+ if self.method in ["POST", "PUT", "PATCH", "DELETE"]:
87
+ data = params
88
+ params = None
89
+ # 对于 POST/PUT/PATCH/DELETE 请求,如果路径中不包含 {space_id},添加到 data 中
90
+ if "{space_id}" not in self.path and "space_id" not in data:
91
+ data["space_id"] = space_id
92
+ else:
93
+ # 对于 GET/HEAD 请求,如果路径中不包含 {space_id},添加到 params 中
94
+ if "{space_id}" not in self.path and "space_id" not in params:
95
+ params["space_id"] = space_id
96
+ path = self.path
97
+ # Request remote server
98
+ if path_params:
99
+ try:
100
+ path = render_string(path, path_params)
101
+ except KeyError as e:
102
+ raise APIException(f"{e} is not in path_params")
103
+ url = self.host.rstrip("/") + path
104
+ try:
105
+ # Pass headers to client.request if provided
106
+ request_kwargs = {}
107
+ if headers:
108
+ request_kwargs["headers"] = headers
109
+ resp = self.client.request(method=self.method, url=url, params=params, data=data, **request_kwargs)
110
+ except Exception as e:
111
+ logger.exception("Error occurred when requesting method=%s, url=%s", self.method, url)
112
+ raise APIException("API调用出错, Exception: %s" % str(e), url=url)
113
+
114
+ # Parse result
115
+ if resp and resp.status_code != self.HTTP_STATUS_OK:
116
+ message = "请求出现错误,请求HTTP状态码:%s" % resp.status_code
117
+ raise APIException(message, resp=resp, url=url)
118
+
119
+ # Response format json or text
120
+ try:
121
+ response = resp.json()
122
+ return response
123
+ except Exception:
124
+ raise APIException("返回数据格式不正确,统一为json", resp=resp, url=url)