Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fixtures/plugins.yaml): new plugins validation #1113

Merged
merged 5 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/dashboard/apigateway/apigateway/apis/web/plugin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ class PluginConfigRetrieveUpdateDestroyApi(
lookup_field = "id"

def _check_if_changed(self, input_data: Dict[str, Any], instance: PluginConfig) -> bool:

try:
input_yaml = yaml_loads(input_data["yaml"])
current_yaml = yaml_loads(instance.yaml)
Expand All @@ -351,7 +350,6 @@ def perform_update(self, serializer):
self.validate_code(type_id=serializer.validated_data["type_id"])

if self._check_if_changed(dict(serializer.validated_data), serializer.instance):

data_before = get_model_dict(serializer.instance)

super().perform_update(serializer)
Expand Down
3 changes: 3 additions & 0 deletions src/dashboard/apigateway/apigateway/common/plugin/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
)
from apigateway.utils.yaml import yaml_loads

from .normalizer import format_fault_injection_config

VARS_ALLOWED_COMPARISON_SYMBOLS = {"==", "~=", ">", ">=", "<", "<=", "~~", "~*", "in", "has", "!", "ipmatch"}


Expand Down Expand Up @@ -195,6 +197,7 @@ def check(self, payload: str):
if not loaded_data:
raise ValueError("YAML cannot be empty")

loaded_data = format_fault_injection_config(loaded_data)
abort_data = loaded_data.get("abort")
delay_data = loaded_data.get("delay")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from apigateway.apps.plugin.constants import PluginTypeCodeEnum
from apigateway.utils.ip import parse_ip_content_to_list

from .normalizer import format_fault_injection_config


class PluginConvertor(ABC):
plugin_type_code: ClassVar[PluginTypeCodeEnum]
Expand Down Expand Up @@ -145,6 +147,9 @@ class FaultInjectionConvertor(PluginConvertor):
plugin_type_code: ClassVar[PluginTypeCodeEnum] = PluginTypeCodeEnum.FAULT_INJECTION

def convert(self, config: Dict[str, Any]) -> Dict[str, Any]:
# NOTE: while the dynamic form textarea would pass here, we should clean it up
config = format_fault_injection_config(config)

if config.get("abort"):
abort = config["abort"]
if abort.get("vars"):
Expand Down
40 changes: 40 additions & 0 deletions src/dashboard/apigateway/apigateway/common/plugin/normalizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
#
# TencentBlueKing is pleased to support the open source community by making
# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available.
# Copyright (C) 2017 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.
#
# We undertake not to change the open source license (MIT license) applicable
# to the current version of the project delivered to anyone in the future.
#
from typing import Any, Dict


def format_fault_injection_config(config: Dict[str, Any]) -> Dict[str, Any]:
"""while the dynamic form input many empty values, should be normalized!"""
if config.get("abort"):
abort = config["abort"]
if abort.get("body") == "":
del abort["body"]
if abort.get("vars") == "":
del abort["vars"]
if not abort:
del config["abort"]

if config.get("delay"):
delay = config["delay"]
if delay.get("vars") == "":
del delay["vars"]
if not delay:
del config["delay"]

