{
  "tags": [
    "CC 防护"
  ],
  "description": "按路径 ID 更新一条 CC 规则组。请求体必须是 JSON 对象，路径中的 `rule_id` 是唯一目标标识；即使请求体包含 `id`，服务端也会用路径 ID 覆盖。名称、排序、备注、规则步骤、定向可见用户、启用状态和前台显示状态均为可选字段，只更新明确提供的字段。普通用户只能更新归属于自己的自定义规则组，管理员可更新其他用户或系统内置规则组。传入空对象也会递增版本号并刷新更新时间。修改已启用且被网站使用的规则步骤会创建节点同步任务；禁用前必须确认规则组未被网站、全局默认值、用户默认值、防火墙默认页规则或自动规则切换引用，禁用成功时会创建节点删除任务。",
  "operationId": "user_put_v1_cc_rules_rule_id",
  "security": [
    {
      "AccessToken": []
    },
    {
      "ApiKey": [],
      "ApiSecret": []
    }
  ],
  "responses": {
    "200": {
      "description": "业务结果通过 HTTP 200 返回。目标规则组更新并提交后返回确认消息；请求体格式、目标记录、访问权限、名称、排序、规则步骤、引用的匹配器或过滤器、定向用户、启用/显示状态、禁用前引用检查、系统维护或认证校验失败时返回字符串业务错误码，事务回滚。",
      "content": {
        "application/json": {
          "schema": {
            "oneOf": [
              {
                "type": "object",
                "required": [
                  "code",
                  "msg",
                  "data"
                ],
                "properties": {
                  "code": {
                    "type": "integer",
                    "enum": [
                      0
                    ],
                    "description": "成功状态码，规则组更新并提交后固定为 0。"
                  },
                  "msg": {
                    "type": "string",
                    "enum": [
                      "更新cc规则成功"
                    ],
                    "description": "规则组更新成功后返回的确认消息。"
                  },
                  "data": {
                    "type": "string",
                    "nullable": true,
                    "enum": [
                      null
                    ],
                    "description": "更新成功时没有额外业务数据，固定为 null。"
                  }
                },
                "additionalProperties": false
              },
              {
                "type": "object",
                "required": [
                  "code",
                  "msg",
                  "data"
                ],
                "properties": {
                  "code": {
                    "type": "string",
                    "enum": [
                      "cc_rule-6",
                      "cc_rule-8",
                      "cc_rule-11",
                      "cc_rule-13",
                      "cc_rule-17",
                      "cc_rule-18",
                      "cc_rule-19",
                      "cc_rule-20",
                      "cc_rule-21",
                      "cc_rule-22",
                      "cc_rule-23",
                      "cc_rule-25",
                      "cc_rule-26",
                      "cc_rule-27",
                      "cc_rule-33",
                      "cc_rule-34",
                      "cc_rule-34-1",
                      "cc_rule-35",
                      "cc_rule-35-1",
                      "cc_rule-35-2",
                      "cc_rule-36",
                      "cc_rule-37",
                      "cc_rule-38",
                      "cc_rule-39",
                      "cc_rule-40",
                      "cc_rule-41",
                      "cc_rule-41-1",
                      "cc_rule-42",
                      "cc_rule-43",
                      "cc_rule-44",
                      "cc_rule-45",
                      "cc_rule-46",
                      "cc_rule-371",
                      "cc_rule-372",
                      "cc_rule-375",
                      "cc_rule-376",
                      "cc_rule-378",
                      "cc_rule-379",
                      "cc_rule-380",
                      "maintain",
                      "login_required"
                    ],
                    "description": "业务错误码：6 表示请求体不是 JSON 对象；8 表示规则组不存在；11、13 表示名称为空或重复；17、18 表示 data 类型错误或步骤过多；19 至 23 表示动作、引用对象、步骤状态或第二过滤器无效；25、26 表示 enable 为空或无效；27、40、43 至 46 表示规则组仍被网站或默认配置引用，或属于不可禁用的保留规则；33 至 35-2 表示步骤缺少 action、matcher、filter1 或其 ID 格式错误；36、37 表示排序为空或不是数字；38、39 表示 is_show 为空或无效；41、41-1 表示定向用户不存在或格式错误；42 表示 internal 无效；371、372 表示 mode 缺失或无效；375、376、378 至 380 表示当前身份无权更新目标或使用管理员专属字段；`maintain` 表示当前禁止写操作，`login_required` 表示认证无效。"
                  },
                  "msg": {
                    "type": "string",
                    "description": "与业务错误码对应的中文请求格式、目标记录、字段校验、规则步骤、引用关系、禁用限制、访问权限、维护状态或认证失败原因。"
                  },
                  "data": {
                    "type": "string",
                    "enum": [
                      ""
                    ],
                    "description": "业务错误时固定为空字符串。"
                  }
                },
                "additionalProperties": false
              }
            ]
          },
          "example": {
            "code": 0,
            "msg": "更新cc规则成功",
            "data": null
          }
        }
      }
    }
  },
  "x-python-handler": "site.CCRuleAPI",
  "x-python-route-line": 411,
  "x-audience": "user",
  "x-auth": "user",
  "x-reviewed": true,
  "parameters": [
    {
      "name": "rule_id",
      "in": "path",
      "required": true,
      "description": "要更新的 CC 规则组 ID；路由只接受十进制整数，并会覆盖请求体中可能存在的 `id`。",
      "schema": {
        "type": "integer",
        "format": "int64",
        "minimum": 1
      },
      "example": 10021
    }
  ],
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255,
              "description": "新的规则组名称；服务端会过滤可执行的 HTML 内容，处理后不得为空，并且在校验所属用户下不可与其他规则组重名。省略时保持原名称。"
            },
            "sort": {
              "oneOf": [
                {
                  "type": "integer",
                  "minimum": 0
                },
                {
                  "type": "string",
                  "pattern": "^[0-9]+$"
                }
              ],
              "description": "新的排序值，数值越小越靠前；接受非负整数或仅含十进制数字的字符串，省略时保持原值。"
            },
            "des": {
              "type": "string",
              "maxLength": 255,
              "description": "新的规则组备注；服务端会过滤可执行的 HTML 内容，可传空字符串清空备注，省略时保持原值。"
            },
            "data": {
              "type": "array",
              "description": "替换当前完整规则步骤的数组，可为空数组；元素数量不得超过运行时配置 `cc-rule-max-limit`，初始安装值为 5。若规则组已启用且正被网站使用，修改步骤会创建节点同步任务。",
              "items": {
                "type": "object",
                "required": [
                  "mode",
                  "action",
                  "matcher",
                  "filter1"
                ],
                "properties": {
                  "mode": {
                    "type": "string",
                    "enum": [
                      "break",
                      "continue"
                    ],
                    "description": "步骤命中后的流程模式：`break` 表示执行后结束该规则组，`continue` 表示继续评估后续步骤。"
                  },
                  "action": {
                    "type": "string",
                    "enum": [
                      "block",
                      "log"
                    ],
                    "description": "步骤动作：`block` 执行所选过滤器防护，`log` 记录命中行为。"
                  },
                  "matcher": {
                    "oneOf": [
                      {
                        "type": "integer",
                        "minimum": 1
                      },
                      {
                        "type": "string",
                        "pattern": "^[0-9]+$"
                      }
                    ],
                    "description": "用于判断该步骤是否命中的 CC 匹配器 ID；接受整数或数字字符串，目标匹配器必须存在且处于启用状态，服务端最终保存为字符串。"
                  },
                  "filter1": {
                    "oneOf": [
                      {
                        "type": "integer",
                        "minimum": 1
                      },
                      {
                        "type": "string",
                        "pattern": "^[0-9]+$"
                      }
                    ],
                    "description": "步骤使用的第一 CC 过滤器 ID；接受整数或数字字符串，目标过滤器必须存在且处于启用状态，服务端最终保存为字符串。"
                  },
                  "filter2": {
                    "oneOf": [
                      {
                        "type": "integer",
                        "minimum": 1
                      },
                      {
                        "type": "string",
                        "pattern": "^(?:[0-9]+)?$"
                      }
                    ],
                    "default": "",
                    "description": "可选的第二 CC 过滤器 ID；省略或空字符串表示不使用第二过滤器，非空时必须是已启用过滤器的整数或数字字符串。"
                  },
                  "state": {
                    "oneOf": [
                      {
                        "type": "boolean"
                      },
                      {
                        "type": "integer",
                        "enum": [
                          0,
                          1
                        ]
                      }
                    ],
                    "default": true,
                    "description": "该规则步骤是否启用；省略时为 true，也接受 0 或 1。"
                  },
                  "matcher_name": {
                    "type": "string",
                    "description": "匹配器名称快照，仅供界面展示；服务端不据此查找匹配器，会与步骤一起原样保存。"
                  },
                  "filter1_name": {
                    "type": "string",
                    "description": "第一过滤器名称快照，仅供界面展示；服务端不据此查找过滤器，会与步骤一起原样保存。"
                  },
                  "filter2_name": {
                    "type": "string",
                    "description": "第二过滤器名称快照，仅供界面展示；没有第二过滤器时通常为空字符串。"
                  }
                },
                "additionalProperties": true,
                "description": "单个 CC 规则步骤；附加字段不会被校验器移除，会随步骤一起序列化保存。"
              }
            },
            "show_to": {
              "oneOf": [
                {
                  "type": "integer",
                  "minimum": 1
                },
                {
                  "type": "string",
                  "pattern": "^(?:[0-9]+(?:,[0-9]+)*)?$"
                }
              ],
              "description": "新的定向可见用户 ID，多个 ID 使用英文逗号分隔；空字符串表示不指定定向用户。仅管理员可修改，每个 ID 都必须对应现有用户。"
            },
            "uid": {
              "type": "integer",
              "format": "int64",
              "minimum": 1,
              "description": "兼容性管理员字段，用作本次名称唯一性校验的用户上下文；仅管理员可传。该字段不会修改规则组数据库中的所属用户，不能用于转移规则组。"
            },
            "internal": {
              "oneOf": [
                {
                  "type": "boolean"
                },
                {
                  "type": "integer",
                  "enum": [
                    0,
                    1
                  ]
                }
              ],
              "description": "兼容性处理标记；1 或 true 要求管理员身份，并会按系统规则流程决定同步任务。该字段不会改写已有规则组的系统内置状态，不能用于转换规则组类型。"
            },
            "enable": {
              "oneOf": [
                {
                  "type": "boolean"
                },
                {
                  "type": "integer",
                  "enum": [
                    0,
                    1
                  ]
                }
              ],
              "description": "新的启用状态：true 或 1 表示启用，false 或 0 表示禁用。禁用前要求规则组未被网站或任何默认配置引用，且 ID 不得小于 10020；满足条件后会为非系统规则创建节点删除任务。"
            },
            "is_show": {
              "oneOf": [
                {
                  "type": "boolean"
                },
                {
                  "type": "integer",
                  "enum": [
                    0,
                    1
                  ]
                }
              ],
              "description": "新的前台显示状态：true 或 1 表示展示，false 或 0 表示隐藏；省略时保持原值。"
            }
          },
          "additionalProperties": true,
          "description": "指定规则组的部分更新对象，可为空对象；请求体中的 `id` 和未识别字段不会决定目标或写入规则组记录。"
        },
        "example": {
          "name": "验证码与频率组合防护",
          "sort": 90,
          "des": "先检查请求特征，再执行验证码过滤",
          "data": [
            {
              "mode": "continue",
              "action": "log",
              "matcher": "10021",
              "matcher_name": "匹配 API 请求",
              "filter1": "10021",
              "filter1_name": "请求频率限制",
              "filter2": "",
              "filter2_name": "",
              "state": true
            }
          ],
          "is_show": true
        }
      }
    }
  },
  "x-itecdn-source-reviewed": true,
  "extensions": [
    {
      "key": "x-python-handler",
      "value": "site.CCRuleAPI"
    },
    {
      "key": "x-python-route-line",
      "value": 411
    },
    {
      "key": "x-audience",
      "value": "user"
    },
    {
      "key": "x-auth",
      "value": "user"
    },
    {
      "key": "x-reviewed",
      "value": true
    },
    {
      "key": "x-itecdn-source-reviewed",
      "value": true
    }
  ],
  "method": "put",
  "path": "/v1/cc-rules/{rule_id}",
  "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",
    "sort": 0,
    "des": "string",
    "data": [
      {
        "mode": "break",
        "action": "block",
        "matcher": 0,
        "filter1": 0,
        "filter2": 0,
        "state": true,
        "matcher_name": "string",
        "filter1_name": "string",
        "filter2_name": "string"
      }
    ],
    "show_to": 0,
    "uid": 0,
    "internal": true,
    "enable": true,
    "is_show": true
  },
  "info": {
    "title": "itecdn v5 用户 API",
    "version": "5.x",
    "description": "itecdn v5.x Python 主控用户 API。本文档不适用于 v6 或其它实现。"
  },
  "postman": {
    "name": "更新指定 CC 规则组",
    "description": {
      "content": "按路径 ID 更新一条 CC 规则组。请求体必须是 JSON 对象，路径中的 `rule_id` 是唯一目标标识；即使请求体包含 `id`，服务端也会用路径 ID 覆盖。名称、排序、备注、规则步骤、定向可见用户、启用状态和前台显示状态均为可选字段，只更新明确提供的字段。普通用户只能更新归属于自己的自定义规则组，管理员可更新其他用户或系统内置规则组。传入空对象也会递增版本号并刷新更新时间。修改已启用且被网站使用的规则步骤会创建节点同步任务；禁用前必须确认规则组未被网站、全局默认值、用户默认值、防火墙默认页规则或自动规则切换引用，禁用成功时会创建节点删除任务。",
      "type": "text/plain"
    },
    "url": {
      "path": [
        "v1",
        "cc-rules",
        ":rule_id"
      ],
      "host": [
        "{{baseUrl}}"
      ],
      "query": [],
      "variable": [
        {
          "disabled": false,
          "description": {
            "content": "(Required) 要更新的 CC 规则组 ID；路由只接受十进制整数，并会覆盖请求体中可能存在的 `id`。",
            "type": "text/plain"
          },
          "type": "any",
          "value": "",
          "key": "rule_id"
        }
      ]
    },
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "method": "PUT",
    "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"
        }
      ]
    }
  }
}