48 lines
1.8 KiB
Diff
48 lines
1.8 KiB
Diff
# UNDF: UNDF-2026-000001093
|
|
--- a/models/asymkey/ssh_key.go
|
|
+++ b/models/asymkey/ssh_key.go
|
|
@@ -378,19 +378,22 @@ func synchronizePublicKeys(ctx context.Context, s *auth.Source, usr *user_model.
|
|
// Process the provided keys to remove duplicates and name part
|
|
- var providedKeys []string
|
|
+ providedKeysSet := make(map[string]struct{})
|
|
+ var providedKeys []string
|
|
for _, v := range sshPublicKeys {
|
|
sshKeySplit := strings.Split(v, " ")
|
|
if len(sshKeySplit) > 1 {
|
|
key := strings.Join(sshKeySplit[:2], " ")
|
|
- if !util.SliceContainsString(providedKeys, key) {
|
|
+ if _, exists := providedKeysSet[key]; !exists {
|
|
+ providedKeysSet[key] = struct{}{}
|
|
providedKeys = append(providedKeys, key)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Check if Public Key sync is needed
|
|
@@ -399,14 +402,16 @@ func synchronizePublicKeys(ctx context.Context, s *auth.Source, usr *user_model.
|
|
|
|
// Add new Public SSH Keys that doesn't already exist in DB
|
|
+ giteaKeysSet := make(map[string]struct{}, len(giteaKeys))
|
|
+ for _, k := range giteaKeys {
|
|
+ giteaKeysSet[k] = struct{}{}
|
|
+ }
|
|
var newKeys []string
|
|
for _, key := range providedKeys {
|
|
- if !util.SliceContainsString(giteaKeys, key) {
|
|
+ if _, exists := giteaKeysSet[key]; !exists {
|
|
newKeys = append(newKeys, key)
|
|
}
|
|
}
|
|
if AddPublicKeysBySource(ctx, usr, s, newKeys) {
|
|
sshKeysNeedUpdate = true
|
|
}
|
|
|
|
// Mark keys from DB that no longer exist in the source for deletion
|
|
var giteaKeysToDelete []string
|
|
for _, giteaKey := range giteaKeys {
|
|
- if !util.SliceContainsString(providedKeys, giteaKey) {
|
|
+ if _, exists := providedKeysSet[giteaKey]; !exists {
|
|
log.Trace("synchronizePublicKeys[%s]: Marking Public SSH Key for deletion for user %s: %v", s.Name, usr.Name, giteaKey)
|
|
giteaKeysToDelete = append(giteaKeysToDelete, giteaKey)
|
|
}
|
|
}
|