return config
10 changes: 5 additions & 5 deletions src/dashboard/apigateway/apigateway/common/plugin/validator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# TencentBlueKing is pleased to support the open source community by making
# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available.
# 蓝鲸智云 - API 网关 (BlueKing - APIGateway) available.
# Copyright (C) 2017 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
Expand Down Expand Up @@ -39,14 +39,14 @@ def validate(self, plugin_type_code: str, payload: str, schema: Optional[Dict] =
:param payload: 插件 yaml 格式配置字符串
:param schema: 插件 schema 规则
"""
# 校验 apisix 额外规则,这个报错的可读性更好,有一些 json schema 中的报错信息不够直观可以重复在这里处理
checker = PluginConfigYamlChecker(plugin_type_code)
checker.check(payload)

# 校验 schema 规则
if schema:
convertor = PluginConvertorFactory.get_convertor(plugin_type_code)
try:
validate(convertor.convert(yaml_loads(payload)), schema=schema)
except JsonSchemaValidationError as err:
raise ValueError(f"{err.message}, path {list(err.absolute_path)}")

# 校验 apisix 额外规则
checker = PluginConfigYamlChecker(plugin_type_code)
checker.check(payload)
84 changes: 84 additions & 0 deletions src/dashboard/apigateway/apigateway/data/version_log/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,87 @@
<!-- 2024-11-15 -->
# V1.15.0 版本更新日志

### 功能优化

- 运行数据-统计报表:整体页面重构
- 权限管理-应用权限: 整体页面重构,合并了两种授权维度成一个列表页/导出
- 网关/组件API 文档和 网关/组件SDK合并成一个页面: API 文档,需测试所有功能
- 优化日志查询页面:搜索历史/图标选中缩小范围
- 优化在线调试页面
- 资源版本:支持生成java sdk
- 资源配置:支持启用 websocket
- 资源维度新增 4 个插件:mock/熔断/请求校验/故障注入,需要测试功能;
- 升级底层django以及所有依赖库到最新版本

---

<!-- 2024-10-30 -->
# V1.14.5 版本更新日志

### 缺陷修复

- 修复资源配置页
- 搜索后页码错误的问题
- 资源配置表格高度问题
- 修复流水日志
- 新增日志查询的搜索历史
- 日志查询语法报错问题
- 流水日志导出数据为空问题
- 修复在线调试 headers 切换重置问题
- 修复资源文档上传失败的问题
- 修复发布环境校验的后端配置问题
- 更新 bkui 以修复 xss 漏洞
- 修复在线调试:响应状态码颜色细分
- 修复网关基本信息:维护人员文本的 tooltips
- 优化资源版本对比展示

---

<!-- 2024-10-09 -->
# V1.14.4 版本更新日志

### 缺陷修复

- 修复在线调试错误的校验

---

<!-- 2024-10-08 -->
# V1.14.3 版本更新日志

### 缺陷修复

- 修复编辑插件时说明消失的问题
- 文档导入 zip 上传失败提示
- XSS 漏洞修复

---

<!-- 2024-09-26 -->
# V1.14.2 版本更新日志

### 缺陷修复

- 资源导入官网文档链接错误
- open api 资源同步支持 delete

---

<!-- 2024-09-25 -->
# V1.14.1 版本更新日志

### 缺陷修复

- 环境概览:资源插件列表合并耗时太长
- 修复确认离开已编辑表单的页面后仍出现提示弹窗的问题

### 功能优化

- 禁止选中并发布 schema v1 资源版本
- 规范化文档中心跳转链接

---

<!-- 2024-09-13 -->
# V1.14.0 版本更新日志

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,87 @@
<!-- 2024-11-15 -->
# V1.15.0 Release Log

### Features

- Data Operation - Statistical Report: Complete page redesign.
- Permission Management - Application Permissions: Full page redesign, merging two permission dimensions into a single list page/export.
- Gateway/Component API Documentation and Gateway/Component SDK: Merged into a single page, API Documentation, with all functions needing testing.
- Optimized Log Query Page: Search history/icon selection to narrow scope.
- Optimized Online Debugging Page.
- Resource Version: Support for generating Java SDK.
- Resource Configuration: Support for enabling WebSocket.
- Added 4 new plugins to Resource Dimension: Mock, Circuit Breaker, Request Validation, and Fault Injection, with functionality needing testing.
- Upgraded the underlying Django framework and all dependency libraries to the latest version.

---

<!-- 2024-10-30 -->
# V1.14.5 Release Log

### Bug Fixes

- Fixed issues on the resource configuration page
- Incorrect page number after search
- Resource configuration table height issue
- Fixed issues in pipeline logs
- Added search history for log queries
- Syntax error in log queries
- Data export issue resulting in empty logs
- Fixed issue with header reset when switching in online debugging
- Fixed the issue with resource documentation upload failure
- Fixed backend configuration issues for environment validation during publishing
- Updated bkui to fix XSS vulnerabilities
- Fixed online debugging: refined response status code color differentiation
- Fixed gateway basic information: tooltips for maintenance personnel text
- Optimized resource version comparison display

---

<!-- 2024-10-09 -->
# V1.14.4 Release Log

### Bug Fixes

- Fixed incorrect validation in online debugging

---

<!-- 2024-10-08 -->
# V1.14.3 Release Log

### Bug Fixes

- Fixed the issue where the description disappears when editing a plugin
- Error notification for failed ZIP uploads during document import
- XSS vulnerability fix

---

<!-- 2024-09-26 -->
# V1.14.2 Release Log

### Bug Fixes

- Fixed incorrect official documentation link for resource import
- Added support for delete operation in OpenAPI resource synchronization

---

<!-- 2024-09-25 -->
# V1.14.1 Release Log

### Bug Fixes

- Environment Overview: Resource plugin list merge takes too long
- Fixed issue where a prompt dialog still appears after leaving a page with an edited form

### Features

- Prohibit selecting and publishing schema v1 resource versions
- Standardize documentation center redirect links

---

<!-- 2024-09-13 -->
# V1.14.0 Release Log

Expand Down
Loading
Loading