correctly remove duplicated secrets and ssh keys

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2025-02-28 15:23:46 +01:00
parent 4ed1e07f16
commit fe17ebda89
4 changed files with 56 additions and 2 deletions

View File

@ -28,7 +28,7 @@ func (s SSHKeys) Normalize() SSHKeys {
if len(s) == 0 {
return nil
}
return removeDupes(s)
return removeSSHDupes(s)
}
func (s SSHKeys) ToPB() []*controllerapi.SSH {
@ -131,3 +131,17 @@ func IsGitSSH(repo string) bool {
}
return url.Scheme == gitutil.SSHProtocol
}
func removeSSHDupes(s []*SSH) []*SSH {
var res []*SSH
m := map[string]int{}
for _, ssh := range s {
if i, ok := m[ssh.ID]; ok {
res[i] = ssh
} else {
m[ssh.ID] = len(res)
res = append(res, ssh)
}
}
return res
}