Skip to content

Commit

Permalink
Merge pull request #169 from alex-smile/add_esb_apis
Browse files Browse the repository at this point in the history
add esb get_systems,get_components apis
  • Loading branch information
alex-smile authored Jan 15, 2020
2 parents 29756e6 + 30e0bcd commit f65e133
Show file tree
Hide file tree
Showing 13 changed files with 437 additions and 1 deletion.
5 changes: 5 additions & 0 deletions paas-ce/paas/esb/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,9 @@
'label': _(u'蓝鲸监控'),
'remark': u'蓝鲸监控',
},
'ESB': {
'name': 'ESB',
'label': u'API网关',
'remark': u'API网关',
},
}
8 changes: 8 additions & 0 deletions paas-ce/paas/esb/components/bk/apisv2/esb/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 |
Original file line number Diff line number Diff line change
@@ -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 |
Original file line number Diff line number Diff line change
@@ -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 |
Original file line number Diff line number Diff line change
@@ -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 | 备注 |
87 changes: 87 additions & 0 deletions paas-ce/paas/esb/components/bk/apisv2/esb/get_components.py
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit f65e133

Please sign in to comment.