Skip to content

Commit ab6cfaa

Browse files
authored
add stepflow sdk (#5)
FEATURE: - Add the SDK of `StepFlow` product (#5) BUGFIX: - Fix the `NoneType` error for `RetCodeException` (#5)
1 parent 06e398e commit ab6cfaa

File tree

8 files changed

+201
-2
lines changed

8 files changed

+201
-2
lines changed

ucloud/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ def pathx(self):
1414

1515
return PathXClient(self._config, self.transport, self.middleware, self.logger)
1616

17+
def stepflow(self):
18+
from ucloud.services.stepflow.client import StepFlowClient
19+
20+
return StepFlowClient(
21+
self._config, self.transport, self.middleware, self.logger
22+
)
23+
1724
def uaccount(self):
1825
from ucloud.services.uaccount.client import UAccountClient
1926

ucloud/core/client/_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def _send(self, action, args, **options):
8080
resp = handler(resp)
8181
if int(resp.get("RetCode", -1)) != 0:
8282
raise exc.RetCodeException(
83-
action=req.json.get("Action"),
83+
action=req.data.get("Action"),
8484
code=int(resp.get("RetCode")),
8585
message=resp.get("Message"),
8686
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- coding: utf-8 -*-

ucloud/services/stepflow/client.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# -*- coding: utf-8 -*-
2+
3+
""" Code is generated by ucloud-model, DO NOT EDIT IT. """
4+
from ucloud.core.client import Client
5+
from ucloud.services.stepflow.schemas import apis
6+
7+
8+
class StepFlowClient(Client):
9+
def __init__(self, config, transport=None, middleware=None, logger=None):
10+
super(StepFlowClient, self).__init__(config, transport, middleware, logger)
11+
12+
def create_sf_workflow_from_template(self, req=None, **kwargs):
13+
""" CreateSFWorkflowFromTemplate - 导入工作流定义
14+
15+
**Request**
16+
17+
- **ProjectId** (str) - (Config) 项目ID。不填写为默认项目,子帐号必须填写。 请参考 `GetProjectList接口 <https://docs.ucloud.cn/api/summary/get_project_list.html>`_
18+
- **Region** (str) - (Config) 地域。 参见 `地域和可用区列表 <https://docs.ucloud.cn/api/summary/regionlist.html>`_
19+
- **Namespace** (str) - (Required) 需要创建的工作流namespace
20+
- **Workflow** (str) - (Required) 描述工作流定义的base64字符串
21+
- **WorkflowName** (str) - (Required) 需要创建的工作流名称
22+
23+
**Response**
24+
25+
- **Message** (str) - 返回消息
26+
- **Version** (int) - 创建的工作流版本号
27+
28+
"""
29+
d = {"ProjectId": self.config.project_id, "Region": self.config.region}
30+
req and d.update(req)
31+
d = apis.CreateSFWorkflowFromTemplateRequestSchema().dumps(d)
32+
kwargs["max_retries"] = 0
33+
resp = self.invoke("CreateSFWorkflowFromTemplate", d, **kwargs)
34+
return apis.CreateSFWorkflowFromTemplateResponseSchema().loads(resp)
35+
36+
def get_sf_workflow_template(self, req=None, **kwargs):
37+
""" GetSFWorkflowTemplate - 导出工作流定义
38+
39+
**Request**
40+
41+
- **ProjectId** (str) - (Config) 项目ID。不填写为默认项目,子帐号必须填写。 请参考 `GetProjectList接口 <https://docs.ucloud.cn/api/summary/get_project_list.html>`_
42+
- **Region** (str) - (Config) 地域。 参见 `地域和可用区列表 <https://docs.ucloud.cn/api/summary/regionlist.html>`_
43+
- **WorkflowId** (str) - (Required) 被导出工作流的Id
44+
- **WorkflowVersion** (int) - 被导出工作流的版本号。取值范围:WorkflowVersion >= 1;默认会获取发布版本对应的workflow;超过最大版本会返回错误
45+
46+
**Response**
47+
48+
- **Message** (str) - 返回消息
49+
- **Version** (int) - 导出工作流的版本号
50+
- **Workflow** (dict) - 见 **WorkflowTemplate** 模型定义
51+
- **WorkflowId** (str) - 导出工作流的Id
52+
53+
**Response Model**
54+
55+
**Param**
56+
57+
- **Name** (str) - 参数名称
58+
- **Type** (str) - 参数类型
59+
- **Value** (str) - 参数值
60+
61+
**ActivityTemplate**
62+
63+
- **Input** (dict) - Activity的输入
64+
- **Name** (str) - Activity的名字
65+
- **Next** (str) - 下一个Activity的名字
66+
- **Output** (list) - Activity的输出,详见Param
67+
- **RetryTimes** (str) - Activity的重试次数
68+
- **Timeout** (str) - Activity的超时时间
69+
- **Type** (str) - Activity的类型
70+
71+
**WorkflowTemplate**
72+
73+
- **Activites** (list) - 见 **ActivityTemplate** 模型定义
74+
- **Input** (list) - 见 **Param** 模型定义
75+
- **Output** (list) - 见 **Param** 模型定义
76+
77+
"""
78+
d = {"ProjectId": self.config.project_id, "Region": self.config.region}
79+
req and d.update(req)
80+
d = apis.GetSFWorkflowTemplateRequestSchema().dumps(d)
81+
resp = self.invoke("GetSFWorkflowTemplate", d, **kwargs)
82+
return apis.GetSFWorkflowTemplateResponseSchema().loads(resp)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- coding: utf-8 -*-
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# -*- coding: utf-8 -*-
2+
3+
""" Code is generated by ucloud-model, DO NOT EDIT IT. """
4+
from ucloud.core.typesystem import schema, fields
5+
from ucloud.services.stepflow.schemas import models
6+
7+
""" StepFlow API Schema
8+
"""
9+
"""
10+
API: CreateSFWorkflowFromTemplate
11+
12+
导入工作流定义
13+
"""
14+
15+
16+
class CreateSFWorkflowFromTemplateRequestSchema(schema.RequestSchema):
17+
""" CreateSFWorkflowFromTemplate - 导入工作流定义
18+
"""
19+
20+
fields = {
21+
"Namespace": fields.Str(required=True, dump_to="Namespace"),
22+
"ProjectId": fields.Str(required=False, dump_to="ProjectId"),
23+
"Region": fields.Str(required=True, dump_to="Region"),
24+
"Workflow": fields.Base64(required=True, dump_to="Workflow"),
25+
"WorkflowName": fields.Str(required=True, dump_to="WorkflowName"),
26+
}
27+
28+
29+
class CreateSFWorkflowFromTemplateResponseSchema(schema.ResponseSchema):
30+
""" CreateSFWorkflowFromTemplate - 导入工作流定义
31+
"""
32+
33+
fields = {
34+
"Message": fields.Str(required=True, load_from="Message"),
35+
"Version": fields.Int(required=True, load_from="Version"),
36+
}
37+
38+
39+
"""
40+
API: GetSFWorkflowTemplate
41+
42+
导出工作流定义
43+
"""
44+
45+
46+
class GetSFWorkflowTemplateRequestSchema(schema.RequestSchema):
47+
""" GetSFWorkflowTemplate - 导出工作流定义
48+
"""
49+
50+
fields = {
51+
"ProjectId": fields.Str(required=False, dump_to="ProjectId"),
52+
"Region": fields.Str(required=True, dump_to="Region"),
53+
"WorkflowId": fields.Str(required=True, dump_to="WorkflowId"),
54+
"WorkflowVersion": fields.Int(required=False, dump_to="WorkflowVersion"),
55+
}
56+
57+
58+
class GetSFWorkflowTemplateResponseSchema(schema.ResponseSchema):
59+
""" GetSFWorkflowTemplate - 导出工作流定义
60+
"""
61+
62+
fields = {
63+
"Message": fields.Str(required=False, load_from="Message"),
64+
"Version": fields.Int(required=True, load_from="Version"),
65+
"Workflow": models.WorkflowTemplateSchema(),
66+
"WorkflowId": fields.Str(required=True, load_from="WorkflowId"),
67+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# -*- coding: utf-8 -*-
2+
3+
""" Code is generated by ucloud-model, DO NOT EDIT IT. """
4+
from ucloud.core.typesystem import schema, fields
5+
6+
7+
class ParamSchema(schema.ResponseSchema):
8+
""" Param - 工作流参数
9+
"""
10+
11+
fields = {
12+
"Name": fields.Str(required=False, load_from="Name"),
13+
"Type": fields.Str(required=False, load_from="Type"),
14+
"Value": fields.Str(required=False, load_from="Value"),
15+
}
16+
17+
18+
class ActivityTemplateSchema(schema.ResponseSchema):
19+
""" ActivityTemplate - 工作流的Activity定义
20+
"""
21+
22+
fields = {
23+
"Input": fields.Str(),
24+
"Name": fields.Str(required=False, load_from="Name"),
25+
"Next": fields.Str(required=False, load_from="Next"),
26+
"Output": fields.List(fields.Str()),
27+
"RetryTimes": fields.Str(required=False, load_from="RetryTimes"),
28+
"Timeout": fields.Str(required=False, load_from="Timeout"),
29+
"Type": fields.Str(required=False, load_from="Type"),
30+
}
31+
32+
33+
class WorkflowTemplateSchema(schema.ResponseSchema):
34+
""" WorkflowTemplate - Workflow对象定义
35+
"""
36+
37+
fields = {
38+
"Activites": fields.List(ActivityTemplateSchema()),
39+
"Input": fields.List(ParamSchema()),
40+
"Output": fields.List(ParamSchema()),
41+
}

ucloud/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# -*- coding: utf-8 -*-
22

3-
version = "0.2.0"
3+
version = "0.3.0"

0 commit comments

Comments
 (0)