Use saved bindings in Advanced Sync lookup

This commit is contained in:
Joe Julian
2026-04-06 19:36:38 -07:00
parent fc59fb4869
commit 99ff89de32
2 changed files with 88 additions and 3 deletions
+45 -3
View File
@@ -2193,12 +2193,54 @@ func (u *ui) matchingAdvancedSyncRemoteCredentialEntries() []vault.Entry {
if baseURL == "" {
return nil
}
var matches []vault.Entry
for _, entry := range u.availableRemoteCredentialEntries() {
remotePath := strings.TrimSpace(u.syncRemotePath.Text())
entries := u.availableRemoteCredentialEntries()
byID := make(map[string]vault.Entry, len(entries))
for _, entry := range entries {
byID[entry.ID] = entry
}
matches := make([]vault.Entry, 0, len(entries))
seen := make(map[string]struct{}, len(entries))
appendMatch := func(entry vault.Entry) {
if strings.TrimSpace(entry.ID) == "" {
return
}
if _, ok := seen[entry.ID]; ok {
return
}
seen[entry.ID] = struct{}{}
matches = append(matches, entry)
}
for _, entry := range entries {
if normalizeRemoteCredentialURL(entry.URL) != baseURL {
continue
}
matches = append(matches, entry)
appendMatch(entry)
}
profilesByID := make(map[string]vault.RemoteProfile)
for _, profile := range u.availableRemoteProfiles() {
profilesByID[profile.ID] = profile
}
localVaultPath := strings.TrimSpace(u.vaultPath.Text())
for _, record := range u.recentRemotes {
if localVaultPath != "" && strings.TrimSpace(record.LocalVaultPath) != localVaultPath {
continue
}
profile, ok := profilesByID[strings.TrimSpace(record.RemoteProfileID)]
if !ok {
continue
}
if normalizeRemoteCredentialURL(profile.BaseURL) != baseURL {
continue
}
if remotePath != "" && strings.TrimSpace(profile.Path) != remotePath && strings.TrimSpace(record.Path) != remotePath {
continue
}
entry, ok := byID[strings.TrimSpace(record.CredentialEntryID)]
if !ok {
continue
}
appendMatch(entry)
}
return matches
}