{
  "tags": [
    "访问控制"
  ],
  "description": "创建一组可供网站引用的 ACL 访问控制规则。接口会校验当前用户可创建的 ACL 数量、同一用户下的名称唯一性、默认动作以及每条匹配规则；规则数量上限由系统配置 `acl-max-limit` 决定。普通用户只能为自己创建 ACL；管理员可通过 `uid` 指定所属用户。创建成功后 ACL 会保存为独立配置并返回新 ACL ID。",
  "operationId": "user_post_v1_acls",
  "security": [
    {
      "AccessToken": []
    },
    {
      "ApiKey": [],
      "ApiSecret": []
    }
  ],
  "responses": {
    "200": {
      "description": "请求始终通过 HTTP 200 返回。创建成功时返回新 ACL ID；配额、名称、默认动作、重定向配置或嵌套匹配规则不合法时，通过字符串 `code` 和 `msg` 返回具体业务错误。",
      "content": {
        "application/json": {
          "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": "integer",
                    "format": "int64",
                    "minimum": 1,
                    "description": "新创建 ACL 的唯一 ID。"
                  }
                },
                "additionalProperties": false
              },
              {
                "type": "object",
                "required": [
                  "code",
                  "msg",
                  "data"
                ],
                "properties": {
                  "code": {
                    "type": "string",
                    "description": "业务错误码。常见值包括配额超限 `acl-8`、名称错误 `acl-9/acl-11/acl-12`、默认动作错误 `acl-14/acl-15/acl-16`、规则错误 `acl-17` 至 `acl-25`、缺少规则 `acl-26`、启用状态错误 `acl-27/acl-28`、重定向错误 `acl-35` 至 `acl-40` 以及管理员权限错误 `acl-43`。"
                  },
                  "msg": {
                    "type": "string",
                    "description": "与业务错误码对应的中文校验失败原因。"
                  },
                  "data": {
                    "type": "string",
                    "enum": [
                      ""
                    ],
                    "description": "业务错误时固定为空字符串。"
                  }
                },
                "additionalProperties": false
              }
            ]
          },
          "example": {
            "code": 0,
            "msg": "ACL添加成功",
            "data": 1
          }
        }
      }
    }
  },
  "x-python-handler": "site.AclAPI",
  "x-python-route-line": 374,
  "x-audience": "user",
  "x-auth": "user",
  "x-reviewed": true,
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "required": [
            "name",
            "default_action",
            "data"
          ],
          "properties": {
            "name": {
              "type": "string",
              "minLength": 1,
              "description": "ACL 名称；不能为空，且在所属用户的 ACL 中必须唯一。"
            },
            "des": {
              "type": "string",
              "default": "",
              "description": "ACL 的备注说明；省略时保存为空字符串。"
            },
            "default_action": {
              "type": "string",
              "enum": [
                "reject",
                "allow"
              ],
              "description": "所有 ACL 规则均未匹配时执行的默认动作：`reject` 拒绝请求，`allow` 放行请求。"
            },
            "reject_code": {
              "type": "string",
              "enum": [
                "403",
                "302"
              ],
              "default": "403",
              "description": "默认动作拒绝请求时的响应方式；403 表示直接拒绝，302 表示重定向。"
            },
            "redirect_url": {
              "type": "string",
              "default": "",
              "description": "`reject_code` 为 302 时必填的重定向地址；使用 403 时可省略。"
            },
            "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
              ],
              "default": 1,
              "description": "新 ACL 的启用状态：1 表示启用，0 表示禁用；省略时启用。"
            },
            "uid": {
              "type": "integer",
              "format": "int64",
              "minimum": 1,
              "description": "新 ACL 的所属用户 ID，仅管理员可传；普通用户传入时返回管理员权限错误。"
            }
          },
          "additionalProperties": false
        },
        "example": {
          "name": "仅允许指定网段",
          "des": "允许文档示例网段访问",
          "default_action": "reject",
          "reject_code": "403",
          "data": [
            {
              "acl_action": "allow",
              "acl_matcher": [
                {
                  "item": "ip",
                  "op": "ip_range",
                  "value": "192.0.2.0/24"
                }
              ]
            }
          ],
          "enable": 1
        }
      }
    }
  },
  "parameters": [],
  "x-itecdn-source-reviewed": true,
  "extensions": [
    {
      "key": "x-python-handler",
      "value": "site.AclAPI"
    },
    {
      "key": "x-python-route-line",
      "value": 374
    },
    {
      "key": "x-audience",
      "value": "user"
    },
    {
      "key": "x-auth",
      "value": "user"
    },
    {
      "key": "x-reviewed",
      "value": true
    },
    {
      "key": "x-itecdn-source-reviewed",
      "value": true
    }
  ],
  "method": "post",
  "path": "/v1/acls",
  "servers": [
    {
      "url": "https://master.example.invalid",
      "description": "不可调用的示例地址；复制示例后替换为自己的主控域名。"
    }
  ],
  "securitySchemes": {
    "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 同时发送。"
    }
  },
  "jsonRequestBodyExample": {
    "name": "string",
    "des": "",
    "default_action": "reject",
    "reject_code": "403",
    "redirect_url": "",
    "data": [
      {
        "acl_action": "reject",
        "acl_code": "403",
        "acl_url": "",
        "acl_matcher": [
          {
            "item": "count404",
            "op": ">",
            "value": ""
          }
        ]
      }
    ],
    "enable": 1,
    "uid": 0
  },
  "info": {
    "title": "itecdn v5 用户 API",
    "version": "5.x",
    "description": "itecdn v5.x Python 主控用户 API。本文档不适用于 v6 或其它实现。"
  },
  "postman": {
    "name": "创建 ACL",
    "description": {
      "content": "创建一组可供网站引用的 ACL 访问控制规则。接口会校验当前用户可创建的 ACL 数量、同一用户下的名称唯一性、默认动作以及每条匹配规则；规则数量上限由系统配置 `acl-max-limit` 决定。普通用户只能为自己创建 ACL；管理员可通过 `uid` 指定所属用户。创建成功后 ACL 会保存为独立配置并返回新 ACL ID。",
      "type": "text/plain"
    },
    "url": {
      "path": [
        "v1",
        "acls"
      ],
      "host": [
        "{{baseUrl}}"
      ],
      "query": [],
      "variable": []
    },
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "method": "POST",
    "body": {
      "mode": "raw",
      "raw": "",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "auth": {
      "type": "apikey",
      "apikey": [
        {
          "type": "any",
          "value": "access-token",
          "key": "key"
        },
        {
          "type": "any",
          "value": "{{apiKey}}",
          "key": "value"
        },
        {
          "type": "any",
          "value": "header",
          "key": "in"
        }
      ]
    }
  }
}