Skip to content

feat(api): expose priority and note in GET /auth-files response#2124

Open
RGBadmin wants to merge 1 commit intorouter-for-me:mainfrom
RGBadmin:feat/auth-list-priority-note
Open

feat(api): expose priority and note in GET /auth-files response#2124
RGBadmin wants to merge 1 commit intorouter-for-me:mainfrom
RGBadmin:feat/auth-list-priority-note

Conversation

@RGBadmin
Copy link
Contributor

概述 / Summary

GET /auth-files 列表接口此前不返回凭证文件中的 prioritynote 字段,导致前端无法在卡片上展示优先级和备注,也无法按优先级排序。本 PR 将这两个字段暴露到列表响应中,并扩展 PATCH /auth-files/fields 以支持写入 note

The GET /auth-files list endpoint previously omitted the priority and note fields 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 extends PATCH /auth-files/fields to support writing the note field.

改动详情 / Changes

1. buildAuthFileEntry() — 正常路径 / Normal path

  • auth.Attributes["priority"](合成阶段已写入)读取 priority,转为 int 返回
  • auth.Metadata["note"] 读取 note(string),非空时返回
  • Reads priority from auth.Attributes["priority"] (already set by synthesizer), converts to int
  • Reads note from auth.Metadata["note"] (string), includes when non-empty

2. listAuthFilesFromDisk() — 回退路径 / Fallback path

  • 通过 gjson 从磁盘文件中额外读取 prioritynote 字段
  • Uses gjson to additionally read priority and note from on-disk JSON files

3. synthesizeFileAuths() — 合成阶段 / Synthesis

  • 在 priority 读取之后,补充从 metadata["note"] 读取 note 并存入 auth.Attributes["note"]
  • After the existing priority extraction, reads note from metadata["note"] into auth.Attributes["note"]

4. PatchAuthFileFields() — 字段写入 / Field update

  • 请求结构体新增 Note *string 字段
  • 空字符串时从 Metadata 中删除 note,非空时写入
  • Adds Note *string to the request struct
  • Empty string removes note from Metadata; non-empty string writes it

改动文件 / Changed files

文件 / File 改动 / Change
internal/api/handlers/management/auth_files.go 列表响应增加 priority/note;PATCH 支持 note 写入
internal/watcher/synthesizer/file.go 合成阶段读取 note 到 Attributes

测试计划 / Test plan

  • priority 的凭证文件,列表接口返回 priority 整数值 / Auth files with priority return it as integer in list response
  • note 的凭证文件,列表接口返回 note 字符串 / Auth files with note return it as string in list response
  • 不含 priority/note 的凭证文件,响应中不包含这两个字段 / Auth files without priority/note omit these fields
  • PATCH /auth-files/fields 传入 note 可正常写入和清除 / PATCH /auth-files/fields with note writes and clears correctly
  • auth manager 不可用时,回退路径同样返回 priority/note / Fallback disk-read path also returns priority/note when auth manager is unavailable

🤖 Generated with Claude Code

…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>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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

  • API Enhancement for Auth Files: The GET /auth-files endpoint now includes priority and note fields in its response, enabling richer display and sorting capabilities on the frontend.
  • Note Field Management: The PATCH /auth-files/fields endpoint has been extended to allow updating and clearing the note field for authentication files.
  • Data Synthesis and Fallback: Logic was added to ensure priority and note are correctly read during the synthesis phase and also when falling back to direct disk reads.

🧠 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
  • internal/api/handlers/management/auth_files.go
    • Implemented reading of 'priority' and 'note' fields from disk using gjson in the fallback listAuthFilesFromDisk function.
    • Added logic to buildAuthFileEntry to extract and include 'priority' (as an integer) from auth attributes and 'note' (as a string) from auth metadata in the API response.
    • Updated the PatchAuthFileFields request struct to include a Note *string field.
    • Modified PatchAuthFileFields to handle updating or deleting the 'note' field in auth metadata based on the request payload.
  • internal/watcher/synthesizer/file.go
    • Introduced logic within synthesizeFileAuths to read the 'note' field from file metadata and store it in the auth object's attributes.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +430 to +435
// Expose note from Metadata.
if note, ok := auth.Metadata["note"].(string); ok {
if trimmed := strings.TrimSpace(note); trimmed != "" {
entry["note"] = trimmed
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

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
	}

Comment on lines +338 to +340
if nv := gjson.GetBytes(data, "note"); nv.Exists() && strings.TrimSpace(nv.String()) != "" {
fileData["note"] = strings.TrimSpace(nv.String())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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
	}
}

Comment on lines +926 to +937
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
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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
	}

Copy link

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

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: 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".

Comment on lines +335 to +337
if pv := gjson.GetBytes(data, "priority"); pv.Exists() {
fileData["priority"] = int(pv.Int())
}

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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.

1 participant