更新 API 密钥
OpenAPI 契约
- 方法
- PUT
- 路径
/api/v1/api-keys/{id}- 认证
- jwtBearer (bearer)
- 响应状态
- 200 400 401 403 404 409 429 500
请求与响应 Schema
JSON
{
"requestBody": {
"application/json": {
"$ref": "#/components/schemas/UpdateApiKeyRequest"
}
},
"responses": {
"200": {
"description": "API key updated",
"content": {
"application/json": {
"$ref": "#/components/schemas/ApiKeyResponse"
}
}
},
"400": {
"description": "Invalid request",
"content": {
"application/json": {
"$ref": "#/components/schemas/RequestError"
}
}
},
"401": {
"description": "Authentication required or invalid",
"content": {
"application/json": {
"$ref": "#/components/schemas/SecurityError"
}
}
},
"403": {
"description": "Authenticated but not permitted",
"content": {
"application/json": {
"$ref": "#/components/schemas/SecurityError"
}
}
},
"404": {
"description": "Requested API key was not found",
"content": {
"application/json": {
"$ref": "#/components/schemas/ApiError"
}
}
},
"409": {
"description": "API key is revoked or the active API-key limit would be exceeded",
"content": {
"application/json": {
"$ref": "#/components/schemas/ApiError"
}
}
},
"429": {
"description": "Rate limit exceeded",
"content": {
"application/json": {
"$ref": "#/components/schemas/SecurityError"
}
}
},
"500": {
"description": "Unexpected server error",
"content": {
"application/json": {
"$ref": "#/components/schemas/ApiError"
}
}
}
}
}PUT /api/v1/api-keys/{id} 仅接受 JWT;它会替换全部可编辑设置,但不会轮换或泄露密钥 secret。请发送 name、非空 scopes 集合和 enabled。还可发送未来的 expiresAt、usageLimitNcu 以及最多 50 个 allowedCidrs。expiry 或 usage limit 为 null 时会清除相应限制;空 CIDR 集合允许任意客户端 IP。
已 revoke 的密钥不能编辑。重新启用密钥受 active-key 上限约束;已过期密钥还需要清除 expiry 或将其移到未来。usageLimitNcu 不能低于当前周期中已消耗或已预留的 NCU。账户之外的密钥按未找到处理。
响应包含更新后的 metadata,绝不包含 secret,并使用 Cache-Control: no-store。
json
{"name":"Production deploys","scopes":["build:read","build:write","artifact:read"],"expiresAt":null,"usageLimitNcu":50000,"allowedCidrs":["203.0.113.0/24"],"enabled":true}