-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat(api): expose priority and note in GET /auth-files response #2124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -332,6 +332,12 @@ func (h *Handler) listAuthFilesFromDisk(c *gin.Context) { | |
| emailValue := gjson.GetBytes(data, "email").String() | ||
| fileData["type"] = typeValue | ||
| fileData["email"] = emailValue | ||
| if pv := gjson.GetBytes(data, "priority"); pv.Exists() { | ||
| fileData["priority"] = int(pv.Int()) | ||
| } | ||
| if nv := gjson.GetBytes(data, "note"); nv.Exists() && strings.TrimSpace(nv.String()) != "" { | ||
| fileData["note"] = strings.TrimSpace(nv.String()) | ||
| } | ||
|
Comment on lines
+338
to
+340
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The expression if nv := gjson.GetBytes(data, "note"); nv.Exists() {
if trimmed := strings.TrimSpace(nv.String()); trimmed != "" {
fileData["note"] = trimmed
}
} |
||
| } | ||
|
|
||
| files = append(files, fileData) | ||
|
|
@@ -415,6 +421,18 @@ func (h *Handler) buildAuthFileEntry(auth *coreauth.Auth) gin.H { | |
| if claims := extractCodexIDTokenClaims(auth); claims != nil { | ||
| entry["id_token"] = claims | ||
| } | ||
| // Expose priority from Attributes (set by synthesizer from JSON "priority" field). | ||
| if p := strings.TrimSpace(authAttribute(auth, "priority")); p != "" { | ||
| if parsed, err := strconv.Atoi(p); err == nil { | ||
| entry["priority"] = parsed | ||
| } | ||
| } | ||
| // Expose note from Metadata. | ||
| if note, ok := auth.Metadata["note"].(string); ok { | ||
| if trimmed := strings.TrimSpace(note); trimmed != "" { | ||
| entry["note"] = trimmed | ||
| } | ||
| } | ||
|
Comment on lines
+430
to
+435
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's an inconsistency in how the For consistency and correctness, // Expose note from Attributes (set by synthesizer from JSON "note" field).
if note := authAttribute(auth, "note"); note != "" {
entry["note"] = note
} |
||
| return entry | ||
| } | ||
|
|
||
|
|
@@ -839,7 +857,7 @@ func (h *Handler) PatchAuthFileStatus(c *gin.Context) { | |
| c.JSON(http.StatusOK, gin.H{"status": "ok", "disabled": *req.Disabled}) | ||
| } | ||
|
|
||
| // PatchAuthFileFields updates editable fields (prefix, proxy_url, priority) of an auth file. | ||
| // PatchAuthFileFields updates editable fields (prefix, proxy_url, priority, note) of an auth file. | ||
| func (h *Handler) PatchAuthFileFields(c *gin.Context) { | ||
| if h.authManager == nil { | ||
| c.JSON(http.StatusServiceUnavailable, gin.H{"error": "core auth manager unavailable"}) | ||
|
|
@@ -851,6 +869,7 @@ func (h *Handler) PatchAuthFileFields(c *gin.Context) { | |
| Prefix *string `json:"prefix"` | ||
| ProxyURL *string `json:"proxy_url"` | ||
| Priority *int `json:"priority"` | ||
| Note *string `json:"note"` | ||
| } | ||
| if err := c.ShouldBindJSON(&req); err != nil { | ||
| c.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body"}) | ||
|
|
@@ -904,6 +923,18 @@ func (h *Handler) PatchAuthFileFields(c *gin.Context) { | |
| } | ||
| changed = true | ||
| } | ||
| 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 | ||
| } | ||
|
Comment on lines
+926
to
+937
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block for handling 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
} |
||
|
|
||
| if !changed { | ||
| c.JSON(http.StatusBadRequest, gin.H{"error": "no fields to update"}) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the auth manager is unavailable, the fallback path now emits
priorityfor any file that merely has aprioritykey, butgjson.Int()coerces non-numeric values (for example"priority":"high"or"priority":null) to0. 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 includesprioritywhen integer parsing succeeds.Useful? React with 👍 / 👎.