feat(api-key): 增加 API Key 创建数量与频率限制

- 新增 api_key_create.max_active_per_user(默认 200)与
  api_key_create.max_per_user_per_hour(默认 20),0 表示不限制
- 创建频率按固定一小时窗口统计,自定义与自动生成的 Key 统一计入
- 创建计数独立于 Key 生命周期,删除或修改 Key 不再重置计数
- 移除不再使用的 DeleteCreateAttemptCount 缓存方法
This commit is contained in:
shaw
2026-09-30 13:44:02 +08:00
parent a0f41f95a0
commit 9ecb340822
12 changed files with 302 additions and 48 deletions
+2 -2
View File
@@ -1737,8 +1737,8 @@ func (stubApiKeyCache) IncrementCreateAttemptCount(ctx context.Context, userID i
return nil
}
func (stubApiKeyCache) DeleteCreateAttemptCount(ctx context.Context, userID int64) error {
return nil
func (stubApiKeyCache) IncrementCreateCount(ctx context.Context, userID int64, window time.Duration) (int64, error) {
return 0, nil
}
func (stubApiKeyCache) IncrementDailyUsage(ctx context.Context, apiKey string) error {