bkflow-sdk 0.0.28__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.
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.28"
@@ -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,342 @@
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}/sdk/template/{template_id}/release_template/",
300
+ description="发布模板",
301
+ token_required=True,
302
+ )
303
+ self.rollback_template = (
304
+ RequestAPI(
305
+ client=self.client,
306
+ method="POST",
307
+ host=self.host,
308
+ path="/{stage}/sdk/template/{template_id}/rollback_template/",
309
+ description="回滚模板",
310
+ token_required=True,
311
+ ),
312
+ )
313
+ self.preview_task_tree = (
314
+ RequestAPI(
315
+ client=self.client,
316
+ method="POST",
317
+ host=self.host,
318
+ path="/{stage}/sdk/template/{template_id}/preview_task_tree/",
319
+ description="预览任务树",
320
+ token_required=True,
321
+ ),
322
+ )
323
+ self.list_snapshot = (
324
+ RequestAPI(
325
+ client=self.client,
326
+ method="GET",
327
+ host=self.host,
328
+ path="/{stage}/sdk/template/snapshot/list_snapshot/",
329
+ description="获取模板快照列表",
330
+ token_required=True,
331
+ ),
332
+ )
333
+ self.delete_snapshot = (
334
+ RequestAPI(
335
+ client=self.client,
336
+ method="POST",
337
+ host=self.host,
338
+ path="/{stage}/sdk/template/snapshot/{snapshot_id}/delete_snapshot/",
339
+ description="删除模板快照",
340
+ token_required=True,
341
+ ),
342
+ )
bkflow/client/base.py ADDED
@@ -0,0 +1,104 @@
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
+
16
+ logger = logging.getLogger(__name__)
17
+
18
+
19
+ def render_string(tmpl, context):
20
+ return tmpl.format(**context)
21
+
22
+
23
+ class RequestAPI:
24
+ """Single request api"""
25
+
26
+ HTTP_STATUS_OK = 200
27
+
28
+ def __init__(self, client, method, host=None, path=None, description="", token_required=False):
29
+ self.host = host
30
+ self.path = path
31
+ self.client = client
32
+ self.method = method
33
+ self.token_required = token_required
34
+
35
+ def __call__(self, *args, path_params=None, headers=None, **kwargs):
36
+ try:
37
+ return self._call(*args, path_params=path_params, headers=headers, **kwargs)
38
+ except APIException as e:
39
+ # Combine log message
40
+ log_message = [
41
+ e.error_message,
42
+ ]
43
+ log_message.append("url=%s" % e.url)
44
+ if e.resp:
45
+ log_message.append("content=%s" % e.resp.text)
46
+
47
+ logger.exception("\n".join(log_message))
48
+
49
+ # Try return error message from remote service
50
+ if e.resp is not None:
51
+ try:
52
+ return e.resp.json()
53
+ except Exception:
54
+ pass
55
+ return {"result": False, "message": e.error_message, "data": None}
56
+
57
+ def _call(self, *args, path_params=None, headers=None, **kwargs):
58
+ if not path_params:
59
+ path_params = {"stage": self.client.stage, "bk_apigw_ver": self.client.bk_apigw_ver}
60
+ else:
61
+ path_params.update({"stage": self.client.stage, "bk_apigw_ver": self.client.bk_apigw_ver})
62
+
63
+ params, data = {}, {}
64
+ for arg in args:
65
+ if isinstance(arg, dict):
66
+ params.update(arg)
67
+ params.update(kwargs)
68
+
69
+ if self.token_required:
70
+ if not headers or API_TOKEN_HEADER_KEY not in headers:
71
+ raise APIException(f"当前接口需要token,请在请求头中添加${API_TOKEN_HEADER_KEY}")
72
+
73
+ if self.method in ["POST", "PUT", "PATCH", "DELETE"]:
74
+ data = params
75
+ params = None
76
+ path = self.path
77
+ # Request remote server
78
+ if path_params:
79
+ try:
80
+ path = render_string(path, path_params)
81
+ except KeyError as e:
82
+ raise APIException(f"{e} is not in path_params")
83
+ url = self.host.rstrip("/") + path
84
+ try:
85
+ # Pass headers to client.request if provided
86
+ request_kwargs = {}
87
+ if headers:
88
+ request_kwargs["headers"] = headers
89
+ resp = self.client.request(method=self.method, url=url, params=params, data=data, **request_kwargs)
90
+ except Exception as e:
91
+ logger.exception("Error occurred when requesting method=%s, url=%s", self.method, url)
92
+ raise APIException("API调用出错, Exception: %s" % str(e), url=url)
93
+
94
+ # Parse result
95
+ if resp and resp.status_code != self.HTTP_STATUS_OK:
96
+ message = "请求出现错误,请求HTTP状态码:%s" % resp.status_code
97
+ raise APIException(message, resp=resp, url=url)
98
+
99
+ # Response format json or text
100
+ try:
101
+ response = resp.json()
102
+ return response
103
+ except Exception:
104
+ raise APIException("返回数据格式不正确,统一为json", resp=resp, url=url)