更新单个 ACL
/v1/acls/{acl_id}根据路径中的 ACL ID 局部更新一条 ACL。请求体必须是 JSON 对象,只需提交要修改的字段;服务端会将路径 acl_id 作为真实目标 ID,即使请求体包含 id 也会被路径值覆盖。普通用户只能更新自己的 ACL,管理员可更新其他用户的 ACL。修改已被网站引用且处于启用状态的 ACL 时会创建同步任务;禁用 ACL 时会创建删除任务,但仍被网站引用的 ACL 不允许直接禁用。
身份认证
access-token
api-key + api-secret
认证定义
{
"AccessToken": {
"type": "apiKey",
"in": "header",
"name": "access-token",
"description": "通过登录接口获得的短期访问令牌。"
},
"ApiKey": {
"type": "apiKey",
"in": "header",
"name": "api-key",
"description": "API Key;必须和 api-secret 同时发送。"
},
"ApiSecret": {
"type": "apiKey",
"in": "header",
"name": "api-secret",
"description": "API Secret;必须和 api-key 同时发送。"
}
}请求参数
| 参数 | 位置 | 类型 | 必填 | 说明与约束 |
|---|---|---|---|---|
acl_id | path | integer (int64) | 必填 | 要更新的 ACL ID;目标必须存在且当前身份有权管理。 完整参数定义 |
请求体 · 必填
application/json
object
| 字段 | 类型 | 必填 | 说明与约束 | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | integer (int64) | 可选 | 兼容字段;如传入会被忽略,实际目标始终由路径中的 约束 / 默认值 / 示例 | ||||||||||||||||||||||||||||||||||||
name | string | 可选 | 新的 ACL 名称;不能为空,且在 ACL 所属用户下必须唯一。 约束 / 默认值 / 示例 | ||||||||||||||||||||||||||||||||||||
des | string | 可选 | 新的 ACL 备注说明,可设置为空字符串。 | ||||||||||||||||||||||||||||||||||||
default_action | string | 可选 | 所有规则均未匹配时执行的新默认动作: 约束 / 默认值 / 示例 | ||||||||||||||||||||||||||||||||||||
reject_code | string | 可选 | 默认拒绝动作使用的新响应方式;403 表示直接拒绝,302 表示重定向。 约束 / 默认值 / 示例 | ||||||||||||||||||||||||||||||||||||
redirect_url | string | 可选 | 新的默认重定向地址;最终 | ||||||||||||||||||||||||||||||||||||
data | array <object> | 可选 | 替换现有配置的完整 ACL 规则数组;条目数不得超过系统配置的 约束 / 默认值 / 示例展开字段结构替换现有配置的完整 ACL 规则数组;条目数不得超过系统配置的 数组元素 · object
| ||||||||||||||||||||||||||||||||||||
enable | integer | 可选 | 更新后的启用状态:1 表示启用,0 表示禁用。禁用前 ACL 不能仍被网站引用。 约束 / 默认值 / 示例 | ||||||||||||||||||||||||||||||||||||
uid | integer (int64) | 可选 | 仅管理员可传,用于按指定用户执行名称和网站引用校验;该字段不会转移 ACL 的所属用户。 约束 / 默认值 / 示例 |
完整 Schema
{
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"deprecated": true,
"description": "兼容字段;如传入会被忽略,实际目标始终由路径中的 `acl_id` 决定。"
},
"name": {
"type": "string",
"minLength": 1,
"description": "新的 ACL 名称;不能为空,且在 ACL 所属用户下必须唯一。"
},
"des": {
"type": "string",
"description": "新的 ACL 备注说明,可设置为空字符串。"
},
"default_action": {
"type": "string",
"enum": [
"reject",
"allow"
],
"description": "所有规则均未匹配时执行的新默认动作:`reject` 拒绝请求,`allow` 放行请求。"
},
"reject_code": {
"type": "string",
"enum": [
"403",
"302"
],
"description": "默认拒绝动作使用的新响应方式;403 表示直接拒绝,302 表示重定向。"
},
"redirect_url": {
"type": "string",
"description": "新的默认重定向地址;最终 `reject_code` 为 302 时不能为空。"
},
"data": {
"type": "array",
"minItems": 1,
"description": "替换现有配置的完整 ACL 规则数组;条目数不得超过系统配置的 `acl-max-limit`。",
"items": {
"type": "object",
"required": [
"acl_action",
"acl_matcher"
],
"properties": {
"acl_action": {
"type": "string",
"enum": [
"reject",
"allow"
],
"description": "该条规则匹配后执行的动作:`reject` 拒绝请求,`allow` 放行请求。"
},
"acl_code": {
"type": "string",
"enum": [
"403",
"302"
],
"default": "403",
"description": "该条规则执行 `reject` 时使用的响应方式;省略时为 403。"
},
"acl_url": {
"type": "string",
"default": "",
"description": "该条规则的 `acl_code` 为 302 时必填的重定向地址。"
},
"acl_matcher": {
"type": "array",
"description": "该条 ACL 规则的新匹配条件;每个条件由匹配项、操作符和值组成。",
"items": {
"type": "object",
"required": [
"item",
"op"
],
"properties": {
"item": {
"type": "string",
"enum": [
"count404",
"uniq_ua",
"header",
"ip",
"host",
"accept_language",
"user_agent",
"referer",
"uri",
"req_uri",
"req_method",
"country_iso_code",
"asnumber",
"province",
"city",
"isp",
"protocol",
"tls_fp",
"uniq_tls_fp",
"server_port"
],
"description": "要检查的请求或客户端属性,例如 `ip`、`host`、`uri`、国家代码或 TLS 指纹。"
},
"op": {
"type": "string",
"enum": [
">",
"=",
"!=",
"!contain",
"contain",
"prefix",
"suffix",
"regex",
"!regex",
"exists",
"!exists",
"ip_range",
"!ip_range"
],
"description": "匹配操作符;`ip_range` 和 `!ip_range` 用于判断 IP 是否属于指定 CIDR 范围。"
},
"value": {
"type": "string",
"default": "",
"description": "参与匹配的值。服务端会移除空行并转为小写;IP 范围操作符使用空白分隔一个或多个 CIDR。"
}
},
"additionalProperties": false
}
}
},
"additionalProperties": false
}
},
"enable": {
"type": "integer",
"enum": [
0,
1
],
"description": "更新后的启用状态:1 表示启用,0 表示禁用。禁用前 ACL 不能仍被网站引用。"
},
"uid": {
"type": "integer",
"format": "int64",
"minimum": 1,
"description": "仅管理员可传,用于按指定用户执行名称和网站引用校验;该字段不会转移 ACL 的所属用户。"
}
},
"additionalProperties": false
}示例
{
"name": "办公网络访问规则",
"default_action": "reject",
"data": [
{
"acl_action": "allow",
"acl_matcher": [
{
"item": "ip",
"op": "ip_range",
"value": "192.0.2.0/24"
}
]
}
]
}请求体示例
{
"name": "string",
"des": "string",
"default_action": "reject",
"reject_code": "403",
"redirect_url": "string",
"data": [
{
"acl_action": "reject",
"acl_code": "403",
"acl_url": "",
"acl_matcher": [
{
"item": "count404",
"op": ">",
"value": ""
}
]
}
],
"enable": 0,
"uid": 0
}响应
HTTP 200
请求始终通过 HTTP 200 返回。单条 ACL 更新成功时返回确认消息;请求体不是对象、ACL 不存在或无权限、字段或嵌套规则校验失败、ACL 仍被网站引用而尝试禁用时,通过字符串 code 和 msg 返回业务错误,当前更新事务会回滚。
application/json
oneOf
oneOf · 1 · object
| 字段 | 类型 | 必填 | 说明与约束 |
|---|---|---|---|
code | integer | 必填 | 成功状态码,ACL 更新成功时固定为 0。 约束 / 默认值 / 示例 |
msg | string | 必填 | ACL 更新并提交事务后返回的确认消息。 约束 / 默认值 / 示例 |
data | string | 必填 | 单条更新成功时没有额外业务数据,固定为 null。 约束 / 默认值 / 示例 |
oneOf · 2 · object
| 字段 | 类型 | 必填 | 说明与约束 |
|---|---|---|---|
code | string | 必填 | 业务错误码。常见值包括请求体格式错误 |
msg | string | 必填 | 与业务错误码对应的中文校验失败或权限错误原因。 |
data | string | 必填 | 业务错误时固定为空字符串。 约束 / 默认值 / 示例 |
完整 Schema
{
"oneOf": [
{
"type": "object",
"required": [
"code",
"msg",
"data"
],
"properties": {
"code": {
"type": "integer",
"enum": [
0
],
"description": "成功状态码,ACL 更新成功时固定为 0。"
},
"msg": {
"type": "string",
"enum": [
"更新ACL成功"
],
"description": "ACL 更新并提交事务后返回的确认消息。"
},
"data": {
"type": "string",
"nullable": true,
"enum": [
null
],
"description": "单条更新成功时没有额外业务数据,固定为 null。"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"code",
"msg",
"data"
],
"properties": {
"code": {
"type": "string",
"description": "业务错误码。常见值包括请求体格式错误 `acl-5`、ID 错误或资源不存在 `acl-6/acl-7`、权限错误 `acl-42/acl-43`、名称错误 `acl-9/acl-11`、默认动作错误 `acl-14/acl-15`、规则错误 `acl-17` 至 `acl-25`、启用状态错误 `acl-27/acl-28/acl-29` 以及重定向错误 `acl-35` 至 `acl-40`。"
},
"msg": {
"type": "string",
"description": "与业务错误码对应的中文校验失败或权限错误原因。"
},
"data": {
"type": "string",
"enum": [
""
],
"description": "业务错误时固定为空字符串。"
}
},
"additionalProperties": false
}
]
}示例
{
"code": 0,
"msg": "更新ACL成功",
"data": null
}cURL 示例
根据文档生成;请替换主控地址、路径参数和凭证,并按上表补充查询参数。
curl --request PUT \
"https://master.example.invalid/v1/acls/{acl_id}" \
--header "access-token: YOUR_ACCESS_TOKEN" \
--header "Content-Type: application/json" \
--data '{"name": "string", "des": "string", "default_action": "reject", "reject_code": "403", "redirect_url": "string", "data": [{"acl_action": "reject", "acl_code": "403", "acl_url": "", "acl_matcher": [{"item": "count404", "op": ">", "value": ""}]}], "enable": 0, "uid": 0}'