diff --git a/paas-ce/paas/esb/common/base_utils.py b/paas-ce/paas/esb/common/base_utils.py index 0464b4c29..a236eb4e9 100644 --- a/paas-ce/paas/esb/common/base_utils.py +++ b/paas-ce/paas/esb/common/base_utils.py @@ -262,3 +262,26 @@ def load_yaml(path): def read_file(path): with open(path, 'r') as fp: return fp.read() + + +def html_escape(html, is_json=False): + """ + Replace special characters "&", "<" and ">" to HTML-safe sequences. + If the optional flag quote is true, the quotation mark character (") + is also translated. + rewrite the cgi method + @param html: html代码 + @param is_json: 是否为json串(True/False) ,默认为False + """ + # &转换 + if not is_json: + html = html.replace('&', '&') # Must be done first! + # <>转换 + html = html.replace("<", "<") + html = html.replace(">", ">") + # 单双引号转换 + if not is_json: + # html = html.replace(' ', " ") + html = html.replace('"', """) + html = html.replace("'", "'") + return html diff --git a/paas-ce/paas/esb/components/confapis/cc/apidocs/en/add_instance_association.md b/paas-ce/paas/esb/components/confapis/cc/apidocs/en/add_instance_association.md new file mode 100644 index 000000000..4c15fa392 --- /dev/null +++ b/paas-ce/paas/esb/components/confapis/cc/apidocs/en/add_instance_association.md @@ -0,0 +1,76 @@ +### Functional description + +create association between object's instance. + +### Request Parameters + +{{ common_args_desc }} + +#### General Parameters + +| Field | Type | Required | Description | +|----------------------|------------|--------|-----------------------------| +| metadata | object | Yes | request meta data | +| condition | string map | Yes | query condition | + + +metadata params + +| Field | Type | Required | Description | +|---------------------|------------|--------|-----------------------------| +| label | string map | Yes |the label data request should with, such as biz info | + + +label params + +| Field | Type | Required | Description | +|---------------------|------------|--------|-----------------------------| +| bk_biz_id | string | Yes | business's ID | + + +condition params + +| Field | Type | Required | Description | +|---------------------|------------|--------|-----------------------------| +| bk_obj_asst_id | string | Yes | object's association unique id | +| bk_inst_id | int64 | Yes | association's source object's instance id | +| bk_asst_inst_id | int64 | Yes | association's destination object's instance id | + + +### Request Parameters Example + +``` json +{ + "bk_obj_asst_id": "bk_switch_belong_bk_host", + "bk_inst_id": 11, + "bk_asst_inst_id": 21, + "metadata":{ + "label":{ + "bk_biz_id":"1" + } + } +} +``` + +### Return Result Example + +```json +{ + "result": true, + "code": 0, + "message": "", + "data": { + "id": 1038 + } +} + +``` + +### Return Result Parameters Description + +#### data : + +| Field | Type | Description | +|------------|----------|--------------| +|id|int64|the instance association's unique id| + diff --git a/paas-ce/paas/esb/components/confapis/cc/apidocs/en/delete_instance_association.md b/paas-ce/paas/esb/components/confapis/cc/apidocs/en/delete_instance_association.md new file mode 100644 index 000000000..d34c5934d --- /dev/null +++ b/paas-ce/paas/esb/components/confapis/cc/apidocs/en/delete_instance_association.md @@ -0,0 +1,39 @@ +### Functional description + +delete association between object's instance. + +### Request Parameters + +{{ common_args_desc }} + +#### General Parameters +| Field | Type | Required | Description | +|----------------------|------------|--------|-----------------------------| +| id | int64 | Yes | the instance association's unique id | + +### Request Parameters Example + +``` json + +``` + +### Return Result Example + +```json +{ + "result": true, + "code": 0, + "message": "", + "data": "success" +} + +``` + +### Return Result Parameters Description + +#### data : + +| Field | Type | Description | +|------------|----------|--------------| + + diff --git a/paas-ce/paas/esb/components/confapis/cc/apidocs/en/find_instance_association.md b/paas-ce/paas/esb/components/confapis/cc/apidocs/en/find_instance_association.md new file mode 100644 index 000000000..88ae559b7 --- /dev/null +++ b/paas-ce/paas/esb/components/confapis/cc/apidocs/en/find_instance_association.md @@ -0,0 +1,88 @@ +### Functional description + +find association between object's instance. + +### Request Parameters + +{{ common_args_desc }} + +#### General Parameters + +| Field | Type | Required | Description | +|----------------------|------------|--------|-----------------------------| +| metadata | object | Yes | request meta data | +| condition | string map | Yes | query condition | + + +metadata params + +| Field | Type | Required | Description | +|---------------------|------------|--------|-----------------------------| +| label | string map | Yes |the label data request should with, such as biz info | + + +label params + +| Field | Type | Required | Description | +|---------------------|------------|--------|-----------------------------| +| bk_biz_id | string | Yes | business's ID | + +condition params +| Field | Type | Required | Description | +|---------------------|------------|--------|-----------------------------| +| bk_obj_asst_id | string | Yes | object's association unique id| +| bk_asst_id | string | NO | object's association kind unique name| +| bk_obj_id | string | NO | the association's source object's id| +| bk_asst_id | string | NO | the association's destination object's id| + + +### Request Parameters Example + +``` json +{ + "condition": { + "bk_obj_asst_id": "bk_switch_belong_bk_host", + "bk_asst_id": "", + "bk_object_id": "", + "bk_asst_obj_id": "" + }, + "metadata":{ + "label":{ + "bk_biz_id":"3" + } + } +} +``` + +### Return Result Example + +```json +{ + "result": true, + "code": 0, + "message": "", + "data": [{ + "bk_obj_asst_id": "bk_switch_belong_bk_host", + "bk_obj_id":"switch", + "bk_asst_obj_id":"host", + "bk_inst_id":12, + "bk_asst_inst_id":13 + }] +} + +``` + + +### Return Result Parameters Description + +#### data : + +| Field | Type | Description | +|------------|----------|--------------| +|id|int64|the association's unique id| +| bk_obj_asst_id| string| auto generated id, which represent this association.| +| bk_obj_id| string| the association source object's id | +| bk_asst_obj_id| string| the association destination object's id| +| bk_inst_id| int64| the association source object's instance id| +| bk_asst_inst_id| int64| the association destination object's instance id| + diff --git a/paas-ce/paas/esb/components/confapis/cc/apidocs/en/find_object_association.md b/paas-ce/paas/esb/components/confapis/cc/apidocs/en/find_object_association.md new file mode 100644 index 000000000..78b8f1355 --- /dev/null +++ b/paas-ce/paas/esb/components/confapis/cc/apidocs/en/find_object_association.md @@ -0,0 +1,98 @@ +### Functional description + +find association between object. + +### Request Parameters + +{{ common_args_desc }} + +#### General Parameters + +| Field | Type | Required | Description | +|----------------------|------------|--------|-----------------------------| +| metadata | object | Yes | request meta data | +| condition | string map | Yes | query condition | + + +metadata params + +| Field | Type | Required | Description | +|---------------------|------------|--------|-----------------------------| +| label | string map | Yes |the label data request should with, such as biz info | + + +label params + +| Field | Type | Required | Description | +|---------------------|------------|--------|-----------------------------| +| bk_biz_id | string | Yes | business's ID | + +condition params +| Field | Type | Required | Description | +|---------------------|------------|--------|-----------------------------| +| bk_asst_id | string | Yes | object's association kind unique name| +| bk_obj_id | string | Yes | the association's source object's id| +| bk_asst_id | string | Yes | the association's destination object's id| + + +### Request Parameters Example + +``` json +{ + "condition": { + "bk_asst_id": "belong", + "bk_obj_id": "bk_switch", + "bk_asst_obj_id": "bk_host" + }, + "metadata":{ + "label":{ + "bk_biz_id":"1" + } + } +} +``` + +### Return Result Example + +```json +{ + "result": true, + "code": 0, + "message": "", + "data": [ + { + "id": 1, + "bk_obj_asst_id": "bk_switch_belong_bk_host", + "bk_obj_asst_name": "", + "bk_asst_id": "belong", + "bk_asst_name": "belong", + "bk_obj_id": "bk_switch", + "bk_obj_name": "switch", + "bk_asst_obj_id": "bk_host", + "bk_asst_obj_name": "host", + "mapping": "1:n", + "on_delete": "none" + } + ] +} + +``` + + +### Return Result Parameters Description + +#### data : + +| Field | Type | Description | +|------------|----------|--------------| +|id|int64|the association's unique id| +| bk_obj_asst_id| string| auto generated id, which represent this association.| +| bk_obj_asst_name| string| the alias name for this association. | +| bk_asst_id| string| association kind id | +| bk_asst_name| string| association kind name | +| bk_obj_id| string| the association source object's id | +| bk_obj_name| string| the association source object's name | +| bk_asst_obj_id| string| the association destination object's id| +| bk_asst_obj_name| string| the association destination object's name| +| mapping| string| association between object's instance type, could be one of [1:1, 1:n, n:n] | +| on_delete| string| the action when this association is delete, could be one of [none, delete_src, delete_dest], "none" means do nothing, "delete_src" means delete source object's instance, "delete_dest" means delete destination object's instance.| diff --git a/paas-ce/paas/esb/components/confapis/cc/apidocs/zh_hans/add_instance_association.md b/paas-ce/paas/esb/components/confapis/cc/apidocs/zh_hans/add_instance_association.md new file mode 100644 index 000000000..c348c3b90 --- /dev/null +++ b/paas-ce/paas/esb/components/confapis/cc/apidocs/zh_hans/add_instance_association.md @@ -0,0 +1,76 @@ +### 功能描述 + +新增模型实例之间的关联关系. + +### 请求参数 + +{{ common_args_desc }} + +#### 接口参数 + +| 字段 | 类型 | 是否必填 | 描述 | +|----------------------|------------|--------|-----------------------------| +| metadata | object | Yes | meta data | +| condition | string map | Yes | 查询条件 | + + +metadata params + +| 字段 | 类型 | 是否必填 | 描述 | +|---------------------|------------|--------|-----------------------------| +| label | string map | Yes |标签信息 | + + +label params + +| 字段 | 类型 | 是否必填 | 描述 | +|---------------------|------------|--------|-----------------------------| +| bk_biz_id | string | Yes | 业务id | + + +condition params + +| 字段 | 类型 | 是否必填 | 描述 | +|---------------------|------------|--------|-----------------------------| +| bk_obj_asst_id | string | Yes | 模型之间关系关系的唯一id| +| bk_inst_id | int64 | Yes | 源模型实例id| +| bk_asst_inst_id | int64 | Yes | 目标模型实例id| + + +### 请求参数示例 + +``` json +{ + "bk_obj_asst_id": "bk_switch_belong_bk_host", + "bk_inst_id": 11, + "bk_asst_inst_id": 21, + "metadata":{ + "label":{ + "bk_biz_id":"1" + } + } +} +``` + +### 返回结果示例 + +```json +{ + "result": true, + "code": 0, + "message": "", + "data": { + "id": 1038 + } +} + +``` + +### 返回结果参数说明 + +#### data + +| 字段 | 类型 | 描述 | +|------------|----------|--------------| +|id|int64|新增的实例关联关系身份id| + diff --git a/paas-ce/paas/esb/components/confapis/cc/apidocs/zh_hans/delete_instance_association.md b/paas-ce/paas/esb/components/confapis/cc/apidocs/zh_hans/delete_instance_association.md new file mode 100644 index 000000000..c03978c97 --- /dev/null +++ b/paas-ce/paas/esb/components/confapis/cc/apidocs/zh_hans/delete_instance_association.md @@ -0,0 +1,39 @@ +### 功能描述 + +删除模型实例之间的关联关系。 + +### 请求参数 + +{{ common_args_desc }} + +#### 接口参数 +| 字段 | 类型 | 必填 | 描述 | +|----------------------|------------|--------|-----------------------------| +| id | int64 | Yes | 模型实例关联关系的唯一身份id | + +### 请求参数示例 + +``` json + +``` + +### 返回结果示例 + +```json +{ + "result": true, + "code": 0, + "message": "", + "data": "success" +} + +``` + +### 返回结果参数说明 + +#### data + +| 字段 | 类型 | 描述 | +|------------|----------|--------------| + + diff --git a/paas-ce/paas/esb/components/confapis/cc/apidocs/zh_hans/find_instance_association.md b/paas-ce/paas/esb/components/confapis/cc/apidocs/zh_hans/find_instance_association.md new file mode 100644 index 000000000..7a709b93e --- /dev/null +++ b/paas-ce/paas/esb/components/confapis/cc/apidocs/zh_hans/find_instance_association.md @@ -0,0 +1,90 @@ +### 功能描述 + +查询模型的实例关联关系。 + +### 请求参数 + +{{ common_args_desc }} + +#### 接口参数 + +| 字段 | 类型 | 是否必填 | 描述 | +|----------------------|------------|--------|-----------------------------| +| metadata | object | Yes | meta data | +| condition | string map | Yes | 查询条件 | + + +metadata params + +| 字段 | 类型 | 是否必填 | 描述 | +|---------------------|------------|--------|-----------------------------| +| label | string map | Yes | 标签信息 | + + +label params + +| 字段 | 类型 | 是否必填 | 描述 | +|---------------------|------------|--------|-----------------------------| +| bk_biz_id | string | Yes | 业务ID | + + +condition params + +| 字段 | 类型 | 是否必填 | 描述 | +|---------------------|------------|--------|-----------------------------| +| bk_obj_asst_id | string | Yes | 模型关联关系的唯一id| +| bk_asst_id | string | NO | 关联类型的唯一id| +| bk_obj_id | string | NO | 源模型id| +| bk_asst_id | string | NO | 目标模型id| + + +### 请求参数示例 + +``` json +{ + "condition": { + "bk_obj_asst_id": "bk_switch_belong_bk_host", + "bk_asst_id": "", + "bk_object_id": "", + "bk_asst_obj_id": "" + }, + "metadata":{ + "label":{ + "bk_biz_id":"3" + } + } +} +``` + +### 返回结果示例 + +```json +{ + "result": true, + "code": 0, + "message": "", + "data": [{ + "bk_obj_asst_id": "bk_switch_belong_bk_host", + "bk_obj_id":"switch", + "bk_asst_obj_id":"host", + "bk_inst_id":12, + "bk_asst_inst_id":13 + }] +} + +``` + + +### 返回结果参数说明 + +#### data + +| 字段 | 类型 | 描述 | +|------------|----------|--------------| +|id|int64|the association's unique id| +| bk_obj_asst_id| string| 自动生成的模型关联关系id.| +| bk_obj_id| string| 关联关系源模型id | +| bk_asst_obj_id| string| 关联关系目标模型id| +| bk_inst_id| int64| 源模型实例id| +| bk_asst_inst_id| int64| 目标模型实例id| + diff --git a/paas-ce/paas/esb/components/confapis/cc/apidocs/zh_hans/find_object_association.md b/paas-ce/paas/esb/components/confapis/cc/apidocs/zh_hans/find_object_association.md new file mode 100644 index 000000000..08b53c57d --- /dev/null +++ b/paas-ce/paas/esb/components/confapis/cc/apidocs/zh_hans/find_object_association.md @@ -0,0 +1,100 @@ +### 功能描述 + +查询模型的实例之间的关联关系。 + +### 请求参数 + +{{ common_args_desc }} + +#### 接口参数 + +| 字段 | 类型 | 是否必填 | 描述 | +|----------------------|------------|--------|-----------------------------| +| metadata | object | Yes | meta data | +| condition | string map | Yes | 查询条件 | + + +metadata params + +| 字段 | 类型 | 是否必填 | 描述 | +|---------------------|------------|--------|-----------------------------| +| label | string map | Yes |标签信息 | + + +label params + +| 字段 | 类型 | 是否必填 | 描述 | +|---------------------|------------|--------|-----------------------------| +| bk_biz_id | string | Yes | 业务id | + + +condition params + +| 字段 | 类型 | 是否必填 | 描述 | +|---------------------|------------|--------|-----------------------------| +| bk_asst_id | string | Yes | 模型的关联类型唯一id| +| bk_obj_id | string | Yes | 源模型id| +| bk_asst_id | string | Yes | 目标模型id| + + +### 请求参数示例 + +``` json +{ + "condition": { + "bk_asst_id": "belong", + "bk_obj_id": "bk_switch", + "bk_asst_obj_id": "bk_host" + }, + "metadata":{ + "label":{ + "bk_biz_id":"1" + } + } +} +``` + +### 返回结果示例 + +```json +{ + "result": true, + "code": 0, + "message": "", + "data": [ + { + "id": 1, + "bk_obj_asst_id": "bk_switch_belong_bk_host", + "bk_obj_asst_name": "", + "bk_asst_id": "belong", + "bk_asst_name": "belong", + "bk_obj_id": "bk_switch", + "bk_obj_name": "switch", + "bk_asst_obj_id": "bk_host", + "bk_asst_obj_name": "host", + "mapping": "1:n", + "on_delete": "none" + } + ] +} + +``` + + +### 返回结果参数说明 + +#### data + +| 字段 | 类型 | 描述 | +|------------|----------|--------------| +| id|int64|模型关联关系的身份id| +| bk_obj_asst_id| string| 模型关联关系的唯一id.| +| bk_obj_asst_name| string| 关联关系的别名. | +| bk_asst_id| string| 关联类型id| +| bk_asst_name| string| 关联类型名称 | +| bk_obj_id| string| 源模型id | +| bk_obj_name| string| 源模型名称 | +| bk_asst_obj_id| string| 目标模型id| +| bk_asst_obj_name| string| 目标模型名称| +| mapping| string| 源模型与目标模型关联关系实例的映身关系,可以是以下中的一种[1:1, 1:n, n:n] | +| on_delete| string| 删除关联关系时的动作, 取值为以下其中的一种 [none, delete_src, delete_dest], "none" 什么也不做, "delete_src" 删除源模型的实例, "delete_dest" 删除目标模型的实例.| diff --git a/paas-ce/paas/esb/components/confapis/cc/cc.yaml b/paas-ce/paas/esb/components/confapis/cc/cc.yaml index 41aac1aa6..1e82cbccf 100644 --- a/paas-ce/paas/esb/components/confapis/cc/cc.yaml +++ b/paas-ce/paas/esb/components/confapis/cc/cc.yaml @@ -482,3 +482,44 @@ dest_path: /api/v3/findmany/modulehost dest_http_method: POST +- path: /v2/cc/find_object_association/ + name: find_object_association + label: 查询模型之间的关联关系 + label_en: find object's association + suggest_method: POST + api_type: query + comp_codename: generic.v2.cc.cc_component + dest_path: /api/v3/find/objectassociation + dest_http_method: POST + +- path: /v2/cc/find_instance_association/ + name: find_instance_association + label: 查询模型实例之间的关联关系 + label_en: find association between object's instance + suggest_method: POST + api_type: query + comp_codename: generic.v2.cc.cc_component + dest_path: /api/v3/find/instassociation + dest_http_method: POST + +- path: /v2/cc/add_instance_association/ + name: add_instance_association + label: 新建模型实例之间的关联关系 + label_en: add association between object's instance + suggest_method: POST + api_type: query + comp_codename: generic.v2.cc.cc_component + dest_path: /api/v3/create/instassociation + dest_http_method: POST + +- path: /v2/cc/delete_instance_association/ + name: delete_instance_association + label: 删除模型实例之间的关联关系 + label_en: delete association between object's instance + method: DELETE + api_type: query + comp_codename: generic.v2.cc.cc_component + dest_path: /api/v3/delete/instassociation/{id} + dest_http_method: DELETE + + diff --git a/paas-ce/paas/esb/components/esb_conf.py b/paas-ce/paas/esb/components/esb_conf.py index b777c5973..1d4288427 100644 --- a/paas-ce/paas/esb/components/esb_conf.py +++ b/paas-ce/paas/esb/components/esb_conf.py @@ -73,6 +73,8 @@ def _rel_path(x): '/v2/cmsi/send_mail/': '/cmsi/send_mail/', '/v2/cmsi/send_sms/': '/cmsi/send_sms/', '/v2/cmsi/send_weixin/': '/cmsi/send_weixin/', + '/v2/cmsi/get_msg_type/': '/cmsi/get_msg_type/', + '/v2/cmsi/send_msg/': '/cmsi/send_msg/', }, 'preset_channels': [ # CC v2 @@ -396,6 +398,8 @@ def _rel_path(x): 'comp_codename': 'generic.cmsi.send_voice_msg', 'comp_conf_to_db': [ ('dest_url', ''), + ('qcloud_app_id', ''), + ('qcloud_app_key', ''), ] }), ('/cmsi/send_mail/', { @@ -432,6 +436,18 @@ def _rel_path(x): ('wx_qy_agentid', ''), ] }), + ('/cmsi/get_msg_type/', { + 'comp_codename': 'generic.cmsi.get_msg_type', + 'comp_conf_to_db': [ + ('weixin', True), + ('mail', True), + ('sms', True), + ('voice', True), + ] + }), + ('/cmsi/send_msg/', { + 'comp_codename': 'generic.cmsi.send_msg' + }), # FTA ('/fta/http_relay/', { diff --git a/paas-ce/paas/esb/components/generic/templates/cmsi/apidocs/en/get_msg_type.md b/paas-ce/paas/esb/components/generic/templates/cmsi/apidocs/en/get_msg_type.md new file mode 100644 index 000000000..30914bfa1 --- /dev/null +++ b/paas-ce/paas/esb/components/generic/templates/cmsi/apidocs/en/get_msg_type.md @@ -0,0 +1,48 @@ +### Functional description + +Query the type of send_msg component that supports sending messages + +### Request Parameters + +{{ common_args_desc }} + +### Request Parameters Example + +```python +{ + "bk_app_code": "esb_test", + "bk_app_secret": "xxx", + "bk_token": "xxx" +} +``` + +### Return Result Example + +```python +{ + "result": true, + "code": 0, + "data": [ + { + "type": "weixin", + "label": "weixin", + "is_active": true + }, + { + "type": "mail", + "label": "mail", + "is_active": true + }, + { + "type": "sms", + "label": "sms", + "is_active": true + }, + { + "type": "voice", + "label": "voice", + "is_active": true + } + ] +} +``` diff --git a/paas-ce/paas/esb/components/generic/templates/cmsi/apidocs/en/send_msg.md b/paas-ce/paas/esb/components/generic/templates/cmsi/apidocs/en/send_msg.md new file mode 100644 index 000000000..3cd6398ad --- /dev/null +++ b/paas-ce/paas/esb/components/generic/templates/cmsi/apidocs/en/send_msg.md @@ -0,0 +1,60 @@ +### Functional description + +Universal messaging interface + +### Request Parameters + +{{ common_args_desc }} + +#### Interface Parameters + +| Field | Type | Required| Description | +|--------------------|------------|--------|-------------------| +| msg_type | string | YES | The type of information sent can be obtained through the get_msg_type interface | +| receiver__username | string | YES | Receiver, including the username, the user needs to register on the BlueKing platform, separated by commas | +| cc__username | string | No | Cc, including the user name, the user needs to register on the Blue Whale platform, multiple comma-separated, msg type is valid for mail | +| title | string | YES | Subject | +| content | string | YES | Content | +| body_format | string | No | Mail format, including 'Html', 'Text', defaults to 'Html', valid when meg type is mail | +| attachments | list | No | Mail attachment, valid when meg type is mail | +| date | string | No | Notification sending time, the default is the current time "YYYY-mm-dd HH:MM", valid when meg type is weixin | +| remark | string | No | Notify the trailing text, valid when meg type is weixin| +| wx_qy_agentid | string | No | Enterprise WeChat AgentId, valid when meg type is weixin | +| wx_qy_corpsecret | string | No | Enterprise WeChat CorpSecret, valid when meg type is weixin | +| is_content_base64 | bool | No | Notification text content is base64 encoding, default False, no encoding, if encoding, please use base64.b64encode method | + +##### attachments + +| Field | Type | Required| Description | +|--------------------|------------|--------|------------| +| filename | string | YES | file name | +| content | string | YES | File content, the content of the file is the base64 encoded string of the original file content | +| type | string | No | File type, default is the file name suffix, such as a.png file type is 'png' | +| disposition | string | No | File Content-Disposition, image file (type=image, jpg, png, jpeg) defaults to 'inline', other files default to 'attachment' | +| content_id | string | No | File Content-ID, effective when the file is an image file; default is '' | + +### Request Parameters Example + +```python +{ + "bk_app_code": "esb-test", + "bk_app_secret": "esb-test-secret", + "bk_username": "admin", + "msg_type": "mail", + "receiver__username": "admin", + "title": "xxx", + "content": "xxx" +} +``` + +### Return Result Example + +```python +{ + "result": true, + "code": 0, + "message": "OK", + "data": [], + "request_id": "sdfdfdfsdfasdasdasas" +} +``` diff --git a/paas-ce/paas/esb/components/generic/templates/cmsi/apidocs/zh_hans/get_msg_type.md b/paas-ce/paas/esb/components/generic/templates/cmsi/apidocs/zh_hans/get_msg_type.md new file mode 100644 index 000000000..27eea482c --- /dev/null +++ b/paas-ce/paas/esb/components/generic/templates/cmsi/apidocs/zh_hans/get_msg_type.md @@ -0,0 +1,48 @@ +### 功能描述 + +查询 send_msg 组件支持发送消息的类型 + +### 请求参数 + +{{ common_args_desc }} + +### 请求参数示例 + +```python +{ + "bk_app_code": "esb_test", + "bk_app_secret": "xxx", + "bk_token": "xxx" +} +``` + +### 返回结果示例 + +```python +{ + "result": true, + "code": 0, + "data": [ + { + "type": "weixin", + "label": "微信", + "is_active": true + }, + { + "type": "mail", + "label": "邮件", + "is_active": true + }, + { + "type": "sms", + "label": "短信", + "is_active": true + }, + { + "type": "voice", + "label": "语音", + "is_active": true + } + ] +} +``` diff --git a/paas-ce/paas/esb/components/generic/templates/cmsi/apidocs/zh_hans/send_msg.md b/paas-ce/paas/esb/components/generic/templates/cmsi/apidocs/zh_hans/send_msg.md new file mode 100644 index 000000000..e3595437f --- /dev/null +++ b/paas-ce/paas/esb/components/generic/templates/cmsi/apidocs/zh_hans/send_msg.md @@ -0,0 +1,62 @@ +### 功能描述 + +通用消息发送接口 + +### 请求参数 + +{{ common_args_desc }} + +#### 接口参数 + +| 字段 | 类型 |必选 | 描述 | +|--------------------|------------|--------|------------| +| msg_type | string | 是 | 发送信息的类型,可通过get_msg_type组件获取 | +| receiver__username | string | 是 | 接收者,包含用户名,用户需在蓝鲸平台注册,多个以逗号分隔 | +| title | string | 是 | 主题 | +| content | string | 是 | 内容 | +| sender | string | 否 | 发件人,msg_type 为 mail 时有效 | +| cc__username | string | 否 | 抄送人,包含用户名,用户需在蓝鲸平台注册,多个以逗号分隔,msg_type为mail时有效 | +| body_format | string | 否 | 邮件格式,包含'Html', 'Text',默认为'Html', msg_type 为 mail 时有效 | +| attachments | list | 否 | 邮件附件, msg_type 为 mail 时有效 | +| date | string | 否 | 通知发送时间,默认为当前时间 "YYYY-mm-dd HH:MM",msg_type 为 weixin 时有效 | +| remark | string | 否 | 通知尾部文字,msg_type 为 weixin 时有效| +| wx_qy_agentid | string | 否 | 企业微信AgentId,msg_type 为 weixin 时有效 | +| wx_qy_corpsecret | string | 否 | 企业微信CorpSecret,msg_type 为 weixin 时有效 | +| is_content_base64 | bool | 否 | 通知文字content是否base64编码,默认False,不编码,若编码请使用base64.b64encode方法 | + + +##### attachments + +| 字段 | 类型 |必选 | 描述 | +|--------------------|------------|--------|------------| +| filename | string | 是 | 文件名 | +| content | string | 是 | 文件内容,文件内容为原文件内容的 base64 编码字符串" | +| type | string | 否 | 文件类型,默认为文件名后缀,如 a.png 文件类型为 'png' | +| disposition | string | 否 | 文件 Content-Disposition,图片文件(type=image, jpg, png, jpeg)默认为 'inline',其他文件默认为 'attachment' | +| content_id | string | 否 | 文件 Content-ID,文件为图片文件时生效;默认为 '<文件名>' | + +### 请求参数示例 + +```python +{ + "bk_app_code": "esb-test", + "bk_app_secret": "esb-test-secret", + "bk_username": "admin", + "msg_type": "mail", + "receiver__username": "admin,yunchao", + "title": "xxx", + "content": "xxx" +} +``` + +### 返回结果示例 + +```python +{ + "result": true, + "code": 0, + "message": "OK", + "data": [], + "request_id": "sdfdfdfsdfasdasdasas" +} +``` diff --git a/paas-ce/paas/esb/components/generic/templates/cmsi/get_msg_type.py b/paas-ce/paas/esb/components/generic/templates/cmsi/get_msg_type.py new file mode 100644 index 000000000..384d14f0e --- /dev/null +++ b/paas-ce/paas/esb/components/generic/templates/cmsi/get_msg_type.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +""" +Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) available. +Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved. +Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at +http://opensource.org/licenses/MIT +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. +""" # noqa +from components.component import Component, SetupConfMixin +from common.constants import API_TYPE_Q, HTTP_METHOD +from common.base_utils import str_bool +from .toolkit import configs + + +class GetMsgType(Component, SetupConfMixin): + suggest_method = HTTP_METHOD.GET + label = u'查询消息发送类型' + label_en = 'Get message type' + + sys_name = configs.SYSTEM_NAME + api_type = API_TYPE_Q + + def handle(self): + bk_language = self.request.headers.get('Blueking-Language', 'en') + + msg_type = [] + for mt in configs.msg_type: + is_active = mt.get('is_active', str_bool(getattr(self, mt['type'], False))) + msg_type.append({ + 'type': mt['type'], + 'label': mt['label_en'] if bk_language == 'en' else mt['label'], + 'is_active': is_active, + }) + + self.response.payload = { + "result": True, + "data": msg_type, + } diff --git a/paas-ce/paas/esb/components/generic/templates/cmsi/send_msg.py b/paas-ce/paas/esb/components/generic/templates/cmsi/send_msg.py new file mode 100644 index 000000000..210d08a58 --- /dev/null +++ b/paas-ce/paas/esb/components/generic/templates/cmsi/send_msg.py @@ -0,0 +1,76 @@ +# -*- coding: utf-8 -*- +""" +Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) available. +Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved. +Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at +http://opensource.org/licenses/MIT +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. +""" # noqa +from django import forms + +from components.component import Component, SetupConfMixin +from esb.channel import get_channel_manager +from common.forms import BaseComponentForm, ListField, DefaultBooleanField, TypeCheckField +from common.constants import API_TYPE_OP, HTTP_METHOD +from .toolkit import configs + + +class SendMsg(Component, SetupConfMixin): + suggest_method = HTTP_METHOD.POST + label = u'通用消息发送' + label_en = 'Send message' + + sys_name = configs.SYSTEM_NAME + api_type = API_TYPE_OP + msg_type_map = configs.msg_type_map + + class Form(BaseComponentForm): + msg_type = forms.CharField(label='msg type', required=True) + receiver__username = ListField(label='recipients', required=True) + sender = forms.CharField(label='mail sender', required=False) + cc__username = ListField(label='CC', required=False) + title = forms.CharField(label='subject', required=True) + content = forms.CharField(label='content', required=True) + body_format = forms.CharField(label='email format', required=False) + attachments = TypeCheckField(label='attachments', promise_type=list, required=False) + date = forms.CharField(label='notification sending time', required=False) + remark = forms.CharField(label='notification tail text', required=False) + wx_qy_agentid = forms.CharField(label='enterprise wechat agentid', required=False) + wx_qy_corpsecret = forms.CharField(label='enterprise wechat corpsecret', required=False) + is_content_base64 = DefaultBooleanField( + label='content is encoded by base64 or not', default=False, required=False) + + def clean(self): + data = self.cleaned_data + if data['msg_type'] == "voice": + data['auto_read_message'] = data['content'] + + if data['msg_type'] == "weixin": + data['data'] = { + 'heading': data['title'], + 'message': data['content'], + 'date': data['date'], + 'remark': data['remark'], + 'is_message_base64': data['is_content_base64'] + } + + return data + + def handle(self): + data = self.form_data + msg_type = data.pop('msg_type') + + channel_manager = get_channel_manager() + + if msg_type not in configs.msg_type_map: + self.response.payload = { + 'result': False, + 'message': 'Unsupported type of msg type' + } + return + + path = '/cmsi/%s/' % self.msg_type_map[msg_type] + channel_conf = channel_manager.get_channel_by_path(path, 'POST') + comp_obj = self.prepare_other('generic.cmsi.%s' % self.msg_type_map[msg_type], kwargs=data) + comp_obj.setup_conf(channel_conf['comp_conf']) + self.response.payload = comp_obj.invoke() diff --git a/paas-ce/paas/esb/components/generic/templates/cmsi/send_sms.py b/paas-ce/paas/esb/components/generic/templates/cmsi/send_sms.py index 7acc8bb32..f07f73c5a 100644 --- a/paas-ce/paas/esb/components/generic/templates/cmsi/send_sms.py +++ b/paas-ce/paas/esb/components/generic/templates/cmsi/send_sms.py @@ -95,9 +95,6 @@ def handle(self): self.qcloud_app_id = getattr(self, 'qcloud_app_id', '') or getattr(configs, 'qcloud_app_id', '') self.qcloud_app_key = getattr(self, 'qcloud_app_key', '') or getattr(configs, 'qcloud_app_key', '') - # 第三方接口地址配置 - self.dest_url = getattr(self, 'dest_url', '') or getattr(configs, 'send_sms_dest_url', '') - data = self.request.kwargs if data['receiver']: tools.validate_receiver(data['receiver'], contact_way=self.contact_way) diff --git a/paas-ce/paas/esb/components/generic/templates/cmsi/send_voice_msg.py b/paas-ce/paas/esb/components/generic/templates/cmsi/send_voice_msg.py index ec411e28d..0e6918098 100644 --- a/paas-ce/paas/esb/components/generic/templates/cmsi/send_voice_msg.py +++ b/paas-ce/paas/esb/components/generic/templates/cmsi/send_voice_msg.py @@ -109,11 +109,11 @@ def clean(self): return data def handle(self): - # QCloud 短信配置 + # QCloud 语音配置 self.qcloud_app_id = getattr(self, 'qcloud_app_id', '') or getattr(configs, 'qcloud_app_id', '') self.qcloud_app_key = getattr(self, 'qcloud_app_key', '') or getattr(configs, 'qcloud_app_key', '') - data = self.request.kwargs + data = self.form_data # 将 receiver__username 中的用户名,转换为接口需要的 user_list_information 信息 if data['receiver__username']: user_data = tools.get_user_contact_with_username( diff --git a/paas-ce/paas/esb/components/generic/templates/cmsi/send_weixin.py b/paas-ce/paas/esb/components/generic/templates/cmsi/send_weixin.py index d3e92f8ad..1c0a87be3 100644 --- a/paas-ce/paas/esb/components/generic/templates/cmsi/send_weixin.py +++ b/paas-ce/paas/esb/components/generic/templates/cmsi/send_weixin.py @@ -90,7 +90,7 @@ class Form(BaseComponentForm): def clean(self): data = self.cleaned_data - if not(data['receiver'] or data['receiver__username']): + if not (data['receiver'] or data['receiver__username']): raise forms.ValidationError( 'WeChat receiver [receiver, receiver__username] shall not be empty at the same time') if data['receiver']: diff --git a/paas-ce/paas/esb/components/generic/templates/cmsi/toolkit/configs.py b/paas-ce/paas/esb/components/generic/templates/cmsi/toolkit/configs.py index f9d53d59b..464ad55f3 100644 --- a/paas-ce/paas/esb/components/generic/templates/cmsi/toolkit/configs.py +++ b/paas-ce/paas/esb/components/generic/templates/cmsi/toolkit/configs.py @@ -28,7 +28,7 @@ # 通过第三方接口发送邮件的配置 -dest_url = '' # 第三方接口完整路径 +dest_url = '' # 邮件第三方接口完整路径 # send_weixin 组件微信消息类型配置 wx_type = 'qy' @@ -46,3 +46,34 @@ # 发送短信腾讯云配置 sdkappid 对应的 appkey,需要业务方高度保密 qcloud_app_id = '' qcloud_app_key = '' + +# cmsi支持的信息发送类型 +msg_type = [ + { + "type": "weixin", + "label": u"微信", + "label_en": "weixin" + }, + { + "type": "mail", + "label": u"邮件", + "label_en": "mail" + }, + { + "type": "sms", + "label": u"短信", + "label_en": "sms" + }, + { + "type": "voice", + "label": u"语音", + "label_en": "voice" + } +] + +msg_type_map = { + "weixin": "send_weixin", + "mail": "send_mail", + "sms": "send_sms", + "voice": "send_voice_msg" +} diff --git a/paas-ce/paas/esb/esb/bkcore/models.py b/paas-ce/paas/esb/esb/bkcore/models.py index 040a5cc5a..c8969cc06 100644 --- a/paas-ce/paas/esb/esb/bkcore/models.py +++ b/paas-ce/paas/esb/esb/bkcore/models.py @@ -9,6 +9,7 @@ """ Core models for the project. """ +import re import json import datetime @@ -94,6 +95,12 @@ def __unicode__(self): def api_path(self): return '/api/c/compapi/%s/' % self.path.strip('/') + @property + def api_version(self): + if self.component_codename.startswith('generic.v2.'): + return 'v2' + return '' + @property def channel_conf(self): return { @@ -229,6 +236,16 @@ def get_extra_headers(self): def get_extra_params(self): return json.loads(self.extra_params or '{}') + @property + def api_path(self): + return '/api/c/self-service-api/%s/' % self.registed_path.strip('/') + + @property + def api_name(self): + path_2_name = re.findall(r'[a-zA-Z0-9]+', self.registed_path.lower()) + path_2_name.insert(0, self.registed_http_method.lower()) + return '_'.join(path_2_name) + class ESBBuffetMapping(models.Model): """ESB 组件自助接入,参数mapping diff --git a/paas-ce/paas/esb/esb/outgoing.py b/paas-ce/paas/esb/esb/outgoing.py index cd2c36baf..465f75e0f 100644 --- a/paas-ce/paas/esb/esb/outgoing.py +++ b/paas-ce/paas/esb/esb/outgoing.py @@ -245,6 +245,7 @@ class HttpClient(BasicHttpClient): DEFAULT_HEADERS = [ 'Blueking-Language', + 'Blueking-Timezone', ] def __init__(self, component):