diff options
author | Lukas Prettenthaler <zyclonite@users.noreply.github.com> | 2019-04-26 17:01:54 +0200 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2019-04-26 18:01:54 +0300 |
commit | 81059a2567be0cd811ca10e3545282c9aa53276a (patch) | |
tree | ff8f31323a2d14f30d7ca87c2028ba3d2266539d | |
parent | f6eedd4dc8fb10df869750c69e2bead0521ec0eb (diff) | |
download | gitea-81059a2567be0cd811ca10e3545282c9aa53276a.tar.gz gitea-81059a2567be0cd811ca10e3545282c9aa53276a.zip |
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>
-rw-r--r-- | models/error.go | 2 | ||||
-rw-r--r-- | models/user.go | 6 |
2 files changed, 6 insertions, 2 deletions
diff --git a/models/error.go b/models/error.go index febe3f3e04..c3495b28d7 100644 --- a/models/error.go +++ b/models/error.go @@ -318,7 +318,7 @@ func IsErrKeyAlreadyExist(err error) bool { } 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) } diff --git a/models/user.go b/models/user.go index 31e2387feb..04fe36ffa0 100644 --- a/models/user.go +++ b/models/user.go @@ -1526,7 +1526,11 @@ func addLdapSSHPublicKeys(usr *User, s *LoginSource, SSHPublicKeys []string) boo if err == nil { sshKeyName := fmt.Sprintf("%s-%s", s.Name, sshKey[0:40]) 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 { log.Trace("addLdapSSHPublicKeys[%s]: Added LDAP Public SSH Key for user %s", s.Name, usr.Name) sshKeysNeedUpdate = true |