refactor(api-keys): remove API key reset endpoint and update documentation

Eliminate the POST /tenants/{id}/api-key endpoint for resetting tenant API keys, transitioning to a more granular API key management approach. Update related documentation and API specifications to reflect the new structure, including changes to the tenant API key management paths. Adjust frontend code and internationalization files to remove references to the deprecated API key reset functionality, enhancing clarity and consistency across the application.
This commit is contained in:
wizardchen
2026-07-06 18:27:18 +08:00
committed by lyingbug
parent 1d1e1e3d25
commit 97c36f634a
25 changed files with 265 additions and 494 deletions
+2 -32
View File
@@ -3,7 +3,7 @@
[返回目录](./README.md)
包含两组接口:
- 租户 CRUD(`/tenants`、`/tenants/:id`、`/tenants/:id/api-key`):当前认证用户对自己所属租户进行管理;跨租户访问需要管理员权限。
- 租户 CRUD(`/tenants`、`/tenants/:id`):当前认证用户对自己所属租户进行管理;跨租户访问需要管理员权限。
- 跨租户接口(`/tenants/all`、`/tenants/search`):**需要服务端启用 `EnableCrossTenantAccess` 且当前用户具备 `CanAccessAllTenants` 权限**,否则返回 403。
- 租户 KV 配置(`/tenants/kv/:key`):当前租户级别的通用配置项,**`tenant_id` 从认证上下文中获取,不在 URL 中传入**。
@@ -15,7 +15,6 @@
| GET | `/tenants/:id` | 获取指定租户信息 |
| PUT | `/tenants/:id` | 更新租户信息 |
| DELETE | `/tenants/:id` | 删除租户 |
| POST | `/tenants/:id/api-key` | 重置租户 API Key(吊销该租户全部旧 Key 后创建一把新的全权限 Key) |
| GET | `/tenants/:id/api-keys` | 列出租户 API Key(Owner) |
| POST | `/tenants/:id/api-keys` | 创建带角色的 API Key(Owner) |
| DELETE | `/tenants/:id/api-keys/:key_id` | 吊销指定 API Key(Owner) |
@@ -111,7 +110,7 @@ curl --location 'http://localhost:8080/api/v1/tenants/search?keyword=weknora&pag
## POST `/tenants` - 创建新租户
创建一个新的租户。**不会**自动发放 API Key;请在创建后通过 `POST /tenants/:id/api-keys` 或 `POST /tenants/:id/api-key` 获取密钥。从旧版本升级时,原有 `tenants.api_key` 会迁移到 `tenant_api_keys` 表并继续可用,直至被吊销。
创建一个新的租户。**不会**自动发放 API Key;请在创建后通过 `POST /tenants/:id/api-keys` 创建密钥。从旧版本升级时,原有 `tenants.api_key` 会迁移到 `tenant_api_keys` 表并继续可用,直至被吊销。
**参数说明(请求体)**:
@@ -330,35 +329,6 @@ curl --location --request DELETE 'http://localhost:8080/api/v1/tenants/10000' \
}
```
## POST `/tenants/:id/api-key` - 重置租户 API Key
为指定租户生成新的 API Key,并**吊销该租户下所有现有 Key**(含迁移进来的旧 Key)。新 Key 拥有 `read` + `write` + `admin` 全权限。访问规则同 `GET /tenants/:id`。
**路径参数**:
| 字段 | 类型 | 说明 |
| ---- | ---- | ------- |
| id | int | 租户 ID |
**请求**:
```curl
curl --location --request POST 'http://localhost:8080/api/v1/tenants/10000/api-key' \
--header 'X-API-Key: sk-aaLRAgvCRJcmtiL2vLMeB1FB5UV0Q-qB7DlTE1pJ9KA93XZG' \
--header 'Content-Type: application/json'
```
**响应**:
```json
{
"data": {
"api_key": "sk-IKtd9JGV4-aPGQ6RiL8YJu9Vzb3-ae4lgFkjFJZmhvUn2mLu"
},
"success": true
}
```
## 租户 API Key 管理(`tenant_api_keys`)
自 scoped API Key 改造后,密钥以独立记录存储,支持:
+75 -55
View File
@@ -11957,56 +11957,6 @@ const docTemplate = `{
}
}
},
"/tenants/{id}/api-key": {
"post": {
"security": [
{
"Bearer": []
}
],
"description": "为指定租户生成一个新的 API Key,旧 Key 立即失效",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"租户管理"
],
"summary": "重置租户 API Key",
"parameters": [
{
"type": "integer",
"description": "租户ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "新生成的 API Key",
"schema": {
"type": "object",
"additionalProperties": true
}
},
"400": {
"description": "请求参数错误",
"schema": {
"$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError"
}
},
"403": {
"description": "权限不足",
"schema": {
"$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError"
}
}
}
}
},
"/tenants/{id}/api-principal-config": {
"get": {
"security": [
@@ -12114,6 +12064,65 @@ const docTemplate = `{
}
}
},
"/tenants/{id}/api-principal-test-token": {
"post": {
"security": [
{
"Bearer": []
}
],
"description": "使用租户已保存的 HMAC 密钥签发短期外部用户 JWT(Owner)",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"租户管理"
],
"summary": "生成 API Playground 测试 JWT",
"parameters": [
{
"type": "integer",
"description": "租户ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "测试 Token 参数",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/internal_handler.apiPrincipalTestTokenRequest"
}
}
],
"responses": {
"200": {
"description": "短期 JWT",
"schema": {
"type": "object",
"additionalProperties": true
}
},
"400": {
"description": "请求参数错误",
"schema": {
"$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError"
}
},
"403": {
"description": "权限不足",
"schema": {
"$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError"
}
}
}
}
},
"/tenants/{id}/audit-log": {
"get": {
"security": [
@@ -14327,6 +14336,10 @@ const docTemplate = `{
"description": "===== Agent Mode Settings =====\nMaximum iterations for ReAct loop (only for agent type)",
"type": "integer"
},
"mcp_auth_wait_timeout": {
"description": "MCPAuthWaitTimeout is how many seconds to wait for in-conversation OAuth\nauthorization before skipping. \u003c=0 uses the gate's configured timeout.",
"type": "integer"
},
"mcp_selection_mode": {
"description": "MCP service selection mode: \"all\" = all enabled MCP services, \"selected\" = specific services, \"none\" = no MCP",
"type": "string"
@@ -17147,7 +17160,7 @@ const docTemplate = `{
"type": "string"
},
"user_id": {
"description": "UserID is the owner of the session. Empty for legacy rows (visible at\ntenant level) and for IM-created sessions that do not map to a WeKnora user.",
"description": "UserID is the owner scope for this session. WeKnora user UUIDs, API\nexternal-user principals, and embed visitor principals all use this column.",
"type": "string"
}
}
@@ -17486,10 +17499,6 @@ const docTemplate = `{
"github_com_Tencent_WeKnora_internal_types.Tenant": {
"type": "object",
"properties": {
"api_key": {
"description": "API key",
"type": "string"
},
"business": {
"description": "Business",
"type": "string"
@@ -19917,6 +19926,17 @@ const docTemplate = `{
}
}
},
"internal_handler.apiPrincipalTestTokenRequest": {
"type": "object",
"properties": {
"expires_in_seconds": {
"type": "integer"
},
"external_user_id": {
"type": "string"
}
}
},
"internal_handler.auditLogListResponse": {
"type": "object",
"properties": {
+75 -55
View File
@@ -11950,56 +11950,6 @@
}
}
},
"/tenants/{id}/api-key": {
"post": {
"security": [
{
"Bearer": []
}
],
"description": "为指定租户生成一个新的 API Key,旧 Key 立即失效",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"租户管理"
],
"summary": "重置租户 API Key",
"parameters": [
{
"type": "integer",
"description": "租户ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "新生成的 API Key",
"schema": {
"type": "object",
"additionalProperties": true
}
},
"400": {
"description": "请求参数错误",
"schema": {
"$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError"
}
},
"403": {
"description": "权限不足",
"schema": {
"$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError"
}
}
}
}
},
"/tenants/{id}/api-principal-config": {
"get": {
"security": [
@@ -12107,6 +12057,65 @@
}
}
},
"/tenants/{id}/api-principal-test-token": {
"post": {
"security": [
{
"Bearer": []
}
],
"description": "使用租户已保存的 HMAC 密钥签发短期外部用户 JWT(Owner)",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"租户管理"
],
"summary": "生成 API Playground 测试 JWT",
"parameters": [
{
"type": "integer",
"description": "租户ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "测试 Token 参数",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/internal_handler.apiPrincipalTestTokenRequest"
}
}
],
"responses": {
"200": {
"description": "短期 JWT",
"schema": {
"type": "object",
"additionalProperties": true
}
},
"400": {
"description": "请求参数错误",
"schema": {
"$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError"
}
},
"403": {
"description": "权限不足",
"schema": {
"$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError"
}
}
}
}
},
"/tenants/{id}/audit-log": {
"get": {
"security": [
@@ -14320,6 +14329,10 @@
"description": "===== Agent Mode Settings =====\nMaximum iterations for ReAct loop (only for agent type)",
"type": "integer"
},
"mcp_auth_wait_timeout": {
"description": "MCPAuthWaitTimeout is how many seconds to wait for in-conversation OAuth\nauthorization before skipping. \u003c=0 uses the gate's configured timeout.",
"type": "integer"
},
"mcp_selection_mode": {
"description": "MCP service selection mode: \"all\" = all enabled MCP services, \"selected\" = specific services, \"none\" = no MCP",
"type": "string"
@@ -17140,7 +17153,7 @@
"type": "string"
},
"user_id": {
"description": "UserID is the owner of the session. Empty for legacy rows (visible at\ntenant level) and for IM-created sessions that do not map to a WeKnora user.",
"description": "UserID is the owner scope for this session. WeKnora user UUIDs, API\nexternal-user principals, and embed visitor principals all use this column.",
"type": "string"
}
}
@@ -17479,10 +17492,6 @@
"github_com_Tencent_WeKnora_internal_types.Tenant": {
"type": "object",
"properties": {
"api_key": {
"description": "API key",
"type": "string"
},
"business": {
"description": "Business",
"type": "string"
@@ -19910,6 +19919,17 @@
}
}
},
"internal_handler.apiPrincipalTestTokenRequest": {
"type": "object",
"properties": {
"expires_in_seconds": {
"type": "integer"
},
"external_user_id": {
"type": "string"
}
}
},
"internal_handler.auditLogListResponse": {
"type": "object",
"properties": {
+52 -37
View File
@@ -660,6 +660,11 @@ definitions:
===== Agent Mode Settings =====
Maximum iterations for ReAct loop (only for agent type)
type: integer
mcp_auth_wait_timeout:
description: |-
MCPAuthWaitTimeout is how many seconds to wait for in-conversation OAuth
authorization before skipping. <=0 uses the gate's configured timeout.
type: integer
mcp_selection_mode:
description: 'MCP service selection mode: "all" = all enabled MCP services,
"selected" = specific services, "none" = no MCP'
@@ -2787,8 +2792,8 @@ definitions:
type: string
user_id:
description: |-
UserID is the owner of the session. Empty for legacy rows (visible at
tenant level) and for IM-created sessions that do not map to a WeKnora user.
UserID is the owner scope for this session. WeKnora user UUIDs, API
external-user principals, and embed visitor principals all use this column.
type: string
type: object
github_com_Tencent_WeKnora_internal_types.SessionLastRequestState:
@@ -3044,9 +3049,6 @@ definitions:
type: object
github_com_Tencent_WeKnora_internal_types.Tenant:
properties:
api_key:
description: API key
type: string
business:
description: Business
type: string
@@ -4806,6 +4808,13 @@ definitions:
signed_token_header_name:
type: string
type: object
internal_handler.apiPrincipalTestTokenRequest:
properties:
expires_in_seconds:
type: integer
external_user_id:
type: string
type: object
internal_handler.auditLogListResponse:
properties:
data:
@@ -12585,38 +12594,6 @@ paths:
summary: 更新租户
tags:
- 租户管理
/tenants/{id}/api-key:
post:
consumes:
- application/json
description: 为指定租户生成一个新的 API Key,旧 Key 立即失效
parameters:
- description: 租户ID
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: 新生成的 API Key
schema:
additionalProperties: true
type: object
"400":
description: 请求参数错误
schema:
$ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError'
"403":
description: 权限不足
schema:
$ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError'
security:
- Bearer: []
summary: 重置租户 API Key
tags:
- 租户管理
/tenants/{id}/api-principal-config:
get:
consumes:
@@ -12686,6 +12663,44 @@ paths:
summary: 更新租户 API Key 用户身份配置
tags:
- 租户管理
/tenants/{id}/api-principal-test-token:
post:
consumes:
- application/json
description: 使用租户已保存的 HMAC 密钥签发短期外部用户 JWT(Owner)
parameters:
- description: 租户ID
in: path
name: id
required: true
type: integer
- description: 测试 Token 参数
in: body
name: request
required: true
schema:
$ref: '#/definitions/internal_handler.apiPrincipalTestTokenRequest'
produces:
- application/json
responses:
"200":
description: 短期 JWT
schema:
additionalProperties: true
type: object
"400":
description: 请求参数错误
schema:
$ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError'
"403":
description: 权限不足
schema:
$ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError'
security:
- Bearer: []
summary: 生成 API Playground 测试 JWT
tags:
- 租户管理
/tenants/{id}/audit-log:
get:
description: 返回该租户最近的审计事件,按 id 倒序。游标分页:将上次响应的 next_cursor 作为下一次请求的 after_id。