itecdn 5.x用户文档
itecdn 5.x / 用户 API

批量更新 ACL

PUT/v1/acls

在一个事务中批量更新一个或多个 ACL。请求体必须是非空数组,每个元素通过 id 指定目标 ACL,并只提交需要修改的字段;普通用户只能更新自己的 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 同时发送。"
  }
}

请求参数

未定义路径、查询或请求头参数。

请求体 · 必填

application/json

array <object>

要批量更新的 ACL 数组;所有元素在同一个数据库事务中处理。

数组元素 · object
字段类型必填说明与约束
idinteger (int64)必填

要更新的 ACL ID;目标必须存在且当前身份有权管理。

约束 / 默认值 / 示例
{
  "format": "int64",
  "minimum": 1
}
namestring可选

新的 ACL 名称;不能为空,且在 ACL 所属用户下必须唯一。

约束 / 默认值 / 示例
{
  "minLength": 1
}
desstring可选

新的 ACL 备注说明,可设置为空字符串。

default_actionstring可选

所有规则均未匹配时执行的新默认动作:reject 拒绝请求,allow 放行请求。

约束 / 默认值 / 示例
{
  "enum": [
    "reject",
    "allow"
  ]
}
reject_codestring可选

默认拒绝动作使用的新响应方式;403 表示直接拒绝,302 表示重定向。

约束 / 默认值 / 示例
{
  "enum": [
    "403",
    "302"
  ]
}
redirect_urlstring可选

新的默认重定向地址;最终 reject_code 为 302 时不能为空。

dataarray <object>可选

替换现有配置的完整 ACL 规则数组;条目数不得超过系统配置的 acl-max-limit。

约束 / 默认值 / 示例
{
  "minItems": 1
}
展开字段结构

替换现有配置的完整 ACL 规则数组;条目数不得超过系统配置的 acl-max-limit。

数组元素 · object
字段类型必填说明与约束
acl_actionstring必填

该条规则匹配后执行的动作:reject 拒绝请求,allow 放行请求。

约束 / 默认值 / 示例
{
  "enum": [
    "reject",
    "allow"
  ]
}
acl_codestring可选

该条规则执行 reject 时使用的响应方式;省略时为 403。

约束 / 默认值 / 示例
{
  "enum": [
    "403",
    "302"
  ],
  "default": "403"
}
acl_urlstring可选

该条规则的 acl_code 为 302 时必填的重定向地址。

约束 / 默认值 / 示例
{
  "default": ""
}
acl_matcherarray <object>必填

该条 ACL 规则的新匹配条件;每个条件由匹配项、操作符和值组成。

展开字段结构

该条 ACL 规则的新匹配条件;每个条件由匹配项、操作符和值组成。

数组元素 · object
字段类型必填说明与约束
itemstring必填

要检查的请求或客户端属性,例如 ip、host、uri、国家代码或 TLS 指纹。

约束 / 默认值 / 示例
{
  "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"
  ]
}
opstring必填

匹配操作符;ip_range 和 !ip_range 用于判断 IP 是否属于指定 CIDR 范围。

约束 / 默认值 / 示例
{
  "enum": [
    ">",
    "=",
    "!=",
    "!contain",
    "contain",
    "prefix",
    "suffix",
    "regex",
    "!regex",
    "exists",
    "!exists",
    "ip_range",
    "!ip_range"
  ]
}
valuestring可选

参与匹配的值。服务端会移除空行并转为小写;IP 范围操作符使用空白分隔一个或多个 CIDR。

约束 / 默认值 / 示例
{
  "default": ""
}
enableinteger可选

更新后的启用状态:1 表示启用,0 表示禁用。禁用前 ACL 不能仍被网站引用。

约束 / 默认值 / 示例
{
  "enum": [
    0,
    1
  ]
}
uidinteger (int64)可选

仅管理员可传,用于按指定用户执行名称和网站引用校验;该字段不会转移 ACL 的所属用户。

约束 / 默认值 / 示例
{
  "format": "int64",
  "minimum": 1
}
完整 Schema
{
  "type": "array",
  "minItems": 1,
  "description": "要批量更新的 ACL 数组;所有元素在同一个数据库事务中处理。",
  "items": {
    "type": "object",
    "required": [
      "id"
    ],
    "properties": {
      "id": {
        "type": "integer",
        "format": "int64",
        "minimum": 1,
        "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
  }
}

示例

[
  {
    "id": 1,
    "name": "办公网络访问规则",
    "default_action": "reject",
    "data": [
      {
        "acl_action": "allow",
        "acl_matcher": [
          {
            "item": "ip",
            "op": "ip_range",
            "value": "192.0.2.0/24"
          }
        ]
      }
    ]
  },
  {
    "id": 2,
    "enable": 0
  }
]

请求体示例

[
  {
    "id": 0,
    "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 仍被网站引用而尝试禁用时,通过字符串 code 和 msg 返回业务错误,且本批次修改全部回滚。

application/json

oneOf

oneOf · 1 · object
字段类型必填说明与约束
codeinteger必填

成功状态码,整批 ACL 更新成功时固定为 0。

约束 / 默认值 / 示例
{
  "enum": [
    0
  ]
}
msgstring必填

整批 ACL 更新并提交事务后返回的确认消息。

约束 / 默认值 / 示例
{
  "enum": [
    "更新ACL成功"
  ]
}
datastring必填

批量更新成功时没有额外业务数据,固定为 null。

约束 / 默认值 / 示例
{
  "nullable": true,
  "enum": [
    null
  ]
}
oneOf · 2 · object
字段类型必填说明与约束
codestring必填

业务错误码。常见值包括请求体格式错误 acl-33、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。

msgstring必填

与业务错误码对应的中文校验失败或权限错误原因。

datastring必填

业务错误时固定为空字符串。

约束 / 默认值 / 示例
{
  "enum": [
    ""
  ]
}
完整 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-33`、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" \
  --header "access-token: YOUR_ACCESS_TOKEN" \
  --header "Content-Type: application/json" \
  --data '[{"id": 0, "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}]'

查看完整接口 JSON