Skip to content

docs(patrol): 2026-06-14 文档维护 — admin-api.md 同步 1:1 约束#744

Merged
hotplex-ai merged 2 commits into
hrygo:mainfrom
aaronwong1989:docs/patrol-2026-06-14
Jun 13, 2026
Merged

docs(patrol): 2026-06-14 文档维护 — admin-api.md 同步 1:1 约束#744
hotplex-ai merged 2 commits into
hrygo:mainfrom
aaronwong1989:docs/patrol-2026-06-14

Conversation

@aaronwong1989

Copy link
Copy Markdown
Collaborator

Summary

变更驱动巡逻:自 fb857af1(PR #730)以来 4 个提交,映射到文档影响分析。

修复 docs/reference/admin-api.md,同步 PR #741 fix(security): enforce 1:1 user_id to API key mapping 引入的行为变更:

  • 节首补充 user_id ↔ API Key 1:1 映射约束 + 409 Conflict 说明
  • POST /admin/api-keys 补充 409 Conflict 响应(user_id 已存在)
  • PATCH /admin/api-keys/{id} 补充 409 Conflict 响应(user_id 冲突)
  • 顺带修正数据库后缀:SQLite → SQLite 或 PostgreSQL(migration 016 双方言)

影响判定(变更窗口其他提交)

提交 类型 文档动作
5f84b7b5 release v1.29.0 版本号 无需
5c1ebc00 docs(patrol) #740 文档自身 已处理
10763824 config 拆分 + DRY #742 纯内部重构(零逻辑/配置项变更) 无需
8dd4faa8 security 1:1 #741 行为变更 ✅ 本次修复

security-model.md / security-hardening.md 描述的是 resolver 机制(未声明映射基数),对 1:1 约束仍准确,不需修改。

Closes #743

🤖 Generated with Claude Code

PR hrygo#741 (fix(security): enforce 1:1 user_id to API key mapping) 引入了
user_id 与 API Key 的 1:1 强制约束,admin-api.md 未同步此行为变更:
- POST/PATCH 在 user_id 冲突时返回 409 Conflict
- 新增 UNIQUE INDEX (migration 016, SQLite + PG)

修正 admin-api.md 三处:
- 节首补充 1:1 映射约束说明 + 409 Conflict
- POST 补充 409 Conflict 响应
- PATCH 补充 409 Conflict 响应
- 顺带修正数据库后缀(SQLite → SQLite 或 PostgreSQL)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
hotplex-ai
hotplex-ai previously approved these changes Jun 13, 2026

@hotplex-ai hotplex-ai left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review — hotplex-ai

Verdict: APPROVE | P0:0 P1:0 P2:0 P3:2

本次 PR 核心改动(user_id ↔ API Key 1:1 映射约束 + 409 Conflict + DB 双后端)经双 agent 逐项核验,与代码实现精确一致

  • 1:1 约束 + 409requireUniqueUserID + ErrUserIDExistshttp.StatusConflict,POST/PATCH 均触发 (apikey_handlers.go:425)
  • POST 201 / 无 DB resolver 时 501 — handler 状态码精确匹配 (apikey_handlers.go:293,323,343,383,443)
  • user_id ≤128 / description ≤512 — 长度校验数值一致 (apikey_handlers.go:301,305,396,400)
  • 脱敏「前 8 + 后 4 位」maskAPIKey 实现匹配 (apikey_handlers.go:25-30)
  • DELETE 清除 resolver 缓存inv.Invalidate() 调用确认 (apikey_handlers.go:464)
  • DB「SQLite 或 PostgreSQL」 — 双 backend 实现确认(apiKeyUserStore + pgStore,按 cfg.DB.Driver 分发)
  • 端点表routes.go:172-176 注册的 5 个路由(方法/路径/Scope)与文档逐一匹配,无遗漏端点
  • 1:1 方向措辞 — 代码用 getByUserIDuser_id 查重,文档「一个 user_id 仅能关联一个 API Key」方向正确无歧义

2 条 pre-existing 友情提示(均非本次 diff 引入,不影响合并,可后续清理):

  • [P3] API Key 生成长度:文档称「32 字节随机 hex」,代码实际 make([]byte, 24) = 24 字节(hpk_ 前缀 + 48 hex 字符,总长 52)。见 apikey_handlers.go:58-62。建议顺带修正为「24 字节随机」。
  • [P3] PATCH/DELETE 行反引号不闭合(**PATCH /admin/api-keys/{id}``** 缺闭背引号)。已核对 HEAD~1 确认 pre-existing,非本 PR 引入。

文档与代码一致性审查通过,LGTM 🚀

- POST 描述 32 字节 → 24 字节,与代码 make([]byte, 24) 一致
- PATCH/DELETE 端点标题闭合反引号,对齐 L189 纯粗体格式

Address PR hrygo#744 review P3 findings (pre-existing, same file).

Co-Authored-By: Claude <noreply@anthropic.com>
@hotplex-ai hotplex-ai merged commit 8aba8e8 into hrygo:main Jun 13, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs(patrol): 2026-06-14 文档维护 — admin-api.md 同步 user_id↔API Key 1:1 约束

2 participants