Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions internal/watcher/synthesizer/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,30 @@ func synthesizeFileAuths(ctx *SynthesisContext, fullPath string, data []byte) []
}
}
}
// Extract cloak configuration from auth file metadata into attributes
// so that getCloakConfigFromAuth can read them for OAuth credentials.
if cloakObj, ok := metadata["cloak"].(map[string]any); ok {
if mode, ok := cloakObj["mode"].(string); ok && mode != "" {
a.Attributes["cloak_mode"] = mode
}
if strict, ok := cloakObj["strict-mode"].(bool); ok && strict {
a.Attributes["cloak_strict_mode"] = "true"
}
if words, ok := cloakObj["sensitive-words"].([]any); ok && len(words) > 0 {
var parts []string
for _, w := range words {
if s, ok := w.(string); ok {
parts = append(parts, s)
}
}
if len(parts) > 0 {
a.Attributes["cloak_sensitive_words"] = strings.Join(parts, ",")
}
}
if cache, ok := cloakObj["cache-user-id"].(bool); ok && cache {
a.Attributes["cloak_cache_user_id"] = "true"
}
}
Comment on lines +160 to +183
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The logic for extracting cloak configuration from metadata is duplicated here and in sdk/auth/filestore.go. To improve maintainability and ensure consistency, consider refactoring this into a shared utility function within the sdk/cliproxy/auth package (e.g., ApplyCloakConfigFromMetadata), similar to how ApplyCustomHeadersFromMetadata is implemented. This would ensure that any future changes to the cloak configuration schema are applied consistently across both the runtime and SDK paths.

Additionally, consider using strings.TrimSpace when parsing the mode and sensitive-words to make the configuration more robust, consistent with how other fields like prefix or note are handled in this file.

coreauth.ApplyCustomHeadersFromMetadata(a)
ApplyAuthExcludedModelsMeta(a, cfg, perAccountExcluded, "oauth")
// For codex auth files, extract plan_type from the JWT id_token.
Expand Down
24 changes: 24 additions & 0 deletions sdk/auth/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,30 @@ func (s *FileTokenStore) readAuthFile(path, baseDir string) (*cliproxyauth.Auth,
if email, ok := metadata["email"].(string); ok && email != "" {
auth.Attributes["email"] = email
}
// Extract cloak configuration from auth file metadata into attributes
// so that getCloakConfigFromAuth can read them for OAuth credentials.
if cloakObj, ok := metadata["cloak"].(map[string]any); ok {
if mode, ok := cloakObj["mode"].(string); ok && mode != "" {
auth.Attributes["cloak_mode"] = mode
}
if strict, ok := cloakObj["strict-mode"].(bool); ok && strict {
auth.Attributes["cloak_strict_mode"] = "true"
}
if words, ok := cloakObj["sensitive-words"].([]any); ok && len(words) > 0 {
var parts []string
for _, w := range words {
if s, ok := w.(string); ok {
parts = append(parts, s)
}
}
if len(parts) > 0 {
auth.Attributes["cloak_sensitive_words"] = strings.Join(parts, ",")
}
}
if cache, ok := cloakObj["cache-user-id"].(bool); ok && cache {
auth.Attributes["cloak_cache_user_id"] = "true"
}
}
Comment on lines +257 to +280
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This block is identical to the one added in internal/watcher/synthesizer/file.go. As suggested there, refactoring this into a shared helper function in the sdk/cliproxy/auth package would avoid code duplication and reduce the risk of logic divergence between the runtime and SDK code paths.

cliproxyauth.ApplyCustomHeadersFromMetadata(auth)
return auth, nil
}
Expand Down
Loading