feat(api): expose priority and note in GET /auth-files response#2124
feat(api): expose priority and note in GET /auth-files response#2124RGBadmin wants to merge 1 commit intorouter-for-me:mainfrom
Conversation
…sponse The list endpoint previously omitted priority and note, which are stored inside each auth file's JSON content. This adds them to both the normal (auth-manager) and fallback (disk-read) code paths, and extends PATCH /auth-files/fields to support writing the note field. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the GET /auth-files API endpoint by exposing previously hidden priority and note fields. This change empowers the frontend to display more comprehensive information on credential cards, including priority badges and user-defined notes, and enables sorting based on priority. Furthermore, the PATCH /auth-files/fields endpoint has been updated to provide full control over the note field, allowing users to set or clear it as needed. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request successfully exposes the priority and note fields in the /auth-files API response and adds support for updating the note field. The implementation is mostly correct, but I've identified a few areas for improvement. Specifically, there's a correctness issue regarding how the note field is read, leading to inconsistent behavior. I've also pointed out a couple of opportunities to refactor the code for better maintainability and efficiency by reducing duplication and redundant operations. Addressing these points will make the new functionality more robust and the code easier to maintain.
| // Expose note from Metadata. | ||
| if note, ok := auth.Metadata["note"].(string); ok { | ||
| if trimmed := strings.TrimSpace(note); trimmed != "" { | ||
| entry["note"] = trimmed | ||
| } | ||
| } |
There was a problem hiding this comment.
There's an inconsistency in how the note field is accessed compared to the priority field. The synthesizer stores both priority and note in auth.Attributes, but here note is being read from auth.Metadata. While this might work in some cases because Metadata is also populated from the file, it's better to have a single, consistent source for these synthesized values.
For consistency and correctness, note should be read from auth.Attributes, just like priority. This also has the benefit of removing a redundant strings.TrimSpace call, as the synthesizer already handles trimming.
// Expose note from Attributes (set by synthesizer from JSON "note" field).
if note := authAttribute(auth, "note"); note != "" {
entry["note"] = note
}| if nv := gjson.GetBytes(data, "note"); nv.Exists() && strings.TrimSpace(nv.String()) != "" { | ||
| fileData["note"] = strings.TrimSpace(nv.String()) | ||
| } |
There was a problem hiding this comment.
The expression strings.TrimSpace(nv.String()) is evaluated twice here, once in the condition and again in the assignment. This is slightly inefficient. You can improve this by storing the trimmed string in a variable and using it in both places. This will also make the code a bit more readable.
if nv := gjson.GetBytes(data, "note"); nv.Exists() {
if trimmed := strings.TrimSpace(nv.String()); trimmed != "" {
fileData["note"] = trimmed
}
}| if req.Note != nil { | ||
| if targetAuth.Metadata == nil { | ||
| targetAuth.Metadata = make(map[string]any) | ||
| } | ||
| trimmedNote := strings.TrimSpace(*req.Note) | ||
| if trimmedNote == "" { | ||
| delete(targetAuth.Metadata, "note") | ||
| } else { | ||
| targetAuth.Metadata["note"] = trimmedNote | ||
| } | ||
| changed = true | ||
| } |
There was a problem hiding this comment.
This block for handling req.Note is very similar to the block for req.Priority just above it. This introduces code duplication, specifically the check if targetAuth.Metadata == nil.
Consider refactoring to reduce this duplication and improve maintainability. You could combine the logic by first checking if either field needs to be updated, then initializing the metadata map if needed, and then handling each field.
For example:
if req.Priority != nil || req.Note != nil {
if targetAuth.Metadata == nil {
targetAuth.Metadata = make(map[string]any)
}
if req.Priority != nil {
if *req.Priority == 0 {
delete(targetAuth.Metadata, "priority")
} else {
targetAuth.Metadata["priority"] = *req.Priority
}
}
if req.Note != nil {
trimmedNote := strings.TrimSpace(*req.Note)
if trimmedNote == "" {
delete(targetAuth.Metadata, "note")
} else {
targetAuth.Metadata["note"] = trimmedNote
}
}
changed = true
}There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5b6342e6ac
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if pv := gjson.GetBytes(data, "priority"); pv.Exists() { | ||
| fileData["priority"] = int(pv.Int()) | ||
| } |
There was a problem hiding this comment.
Ignore invalid disk priority values instead of coercing to 0
When the auth manager is unavailable, the fallback path now emits priority for any file that merely has a priority key, but gjson.Int() coerces non-numeric values (for example "priority":"high" or "priority":null) to 0. This makes the API report a concrete priority that was never configured and can change sort/order behavior in degraded mode, while the normal in-memory path only includes priority when integer parsing succeeds.
Useful? React with 👍 / 👎.
概述 / Summary
GET /auth-files列表接口此前不返回凭证文件中的priority和note字段,导致前端无法在卡片上展示优先级和备注,也无法按优先级排序。本 PR 将这两个字段暴露到列表响应中,并扩展PATCH /auth-files/fields以支持写入note。The
GET /auth-fileslist endpoint previously omitted thepriorityandnotefields stored inside each auth file's JSON content. This meant the frontend could not display priority badges or notes on credential cards, nor sort by priority. This PR exposes both fields in the list response and extendsPATCH /auth-files/fieldsto support writing thenotefield.改动详情 / Changes
1.
buildAuthFileEntry()— 正常路径 / Normal pathauth.Attributes["priority"](合成阶段已写入)读取 priority,转为 int 返回auth.Metadata["note"]读取 note(string),非空时返回priorityfromauth.Attributes["priority"](already set by synthesizer), converts to intnotefromauth.Metadata["note"](string), includes when non-empty2.
listAuthFilesFromDisk()— 回退路径 / Fallback pathpriority和note字段priorityandnotefrom on-disk JSON files3.
synthesizeFileAuths()— 合成阶段 / Synthesismetadata["note"]读取 note 并存入auth.Attributes["note"]notefrommetadata["note"]intoauth.Attributes["note"]4.
PatchAuthFileFields()— 字段写入 / Field updateNote *string字段Note *stringto the request struct改动文件 / Changed files
internal/api/handlers/management/auth_files.gointernal/watcher/synthesizer/file.go测试计划 / Test plan
priority的凭证文件,列表接口返回priority整数值 / Auth files withpriorityreturn it as integer in list responsenote的凭证文件,列表接口返回note字符串 / Auth files withnotereturn it as string in list responsePATCH /auth-files/fields传入note可正常写入和清除 /PATCH /auth-files/fieldswithnotewrites and clears correctly🤖 Generated with Claude Code