From 30e0bcd411458ef27a7f36f4db33ae8903878d17 Mon Sep 17 00:00:00 2001 From: alex-smile <443677891@qq.com> Date: Wed, 15 Jan 2020 16:10:38 +0800 Subject: [PATCH] add esb get_systems,get_components apis --- paas-ce/paas/esb/common/constants.py | 5 ++ .../esb/components/bk/apisv2/esb/__init__.py | 8 ++ .../apisv2/esb/apidocs/en/get_components.md | 73 ++++++++++++++++ .../bk/apisv2/esb/apidocs/en/get_systems.md | 52 +++++++++++ .../esb/apidocs/zh_hans/get_components.md | 73 ++++++++++++++++ .../apisv2/esb/apidocs/zh_hans/get_systems.md | 52 +++++++++++ .../bk/apisv2/esb/get_components.py | 87 +++++++++++++++++++ .../components/bk/apisv2/esb/get_systems.py | 53 +++++++++++ .../bk/apisv2/esb/toolkit/__init__.py | 8 ++ .../bk/apisv2/esb/toolkit/configs.py | 10 +++ .../components/bk/apisv2/esb/toolkit/tools.py | 8 ++ paas-ce/paas/esb/components/esb_conf.py | 7 ++ .../esb/esb/management/utils/constants.py | 2 +- 13 files changed, 437 insertions(+), 1 deletion(-) create mode 100644 paas-ce/paas/esb/components/bk/apisv2/esb/__init__.py create mode 100644 paas-ce/paas/esb/components/bk/apisv2/esb/apidocs/en/get_components.md create mode 100644 paas-ce/paas/esb/components/bk/apisv2/esb/apidocs/en/get_systems.md create mode 100644 paas-ce/paas/esb/components/bk/apisv2/esb/apidocs/zh_hans/get_components.md create mode 100644 paas-ce/paas/esb/components/bk/apisv2/esb/apidocs/zh_hans/get_systems.md create mode 100644 paas-ce/paas/esb/components/bk/apisv2/esb/get_components.py create mode 100644 paas-ce/paas/esb/components/bk/apisv2/esb/get_systems.py create mode 100644 paas-ce/paas/esb/components/bk/apisv2/esb/toolkit/__init__.py create mode 100644 paas-ce/paas/esb/components/bk/apisv2/esb/toolkit/configs.py create mode 100644 paas-ce/paas/esb/components/bk/apisv2/esb/toolkit/tools.py diff --git a/paas-ce/paas/esb/common/constants.py b/paas-ce/paas/esb/common/constants.py index a8b2b5c8b..28b01e869 100644 --- a/paas-ce/paas/esb/common/constants.py +++ b/paas-ce/paas/esb/common/constants.py @@ -73,4 +73,9 @@ 'label': _(u'蓝鲸监控'), 'remark': u'蓝鲸监控', }, + 'ESB': { + 'name': 'ESB', + 'label': u'API网关', + 'remark': u'API网关', + }, } diff --git a/paas-ce/paas/esb/components/bk/apisv2/esb/__init__.py b/paas-ce/paas/esb/components/bk/apisv2/esb/__init__.py new file mode 100644 index 000000000..f5459e554 --- /dev/null +++ b/paas-ce/paas/esb/components/bk/apisv2/esb/__init__.py @@ -0,0 +1,8 @@ +# -*- 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 diff --git a/paas-ce/paas/esb/components/bk/apisv2/esb/apidocs/en/get_components.md b/paas-ce/paas/esb/components/bk/apisv2/esb/apidocs/en/get_components.md new file mode 100644 index 000000000..008d4d786 --- /dev/null +++ b/paas-ce/paas/esb/components/bk/apisv2/esb/apidocs/en/get_components.md @@ -0,0 +1,73 @@ +### Functional description + +Get the list of components for the specified system + +### Request Parameters + +{{ common_args_desc }} + +#### Interface Parameters + +| Field | Type | Required | Description | +|---------------|------------|--------|------------------| +| system_names | list | YES | System name, Available through the component get_systems.| + +### Request Parameters Example + +```python +{ + "bk_app_code": "esb_test", + "bk_app_secret": "xxx", + "bk_token": "xxx", + "system_names": ["BK_LOGIN", "XXXX"] +} +``` + +### Return Result Example + +```python +{ + "result": true, + "code": 0, + "data": [ + { + "name": "get_all_users", + "label": "get all users", + "version": "v2", + "method": "GET", + "path": "/api/c/compapi/v2/bk_login/get_all_users/", + "type": 2, + "system_id": 1, + "system_name": "BK_LOGIN", + "category": "component" + }, + { + "name": "get_api_check_component_exist", + "label": "check_component_exist", + "version": "", + "method": "GET", + "path": "/api/c/self-service-api/api/check_component_exist/", + "type": 2, + "system_id": 6, + "system_name": "XXXX", + "category": "buffet_component" + } + ], + "message": "" +} +``` + +### Return Result Description + +#### data + +| Field | Type | Description | +| ------------ | ---------- | ------------------------------ | +| method | string | suggest request method | +| version | string | component version | +| system_id | int | System id | +| name | string | component name | +| path | string | component Third-party system path | +| type | int | 1 query, 2 operate | +| label | string | component label | +| category | string | component category, component or buffet_component | diff --git a/paas-ce/paas/esb/components/bk/apisv2/esb/apidocs/en/get_systems.md b/paas-ce/paas/esb/components/bk/apisv2/esb/apidocs/en/get_systems.md new file mode 100644 index 000000000..3e61f085f --- /dev/null +++ b/paas-ce/paas/esb/components/bk/apisv2/esb/apidocs/en/get_systems.md @@ -0,0 +1,52 @@ +### Functional description + +Get the list of systems accessing the ESB + +### 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, + "message": "OK", + "data": [ + { + "id": 1, + "name": "BK_LOGIN", + "label": "Login System", + "remark": "BlueKing Login System, managing user login authentication and user information" + }, + { + "id": 2, + "name": "BK_PAAS", + "label": "Developer Center", + "remark": "Developer Center" + } + ] +} +``` + +### Return Result Description + +#### data + +| Field | Type | Description | +|-----------|----------|-----------| +| id | int | system id | +| label | string | system label | +| name | string | system name | +| remark | string | remark | diff --git a/paas-ce/paas/esb/components/bk/apisv2/esb/apidocs/zh_hans/get_components.md b/paas-ce/paas/esb/components/bk/apisv2/esb/apidocs/zh_hans/get_components.md new file mode 100644 index 000000000..b1bb8fad3 --- /dev/null +++ b/paas-ce/paas/esb/components/bk/apisv2/esb/apidocs/zh_hans/get_components.md @@ -0,0 +1,73 @@ +### 功能描述 + +获取指定系统的组件列表 + +### 请求参数 + +{{ common_args_desc }} + +#### 接口参数 + +| 字段 | 类型 | 必选 | 描述 | +|---------------|------------|--------|------------------| +| system_names | list | 是 | 系统名称, 可通过组件get_systems获取| + +### 请求参数示例 + +```python +{ + "bk_app_code": "esb_test", + "bk_app_secret": "xxx", + "bk_token": "xxx", + "system_names": ["BK_LOGIN", "XXXX"] +} +``` + +### 返回结果示例 + +```python +{ + "result": true, + "code": 0, + "data": [ + { + "name": "get_all_users", + "label": "获取所有用户信息", + "version": "v2", + "method": "GET", + "path": "/api/c/compapi/v2/bk_login/get_all_users/", + "system_id": 1, + "system_name": "BK_LOGIN", + "type": 2, + "category": "component", + }, + { + "name": "get_api_check_component_exist", + "label": "check_component_exist", + "version": "", + "method": "GET", + "path": "/api/c/self-service-api/api/check_component_exist/", + "system_id": 6, + "system_name": "XXXX", + "type": 2, + "category": "buffet_component", + } + ], + "message": "" +} +``` + +### 返回结果参数说明 + +#### data + +| 字段 | 类型 | 描述 | +|-----------|----------|-----------| +| method | string | 建议请求方法 | +| version | string | 组件版本 | +| system_id | int | 所属系统id | +| name | string | 组件名称 | +| path | string | 组件第三方系统路径 | +| type | int | 1 query, 2 operate | +| label | string | 组件标签 | +| category | string | 组件类型, component or buffet_component | diff --git a/paas-ce/paas/esb/components/bk/apisv2/esb/apidocs/zh_hans/get_systems.md b/paas-ce/paas/esb/components/bk/apisv2/esb/apidocs/zh_hans/get_systems.md new file mode 100644 index 000000000..44e11db55 --- /dev/null +++ b/paas-ce/paas/esb/components/bk/apisv2/esb/apidocs/zh_hans/get_systems.md @@ -0,0 +1,52 @@ +### 功能描述 + +获取ESB中的组件系统列表 + +### 请求参数 + +{{ common_args_desc }} + +### 请求参数示例 + +```python +{ + "bk_app_code": "esb_test", + "bk_app_secret": "xxx", + "bk_token": "xxx" +} +``` + +### 返回结果示例 + +```python +{ + "result": true + "code": 0, + "message": "OK", + "data": [ + { + "id": 1, + "name": "BK_LOGIN", + "label": "蓝鲸统一登录", + "remark": "蓝鲸统一登录,管理用户登录验证,及用户信息" + }, + { + "id": 2, + "name": "BK_PAAS", + "label": "蓝鲸开发者中心", + "remark": "蓝鲸开发者中心" + } + ] +} +``` + +### 返回结果参数说明 + +#### data + +| 名称 | 类型 | 说明 | +| ------------ | ---------- | ------------------------------ | +| id | int | 系统id | +| name | string | 系统名称 | +| label | string | 系统标签 | +| remark | string | 备注 | diff --git a/paas-ce/paas/esb/components/bk/apisv2/esb/get_components.py b/paas-ce/paas/esb/components/bk/apisv2/esb/get_components.py new file mode 100644 index 000000000..102cfac1c --- /dev/null +++ b/paas-ce/paas/esb/components/bk/apisv2/esb/get_components.py @@ -0,0 +1,87 @@ +# -*- 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.utils import translation +from django.utils.translation import ugettext as _ + +from common.base_utils import html_escape +from components.component import Component +from common.forms import BaseComponentForm, ListField +from common.constants import API_TYPE_Q, HTTP_METHOD +from esb.bkcore.models import ComponentSystem, ESBChannel, ESBBuffetComponent + +from .toolkit import configs + + +class GetComponents(Component): + suggest_method = HTTP_METHOD.POST + label = u'获取指定系统的组件列表' + label_en = 'Get components' + + sys_name = configs.SYSTEM_NAME + api_type = API_TYPE_Q + + class Form(BaseComponentForm): + system_names = ListField(label='system name', required=True) + + def handle(self): + system_names = self.form_data['system_names'] + + component_queryset = ESBChannel.objects.filter(component_system__name__in=system_names, is_hidden=False) + buffet_component_queryset = ESBBuffetComponent.objects.filter(system__name__in=system_names) + + systems = self.get_systems(system_names) + + component_list = [] + + bk_language = self.request.headers.get('Blueking-Language', 'en') + with translation.override(bk_language): + for channel in component_queryset: + is_official = systems.get(channel.component_system_id, {}).get('is_official', False) + channel_name = channel.name + if is_official: + channel_name = _(channel_name) + component_list.append({ + 'name': channel.component_name, + 'label': html_escape(channel_name), + 'method': channel.extra_info_json().get('suggest_method', ''), + 'path': channel.api_path, + 'system_id': channel.component_system_id, + 'system_name': channel.component_system.name, + 'type': channel.type, + 'version': channel.api_version, + 'category': 'component', + }) + + buffet_component_list = [ + { + 'name': buffet.api_name, + 'label': buffet.name, + 'method': buffet.registed_http_method, + 'path': buffet.api_path, + 'system_id': buffet.system_id, + 'system_name': buffet.system.name, + 'type': buffet.type, + 'version': '', + 'category': 'buffet_component', + } + for buffet in buffet_component_queryset + ] + + self.response.payload = { + "result": True, + "data": component_list + buffet_component_list, + } + + def get_systems(self, system_names): + systems = {} + for system in ComponentSystem.objects.filter(name__in=system_names): + systems[system.id] = { + 'is_official': system.is_official, + } + return systems diff --git a/paas-ce/paas/esb/components/bk/apisv2/esb/get_systems.py b/paas-ce/paas/esb/components/bk/apisv2/esb/get_systems.py new file mode 100644 index 000000000..18282d9e0 --- /dev/null +++ b/paas-ce/paas/esb/components/bk/apisv2/esb/get_systems.py @@ -0,0 +1,53 @@ +# -*- 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.utils import translation +from django.utils.translation import ugettext as _ + +from common.base_utils import html_escape +from common.constants import API_TYPE_Q, HTTP_METHOD +from components.component import Component +from esb.bkcore.models import ComponentSystem, ESBChannel, ESBBuffetComponent + +from .toolkit import configs + + +class GetSystems(Component): + suggest_method = HTTP_METHOD.GET + label = u'获取系统列表' + label_en = 'Get systems' + + sys_name = configs.SYSTEM_NAME + api_type = API_TYPE_Q + + def handle(self): + systems = ComponentSystem.objects.all() + systems_has_channel = [] + + bk_language = self.request.headers.get('Blueking-Language', 'en') + with translation.override(bk_language): + for system in systems: + has_channel = ESBChannel.objects.filter(component_system_id=system.id, is_hidden=False).exists() + has_buffet = ESBBuffetComponent.objects.filter(system_id=system.id).exists() + if has_channel or has_buffet: + system_label = system.label + system_remark = system.remark + if system.is_official: + system_label = _(system_label) + system_remark = _(system_remark) + systems_has_channel.append({ + 'id': system.id, + 'name': html_escape(system.name), + 'label': html_escape(system_label), + 'remark': html_escape(system_remark), + }) + + self.response.payload = { + "result": True, + "data": systems_has_channel, + } diff --git a/paas-ce/paas/esb/components/bk/apisv2/esb/toolkit/__init__.py b/paas-ce/paas/esb/components/bk/apisv2/esb/toolkit/__init__.py new file mode 100644 index 000000000..f5459e554 --- /dev/null +++ b/paas-ce/paas/esb/components/bk/apisv2/esb/toolkit/__init__.py @@ -0,0 +1,8 @@ +# -*- 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 diff --git a/paas-ce/paas/esb/components/bk/apisv2/esb/toolkit/configs.py b/paas-ce/paas/esb/components/bk/apisv2/esb/toolkit/configs.py new file mode 100644 index 000000000..50edfd177 --- /dev/null +++ b/paas-ce/paas/esb/components/bk/apisv2/esb/toolkit/configs.py @@ -0,0 +1,10 @@ +# -*- 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 + +SYSTEM_NAME = 'ESB' diff --git a/paas-ce/paas/esb/components/bk/apisv2/esb/toolkit/tools.py b/paas-ce/paas/esb/components/bk/apisv2/esb/toolkit/tools.py new file mode 100644 index 000000000..f5459e554 --- /dev/null +++ b/paas-ce/paas/esb/components/bk/apisv2/esb/toolkit/tools.py @@ -0,0 +1,8 @@ +# -*- 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 diff --git a/paas-ce/paas/esb/components/esb_conf.py b/paas-ce/paas/esb/components/esb_conf.py index 1d4288427..f3faf9216 100644 --- a/paas-ce/paas/esb/components/esb_conf.py +++ b/paas-ce/paas/esb/components/esb_conf.py @@ -487,6 +487,13 @@ def _rel_path(x): 'is_hidden': True }), + # ESB + ('/v2/esb/get_systems/', { + 'comp_codename': 'generic.v2.esb.get_systems' + }), + ('/v2/esb/get_components/', { + 'comp_codename': 'generic.v2.esb.get_components' + }), ] }, 'esb': { diff --git a/paas-ce/paas/esb/esb/management/utils/constants.py b/paas-ce/paas/esb/esb/management/utils/constants.py index 24778dcee..58a2e5343 100644 --- a/paas-ce/paas/esb/esb/management/utils/constants.py +++ b/paas-ce/paas/esb/esb/management/utils/constants.py @@ -46,6 +46,6 @@ 'name': 'management_tools', 'label': u'管理工具', 'priority': 50, - 'systems': ['SOPS', 'MONITOR'] + 'systems': ['SOPS', 'MONITOR', 'ESB'] }, ]