refactor: 移除 API Key 最小长度限制并放宽最大长度至 10000 字符

This commit is contained in:
fawney19
2026-02-09 17:00:48 +08:00
parent c5d1d2c21e
commit 65658e58d5
4 changed files with 5 additions and 48 deletions

View File

@@ -349,7 +349,7 @@ class CreateAPIKeyRequest(BaseModel):
"""创建 API Key 请求"""
endpoint_id: str = Field(..., description="Endpoint ID")
api_key: str = Field(..., min_length=1, max_length=500, description="API Key")
api_key: str = Field(..., min_length=1, max_length=10000, description="API Key")
priority: int | None = Field(100, ge=0, le=1000, description="优先级")
is_active: bool | None = Field(True, description="是否启用")
rpm_limit: int | None = Field(None, ge=0, description="RPM 限制NULL=自适应)")
@@ -362,10 +362,6 @@ class CreateAPIKeyRequest(BaseModel):
# 移除首尾空白
v = v.strip()
# 检查最小长度
if len(v) < 3:
raise ValueError("API Key 长度不能少于 3 个字符")
# 检查危险字符(不应包含 SQL 注入字符)
dangerous_chars = ["'", '"', ";", "--", "/*", "*/", "<", ">"]
for char in dangerous_chars:

View File

@@ -322,7 +322,7 @@ class EndpointAPIKeyCreate(BaseModel):
)
api_key: str = Field(
default="", max_length=500, description="API Key标准认证时必填将自动加密"
default="", max_length=10000, description="API Key标准认证时必填将自动加密"
)
auth_type: Literal["api_key", "vertex_ai", "oauth"] = Field(
default="api_key",
@@ -484,8 +484,7 @@ class EndpointAPIKeyUpdate(BaseModel):
api_key: str | None = Field(
default=None,
min_length=3,
max_length=500,
max_length=10000,
description="API Key标准认证时使用将自动加密",
)
auth_type: Literal["api_key", "vertex_ai", "oauth"] | None = Field(
@@ -576,8 +575,6 @@ class EndpointAPIKeyUpdate(BaseModel):
return v
v = v.strip()
if len(v) < 3:
raise ValueError("API Key 长度不能少于 3 个字符")
dangerous_chars = ["'", '"', ";", "--", "/*", "*/", "<", ">"]
for char in dangerous_chars: