mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	LDAP: ignore already existing public keys after ldap sync (#6766)
* fix type in public key exist error, only log trace for ldap public key import if existing Signed-off-by: Lukas Prettenthaler <lukas@noenv.com> * cleanup switch statement Signed-off-by: Lukas Prettenthaler <lukas@noenv.com> * replace switch with if, fix log formatting Signed-off-by: Lukas Prettenthaler <lukas@noenv.com> * fix formatting Signed-off-by: Lukas Prettenthaler <lukas@noenv.com>
This commit is contained in:
		
				
					committed by
					
						
						Lauris BH
					
				
			
			
				
	
			
			
			
						parent
						
							f6eedd4dc8
						
					
				
				
					commit
					81059a2567
				
			@@ -318,7 +318,7 @@ func IsErrKeyAlreadyExist(err error) bool {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (err ErrKeyAlreadyExist) Error() string {
 | 
					func (err ErrKeyAlreadyExist) Error() string {
 | 
				
			||||||
	return fmt.Sprintf("public key already exists [owner_id: %d, finter_print: %s, content: %s]",
 | 
						return fmt.Sprintf("public key already exists [owner_id: %d, finger_print: %s, content: %s]",
 | 
				
			||||||
		err.OwnerID, err.Fingerprint, err.Content)
 | 
							err.OwnerID, err.Fingerprint, err.Content)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1526,7 +1526,11 @@ func addLdapSSHPublicKeys(usr *User, s *LoginSource, SSHPublicKeys []string) boo
 | 
				
			|||||||
		if err == nil {
 | 
							if err == nil {
 | 
				
			||||||
			sshKeyName := fmt.Sprintf("%s-%s", s.Name, sshKey[0:40])
 | 
								sshKeyName := fmt.Sprintf("%s-%s", s.Name, sshKey[0:40])
 | 
				
			||||||
			if _, err := AddPublicKey(usr.ID, sshKeyName, sshKey, s.ID); err != nil {
 | 
								if _, err := AddPublicKey(usr.ID, sshKeyName, sshKey, s.ID); err != nil {
 | 
				
			||||||
				log.Error("addLdapSSHPublicKeys[%s]: Error adding LDAP Public SSH Key for user %s: %v", s.Name, usr.Name, err)
 | 
									if IsErrKeyAlreadyExist(err) {
 | 
				
			||||||
 | 
										log.Trace("addLdapSSHPublicKeys[%s]: LDAP Public SSH Key %s already exists for user", s.Name, usr.Name)
 | 
				
			||||||
 | 
									} else {
 | 
				
			||||||
 | 
										log.Error("addLdapSSHPublicKeys[%s]: Error adding LDAP Public SSH Key for user %s: %v", s.Name, usr.Name, err)
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				log.Trace("addLdapSSHPublicKeys[%s]: Added LDAP Public SSH Key for user %s", s.Name, usr.Name)
 | 
									log.Trace("addLdapSSHPublicKeys[%s]: Added LDAP Public SSH Key for user %s", s.Name, usr.Name)
 | 
				
			||||||
				sshKeysNeedUpdate = true
 | 
									sshKeysNeedUpdate = true
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user