Skip to content

feat(access-keys): 支持自定义密钥并统一编辑与生成交互 - #611

Merged
tbphp merged 6 commits into
mainfrom
tbphp/custom-access-keys
Sep 9, 2026
Merged

feat(access-keys): 支持自定义密钥并统一编辑与生成交互#611
tbphp merged 6 commits into
mainfrom
tbphp/custom-access-keys

Conversation

@tbphp

@tbphp tbphp commented Sep 9, 2026

Copy link
Copy Markdown
Owner

关联 Issue / Related Issue

无。

变更内容 / Change Content

  • Bug 修复 / Bug fix
  • 新功能 / New feature
  • 其他改动 / Other changes

访问密钥支持自定义值,新增和编辑共用输入框,末尾连接骰子图标按钮,悬停提示「随机生成」。新增留空由系统生成,编辑留空保持原值;随机生成使用安全随机数,只填入草稿,保存成功后才生效。界面移除独立轮换按钮和弹窗。弱密钥显示三档强度估算,允许确认后保存;编辑更换密钥时,将旧密钥失效和弱密钥警告合并为一次确认。

包含新密钥的编辑请求将密钥与其他配置在同一事务中保存,保留原 ID、权限、额度和已用金额,并通过现有幂等操作与快照恢复机制确保重试不会覆盖后来的修改。PUT /api/access-keys/:idkey 非空时要求 Idempotency-Key;省略或传入空字符串保持原密钥。现有轮换 API 保留。

后端仅校验可用字符、256 字符上限、唯一性和管理员密钥冲突,不设置强度门槛;凭据加密保存,幂等摘要使用 HMAC 指纹。掩码按长度分档:超过 16 位显示实际前 6 位及末 4 位,9–16 位仅显示末 4 位,8 位及以下完全隐藏。默认生成密钥保持原有的 sk-gl-****abcd 格式。

新增 0011_custom_access_keys 放宽尾号字符约束,0012_access_key_mask_prefix 保存脱敏前缀,使元数据读取无需解密。SQLite 重建表在迁移专用连接和写事务中执行,提交前校验外键并恢复连接设置,保留已有密钥、额度规则、用量检查点、索引和编号序列。

验证:最终 make check 通过;覆盖编辑空值保留、弱密钥保存、额度保留、原子回滚、相同掩码下的幂等区分、旧操作重试及提交后的快照恢复。迁移合同已使用 SQLite、真实 MySQL 8.0 和 PostgreSQL 16 验证新库、已有库、重复执行和中断恢复。按仓库规则未运行前端测试或本地 race 测试。

自查清单 / Checklist

  • 我已运行 make check,或在说明中写明无法运行的原因和未验证范围。 / I ran make check, or documented why it could not run and what remains unverified.
  • 本 PR 范围聚焦,未包含无关改动。 / This PR is focused and contains no unrelated changes.
  • 我已更新必要的公开文档或发布说明。 / I updated any required public documentation or release notes.
  • 我已确认提交、日志和测试数据不包含敏感信息。 / I confirmed that commits, logs, and fixtures contain no sensitive data.
  • 如适用,我已说明兼容性或数据迁移影响。 / Where applicable, I documented compatibility or data-migration impact.

本次未修改公开文档或发布说明。

Copilot AI lite review requested due to automatic review settings September 9, 2026 13:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-09T15:03:52.785758Z 7adbcce New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: QUIET

Plan: Advanced

Run ID: fd4c67bf-dd92-4d36-a9e7-c338dfa8169c

📥 Commits

Reviewing files that changed from the base of the PR and between 0e9cfef and 7adbcce.

📒 Files selected for processing (2)
  • internal/control/access_key_edit_credential_test.go
  • internal/control/access_key_update_idempotency.go

Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

本次变更支持自定义访问密钥,并新增前缀元数据和统一掩码。创建与更新操作加入幂等处理、管理员密钥冲突校验和恢复流程。数据库新增两项迁移,并增强 SQLite 迁移回滚处理。前端新增密钥输入、强度提示和替换确认流程,同时移除独立的密钥轮换界面。

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🟡 Moderate · up to 7adbc

Custom access-key updates and migrations are substantially covered, but SQLite upgrades may reuse deleted access-key IDs and the recovery interface may show conflicting states. These issues should be resolved or explicitly accepted before merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.23% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 65 functions across 44 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed PR 描述完整覆盖变更内容、验证范围、迁移影响和自查结果。未关联 Issue,且未更新公开文档的原因已明确说明。
Title check ✅ Passed 标题“feat(access-keys): 支持自定义密钥并统一编辑与生成交互”准确概括了访问密钥自定义值支持及交互统一这一主要变更,内容简洁明确。

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Note

Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.

🟡 Other comments (1)
web/src/features/access-keys/AccessKeyDrawer.vue-617-621 (1)

617-621: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

进入密钥对账时应清除 failed 标志。

retryable-preconditionoutcome.kindfailed,因此第 594 行已把 failed 置为 true。新分支随后设置 editReconciliation 并把 mutationState 置为 reconciling。结果 AccessKeyOperationFeedback 同时收到 failed=trueaccessKeys.customKey.editKeyReconciling,界面同时显示“保存失败”和“对账中”两种矛盾状态。

