fix: avoid listing credentials, prefer getting

This commit is contained in:
James Houlahan
2020-06-15 14:20:14 +02:00
parent c329711f9c
commit 9808c44714
2 changed files with 3 additions and 43 deletions

View File

@ -26,6 +26,7 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/)
* Crash in message.combineParts when copying nil slice
* Handle double charset better by using local ParseMediaType instead of mime.ParseMediaType
* Don't remove log dir
* GODT-422 Fix element not found (avoid listing credentials, prefer getting)
## [v1.2.7] Donghai-hotfix - beta (2020-05-07)

View File

@ -18,7 +18,6 @@
package credentials
import (
"errors"
"fmt"
"sort"
"sync"
@ -67,18 +66,9 @@ func (s *Store) Add(userID, userName, apiToken, mailboxPassword string, emails [
creds.SetEmailList(emails)
var has bool
if has, err = s.has(userID); err != nil {
log.WithField("userID", userID).WithError(err).Error("Could not check if user credentials already exist")
return
}
if has {
currentCredentials, err := s.get(userID)
if err == nil {
log.Info("Updating credentials of existing user")
currentCredentials, err := s.get(userID)
if err != nil {
return nil, err
}
creds.BridgePassword = currentCredentials.BridgePassword
creds.IsCombinedAddressMode = currentCredentials.IsCombinedAddressMode
creds.Timestamp = currentCredentials.Timestamp
@ -239,40 +229,9 @@ func (s *Store) Get(userID string) (creds *Credentials, err error) {
storeLocker.RLock()
defer storeLocker.RUnlock()
var has bool
if has, err = s.has(userID); err != nil {
log.WithError(err).Error("Could not check for credentials")
return
}
if !has {
err = errors.New("no credentials found for given userID")
return
}
return s.get(userID)
}
func (s *Store) has(userID string) (has bool, err error) {
if err = s.checkKeychain(); err != nil {
return
}
var ids []string
if ids, err = s.secrets.List(); err != nil {
log.WithError(err).Error("Could not list credentials")
return
}
for _, id := range ids {
if id == userID {
has = true
}
}
return
}
func (s *Store) get(userID string) (creds *Credentials, err error) {
log := log.WithField("user", userID)