mirror of
https://github.com/alibaba/higress.git
synced 2026-06-05 02:27:28 +08:00
update plugins doc (#1305)
This commit is contained in:
@@ -1,7 +1,18 @@
|
||||
# 功能说明
|
||||
---
|
||||
title: 请求协议校验
|
||||
keywords: [higress,request validation]
|
||||
description: 请求协议校验插件配置参考
|
||||
---
|
||||
|
||||
## 功能说明
|
||||
`request-validation`插件用于提前验证向上游服务转发的请求。该插件使用`JSON Schema`机制进行数据验证,可以验证请求的body及header数据。
|
||||
|
||||
# 配置字段
|
||||
## 运行属性
|
||||
|
||||
插件执行阶段:`认证阶段`
|
||||
插件执行优先级:`220`
|
||||
|
||||
## 配置字段
|
||||
|
||||
| 名称 | 数据类型 | 填写要求 | 默认值 | 描述 |
|
||||
| -------- | -------- | -------- |-----| -------- |
|
||||
@@ -14,9 +25,9 @@
|
||||
|
||||
**校验规则对header和body是一样的,下面以body为例说明**
|
||||
|
||||
# 配置示例
|
||||
## 配置示例
|
||||
|
||||
## 枚举(Enum)验证
|
||||
### 枚举(Enum)验证
|
||||
```yaml
|
||||
body_schema:
|
||||
type: object
|
||||
@@ -31,7 +42,7 @@ body_schema:
|
||||
default: "enum_string_1"
|
||||
```
|
||||
|
||||
## 布尔(Boolean)验证
|
||||
### 布尔(Boolean)验证
|
||||
```yaml
|
||||
body_schema:
|
||||
type: object
|
||||
@@ -43,7 +54,7 @@ body_schema:
|
||||
default: true
|
||||
```
|
||||
|
||||
## 数字范围(Number or Integer)验证
|
||||
### 数字范围(Number or Integer)验证
|
||||
```yaml
|
||||
body_schema:
|
||||
type: object
|
||||
@@ -56,7 +67,7 @@ body_schema:
|
||||
maximum: 10
|
||||
```
|
||||
|
||||
## 字符串长度(String)验证
|
||||
### 字符串长度(String)验证
|
||||
```yaml
|
||||
body_schema:
|
||||
type: object
|
||||
@@ -69,7 +80,7 @@ body_schema:
|
||||
maxLength: 10
|
||||
```
|
||||
|
||||
## 正则表达式(Regex)验证
|
||||
### 正则表达式(Regex)验证
|
||||
```yaml
|
||||
body_schema:
|
||||
type: object
|
||||
@@ -83,7 +94,7 @@ body_schema:
|
||||
pattern: "^[a-zA-Z0-9_]+$"
|
||||
```
|
||||
|
||||
## 数组(Array)验证
|
||||
### 数组(Array)验证
|
||||
```yaml
|
||||
body_schema:
|
||||
type: object
|
||||
@@ -101,7 +112,7 @@ body_schema:
|
||||
default: [1, 2, 3]
|
||||
```
|
||||
|
||||
## 多字段组合(Combined)验证
|
||||
### 多字段组合(Combined)验证
|
||||
```yaml
|
||||
body_schema:
|
||||
type: object
|
||||
@@ -128,7 +139,7 @@ body_schema:
|
||||
pattern: "^[a-zA-Z0-9_]+$"
|
||||
```
|
||||
|
||||
## 自定义拒绝信息
|
||||
### 自定义拒绝信息
|
||||
```yaml
|
||||
body_schema:
|
||||
type: object
|
||||
@@ -141,6 +152,3 @@ rejected_code: 403
|
||||
rejected_msg: "请求被拒绝"
|
||||
```
|
||||
|
||||
# 本地调试
|
||||
|
||||
参考[使用 GO 语言开发 WASM 插件](https://higress.io/zh-cn/docs/user/wasm-go#%E4%B8%89%E6%9C%AC%E5%9C%B0%E8%B0%83%E8%AF%95)
|
||||
149
plugins/wasm-go/extensions/request-validation/README_EN.md
Normal file
149
plugins/wasm-go/extensions/request-validation/README_EN.md
Normal file
@@ -0,0 +1,149 @@
|
||||
---
|
||||
title: Request Protocol Validation
|
||||
keywords: [higress,request validation]
|
||||
description: Configuration reference for request protocol validation plugin
|
||||
---
|
||||
## Function Description
|
||||
The `request-validation` plugin is used to validate requests forwarded to upstream services in advance. This plugin utilizes the `JSON Schema` mechanism for data validation, capable of validating both the body and header data of requests.
|
||||
|
||||
## Execution Attributes
|
||||
Plugin Execution Phase: `Authentication Phase`
|
||||
Plugin Execution Priority: `220`
|
||||
|
||||
## Configuration Fields
|
||||
| Name | Data Type | Requirements | Default Value | Description |
|
||||
|-----------------|-----------|--------------|---------------|---------------------------------------------------|
|
||||
| header_schema | object | Optional | - | Configuration for JSON Schema to validate request headers |
|
||||
| body_schema | object | Optional | - | Configuration for JSON Schema to validate request body |
|
||||
| rejected_code | number | Optional | 403 | HTTP status code returned when the request is rejected |
|
||||
| rejected_msg | string | Optional | - | HTTP response body returned when the request is rejected |
|
||||
| enable_swagger | bool | Optional | false | Configuration to enable Swagger documentation validation |
|
||||
| enable_oas3 | bool | Optional | false | Configuration to enable OAS3 documentation validation |
|
||||
|
||||
**Validation rules for header and body are the same, below is an example using body.**
|
||||
|
||||
## Configuration Examples
|
||||
### Enumeration (Enum) Validation
|
||||
```yaml
|
||||
body_schema:
|
||||
type: object
|
||||
required:
|
||||
- enum_payload
|
||||
properties:
|
||||
enum_payload:
|
||||
type: string
|
||||
enum:
|
||||
- "enum_string_1"
|
||||
- "enum_string_2"
|
||||
default: "enum_string_1"
|
||||
```
|
||||
|
||||
### Boolean Validation
|
||||
```yaml
|
||||
body_schema:
|
||||
type: object
|
||||
required:
|
||||
- boolean_payload
|
||||
properties:
|
||||
boolean_payload:
|
||||
type: boolean
|
||||
default: true
|
||||
```
|
||||
|
||||
### Number Range (Number or Integer) Validation
|
||||
```yaml
|
||||
body_schema:
|
||||
type: object
|
||||
required:
|
||||
- integer_payload
|
||||
properties:
|
||||
integer_payload:
|
||||
type: integer
|
||||
minimum: 1
|
||||
maximum: 10
|
||||
```
|
||||
|
||||
### String Length Validation
|
||||
```yaml
|
||||
body_schema:
|
||||
type: object
|
||||
required:
|
||||
- string_payload
|
||||
properties:
|
||||
string_payload:
|
||||
type: string
|
||||
minLength: 1
|
||||
maxLength: 10
|
||||
```
|
||||
|
||||
### Regular Expression (Regex) Validation
|
||||
```yaml
|
||||
body_schema:
|
||||
type: object
|
||||
required:
|
||||
- regex_payload
|
||||
properties:
|
||||
regex_payload:
|
||||
type: string
|
||||
minLength: 1
|
||||
maxLength: 10
|
||||
pattern: "^[a-zA-Z0-9_]+$"
|
||||
```
|
||||
|
||||
### Array Validation
|
||||
```yaml
|
||||
body_schema:
|
||||
type: object
|
||||
required:
|
||||
- array_payload
|
||||
properties:
|
||||
array_payload:
|
||||
type: array
|
||||
minItems: 1
|
||||
items:
|
||||
type: integer
|
||||
minimum: 1
|
||||
maximum: 10
|
||||
uniqueItems: true
|
||||
default: [1, 2, 3]
|
||||
```
|
||||
|
||||
### Combined Validation
|
||||
```yaml
|
||||
body_schema:
|
||||
type: object
|
||||
required:
|
||||
- boolean_payload
|
||||
- array_payload
|
||||
- regex_payload
|
||||
properties:
|
||||
boolean_payload:
|
||||
type: boolean
|
||||
array_payload:
|
||||
type: array
|
||||
minItems: 1
|
||||
items:
|
||||
type: integer
|
||||
minimum: 1
|
||||
maximum: 10
|
||||
uniqueItems: true
|
||||
default: [1, 2, 3]
|
||||
regex_payload:
|
||||
type: string
|
||||
minLength: 1
|
||||
maxLength: 10
|
||||
pattern: "^[a-zA-Z0-9_]+$"
|
||||
```
|
||||
|
||||
### Custom Rejection Message
|
||||
```yaml
|
||||
body_schema:
|
||||
type: object
|
||||
required:
|
||||
- boolean_payload
|
||||
properties:
|
||||
boolean_payload:
|
||||
type: boolean
|
||||
rejected_code: 403
|
||||
rejected_msg: "Request rejected"
|
||||
```
|
||||
Reference in New Issue
Block a user