reconcileEdit 的同类分支没有这个组合:它先把 failed 置为 false,再设置对账状态。请在此处对齐该语义。

🐛 建议的修正
       const operation: PendingAccessKeyEditOperation = {
         base: currentBase,
         patch: updateBody,
         ...(updateBody.key ? { idempotencyKey: activeOperationID } : {}),
         state: outcome.kind === 'failed' ? 'reconciling' : outcome.kind,
       }
+      failed.value = false
       editReconciliation.value = operation
       editOperationRetained.value = true
       emit('update:editOperation', operation)

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: QUIET

Plan: Advanced

Run ID: cbbd7833-6caa-4b96-ae07-0006c9a86cf7

📥 Commits

Reviewing files that changed from the base of the PR and between d417b7d and 74ac0fd.

📒 Files selected for processing (55)
  • internal/control/access_key_collection.go
  • internal/control/access_key_collection_query_test.go
  • internal/control/access_key_custom_test.go
  • internal/control/access_key_edit_credential_test.go
  • internal/control/access_key_idempotency.go
  • internal/control/access_key_mask_test.go
  • internal/control/access_key_rotation.go
  • internal/control/access_key_update_idempotency.go
  • internal/control/access_keys.go
  • internal/control/access_keys_phase1_test.go
  • internal/control/bootstrap.go
  • internal/control/health.go
  • internal/control/home.go
  • internal/control/idempotency_digest.go
  • internal/control/idempotency_operation.go
  • internal/control/operation_recovery.go
  • internal/control/server.go
  • internal/platform/errors/errors.go
  • internal/platform/i18n/locales/en-US.go
  • internal/platform/i18n/locales/ja-JP.go
  • internal/platform/i18n/locales/zh-CN.go
  • internal/state/loader/loader.go
  • internal/state/snapshot.go
  • internal/storage/access_key_prefix_migration_test.go
  • internal/storage/custom_access_key_migration_test.go
  • internal/storage/database_integration_test.go
  • internal/storage/db_test.go
  • internal/storage/migration.go
  • internal/storage/migration_sqlite.go
  • internal/storage/migration_sqlite_test.go
  • internal/storage/migration_test.go
  • internal/storage/migrations/0007_access_key_lifecycle_test.go
  • internal/storage/migrations/0011_custom_access_keys.go
  • internal/storage/migrations/0012_access_key_mask_prefix.go
  • internal/storage/models/access_key.go
  • web/src/api/control/types.ts
  • web/src/app/mutation-outcome.ts
  • web/src/app/resources/access-keys.ts
  • web/src/app/resources/invalidation.ts
  • web/src/components/ui/AppConfirmDialog.vue
  • web/src/components/ui/AppDialog.vue
  • web/src/components/ui/AppTextInput.vue
  • web/src/features/access-keys/AccessKeyCredentialField.vue
  • web/src/features/access-keys/AccessKeyDrawer.vue
  • web/src/features/access-keys/AccessKeyFormFields.vue
  • web/src/features/access-keys/AccessKeyRotateDialog.vue
  • web/src/features/access-keys/AccessKeysView.vue
  • web/src/features/access-keys/access-key-create-operation.ts
  • web/src/features/access-keys/access-key-edit-operation.ts
  • web/src/features/access-keys/access-key-patch.ts
  • web/src/features/access-keys/access-key-rotate-operation.ts
  • web/src/features/access-keys/access-key-strength.ts
  • web/src/i18n/locales/en-US/access-keys.ts
  • web/src/i18n/locales/ja-JP/access-keys.ts
  • web/src/i18n/locales/zh-CN/access-keys.ts
💤 Files with no reviewable changes (4)
  • web/src/api/control/types.ts
  • web/src/app/resources/invalidation.ts
  • web/src/features/access-keys/AccessKeyRotateDialog.vue
  • web/src/features/access-keys/access-key-rotate-operation.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.

Comment thread internal/control/access_key_update_idempotency.go
Comment thread internal/storage/migrations/0011_custom_access_keys.go
Comment thread internal/storage/migrations/0011_custom_access_keys.go
@tbphp tbphp self-assigned this Sep 9, 2026
@tbphp tbphp added the enhancement New feature or request label Sep 9, 2026
@tbphp tbphp added this to the v2.0.0 milestone Sep 9, 2026
@tbphp

tbphp commented Sep 9, 2026

Copy link
Copy Markdown
Owner Author

已在 0e9cfef8 完成本轮修复:

  • 筛选条件的幂等摘要 复用现有归一化与排序逻辑;保留未传筛选和清空筛选的区别,并增加等价重试及冲突回归验证。
  • 恢复状态提示 在进入恢复流程时清除失败标志,避免同时显示失败和恢复中。

定向 Go 回归测试及 make check 均通过。

MySQLSQLite 两条迁移意见已在原讨论说明实测结果,保留现有实现。对于 Docstring Coverage 的比例建议,本次不为达到比例批量补注释,保持修复范围聚焦。

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0e9cfef8c0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/control/access_key_update_idempotency.go
@tbphp
tbphp merged commit de6d2d4 into main Sep 9, 2026
14 of 20 checks passed
@tbphp
tbphp deleted the tbphp/custom-access-keys branch September 9, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants