{
  "tags": [
    "API 密钥"
  ],
  "description": "更新当前登录用户的 API Key 配置；管理员可通过 `uid` 操作指定用户。请求体支持两种操作：通过 `ip` 设置最多 10 个 IPv4/IPv6 来源地址，传空字符串或 null 可清除白名单；通过 `reset` 重新生成 16 位 API Key 和 30 位 API Secret，旧凭证立即失效。目标用户必须已经开通 API Key。`ip` 与 `reset` 不应同时提交；若同时存在，服务端只执行 `ip` 分支而不会重置凭证。",
  "operationId": "user_put_v1_api_key",
  "security": [
    {
      "AccessToken": []
    },
    {
      "ApiKey": [],
      "ApiSecret": []
    }
  ],
  "responses": {
    "200": {
      "description": "业务结果通过 HTTP 200 返回。IP 白名单修改成功时返回空业务数据；凭证重置成功时返回新 API Key 和 API Secret；目标用户未开通、IP 数量或格式不合法、普通用户指定 `uid` 或认证无效时返回字符串业务错误码。",
      "content": {
        "application/json": {
          "schema": {
            "oneOf": [
              {
                "type": "object",
                "required": [
                  "code",
                  "msg",
                  "data"
                ],
                "properties": {
                  "code": {
                    "type": "integer",
                    "enum": [
                      0
                    ],
                    "description": "成功状态码，来源 IP 白名单修改成功时固定为 0。"
                  },
                  "msg": {
                    "type": "string",
                    "enum": [
                      "修改成功"
                    ],
                    "description": "来源 IP 白名单写入并提交后返回的确认消息。"
                  },
                  "data": {
                    "type": "string",
                    "nullable": true,
                    "enum": [
                      null
                    ],
                    "description": "来源 IP 白名单修改成功时没有额外业务数据，固定为 null。"
                  }
                },
                "additionalProperties": false
              },
              {
                "type": "object",
                "required": [
                  "code",
                  "msg",
                  "data"
                ],
                "properties": {
                  "code": {
                    "type": "integer",
                    "enum": [
                      0
                    ],
                    "description": "成功状态码，API Key 凭证重置成功时固定为 0。"
                  },
                  "msg": {
                    "type": "string",
                    "enum": [
                      "重置成功"
                    ],
                    "description": "新凭证写入并使旧凭证失效后返回的确认消息。"
                  },
                  "data": {
                    "type": "object",
                    "required": [
                      "api_key",
                      "api_secret"
                    ],
                    "properties": {
                      "api_key": {
                        "type": "string",
                        "minLength": 16,
                        "maxLength": 16,
                        "description": "重置后新生成的 16 位访问标识。"
                      },
                      "api_secret": {
                        "type": "string",
                        "minLength": 30,
                        "maxLength": 30,
                        "description": "与新 API Key 配对的 30 位明文密钥。"
                      }
                    },
                    "additionalProperties": false,
                    "description": "重置后立即生效的新 API Key 凭证对。"
                  }
                },
                "additionalProperties": false
              },
              {
                "type": "object",
                "required": [
                  "code",
                  "msg",
                  "data"
                ],
                "properties": {
                  "code": {
                    "type": "string",
                    "enum": [
                      "api-key-2",
                      "api-key-3",
                      "api-key-5",
                      "message-27",
                      "login_required"
                    ],
                    "description": "业务错误码：`api-key-2` 表示目标用户未开通 API Key，`api-key-3` 表示某个 IP 地址无效，`api-key-5` 表示白名单超过 10 个地址，`message-27` 表示普通用户尝试操作指定用户，`login_required` 表示认证无效。"
                  },
                  "msg": {
                    "type": "string",
                    "description": "与业务错误码对应的中文配置、IP、权限或认证失败原因。"
                  },
                  "data": {
                    "type": "string",
                    "enum": [
                      ""
                    ],
                    "description": "业务错误时固定为空字符串。"
                  }
                },
                "additionalProperties": false
              }
            ]
          },
          "example": {
            "code": 0,
            "msg": "重置成功",
            "data": {
              "api_key": "EXAMPLEAPIKEY001",
              "api_secret": "EXAMPLE_API_SECRET_00000000000"
            }
          }
        }
      }
    }
  },
  "x-python-handler": "system.ApiKeyAPI",
  "x-python-route-line": 907,
  "x-audience": "user",
  "x-auth": "user",
  "x-reviewed": true,
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "oneOf": [
            {
              "type": "object",
              "required": [
                "ip"
              ],
              "properties": {
                "ip": {
                  "type": "string",
                  "nullable": true,
                  "description": "允许使用该 API Key 的来源 IP 白名单，最多 10 个 IPv4 或 IPv6 地址，多个地址以竖线 `|` 分隔；空字符串或 null 表示清除限制。"
                },
                "uid": {
                  "type": "integer",
                  "format": "int64",
                  "minimum": 1,
                  "description": "要修改 API Key 的用户 ID；省略时为当前登录用户，仅管理员可指定其他用户。"
                }
              },
              "additionalProperties": false,
              "description": "设置或清空 API Key 来源 IP 白名单。"
            },
            {
              "type": "object",
              "required": [
                "reset"
              ],
              "properties": {
                "reset": {
                  "type": "boolean",
                  "enum": [
                    true
                  ],
                  "description": "传 true 重新生成 API Key 和 API Secret；服务端以字段是否存在触发重置。"
                },
                "uid": {
                  "type": "integer",
                  "format": "int64",
                  "minimum": 1,
                  "description": "要重置 API Key 的用户 ID；省略时为当前登录用户，仅管理员可指定其他用户。"
                }
              },
              "additionalProperties": false,
              "description": "重置 API Key 凭证对。"
            }
          ]
        },
        "example": {
          "ip": "192.0.2.10|2001:db8::10"
        }
      }
    }
  },
  "parameters": [],
  "x-itecdn-source-reviewed": true,
  "extensions": [
    {
      "key": "x-python-handler",
      "value": "system.ApiKeyAPI"
    },
    {
      "key": "x-python-route-line",
      "value": 907
    },
    {
      "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/api-key",
  "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": {
    "ip": "string",
    "uid": 0
  },
  "info": {
    "title": "itecdn v5 用户 API",
    "version": "5.x",
    "description": "itecdn v5.x Python 主控用户 API。本文档不适用于 v6 或其它实现。"
  },
  "postman": {
    "name": "更新或重置 API Key",
    "description": {
      "content": "更新当前登录用户的 API Key 配置；管理员可通过 `uid` 操作指定用户。请求体支持两种操作：通过 `ip` 设置最多 10 个 IPv4/IPv6 来源地址，传空字符串或 null 可清除白名单；通过 `reset` 重新生成 16 位 API Key 和 30 位 API Secret，旧凭证立即失效。目标用户必须已经开通 API Key。`ip` 与 `reset` 不应同时提交；若同时存在，服务端只执行 `ip` 分支而不会重置凭证。",
      "type": "text/plain"
    },
    "url": {
      "path": [
        "v1",
        "api-key"
      ],
      "host": [
        "{{baseUrl}}"
      ],
      "query": [],
      "variable": []
    },
    "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"
        }
      ]
    }
  }
}