forked from Silverfish/proton-bridge
fix: avoid listing credentials, prefer getting
This commit is contained in:
@ -26,6 +26,7 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/)
|
|||||||
* Crash in message.combineParts when copying nil slice
|
* Crash in message.combineParts when copying nil slice
|
||||||
* Handle double charset better by using local ParseMediaType instead of mime.ParseMediaType
|
* Handle double charset better by using local ParseMediaType instead of mime.ParseMediaType
|
||||||
* Don't remove log dir
|
* 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)
|
## [v1.2.7] Donghai-hotfix - beta (2020-05-07)
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,6 @@
|
|||||||
package credentials
|
package credentials
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
@ -67,18 +66,9 @@ func (s *Store) Add(userID, userName, apiToken, mailboxPassword string, emails [
|
|||||||
|
|
||||||
creds.SetEmailList(emails)
|
creds.SetEmailList(emails)
|
||||||
|
|
||||||
var has bool
|
currentCredentials, err := s.get(userID)
|
||||||
if has, err = s.has(userID); err != nil {
|
if err == nil {
|
||||||
log.WithField("userID", userID).WithError(err).Error("Could not check if user credentials already exist")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if has {
|
|
||||||
log.Info("Updating credentials of existing user")
|
log.Info("Updating credentials of existing user")
|
||||||
currentCredentials, err := s.get(userID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
creds.BridgePassword = currentCredentials.BridgePassword
|
creds.BridgePassword = currentCredentials.BridgePassword
|
||||||
creds.IsCombinedAddressMode = currentCredentials.IsCombinedAddressMode
|
creds.IsCombinedAddressMode = currentCredentials.IsCombinedAddressMode
|
||||||
creds.Timestamp = currentCredentials.Timestamp
|
creds.Timestamp = currentCredentials.Timestamp
|
||||||
@ -239,40 +229,9 @@ func (s *Store) Get(userID string) (creds *Credentials, err error) {
|
|||||||
storeLocker.RLock()
|
storeLocker.RLock()
|
||||||
defer storeLocker.RUnlock()
|
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)
|
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) {
|
func (s *Store) get(userID string) (creds *Credentials, err error) {
|
||||||
log := log.WithField("user", userID)
|
log := log.WithField("user", userID)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user