forked from Silverfish/proton-bridge
fix: address review comments
This commit is contained in:
@ -31,12 +31,12 @@ import (
|
||||
"github.com/ProtonMail/proton-bridge/internal/preferences"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/config"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/listener"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/logs"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/ports"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var (
|
||||
log = logs.GetLogEntry("api") //nolint[gochecknoglobals]
|
||||
log = logrus.WithField("pkg", "api") //nolint[gochecknoglobals]
|
||||
)
|
||||
|
||||
type apiServer struct {
|
||||
|
||||
@ -29,7 +29,6 @@ import (
|
||||
"github.com/ProtonMail/proton-bridge/internal/preferences"
|
||||
"github.com/ProtonMail/proton-bridge/internal/store"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/listener"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/logs"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/pkg/errors"
|
||||
@ -37,8 +36,8 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
log = logs.GetLogEntry("bridge") //nolint[gochecknoglobals]
|
||||
isApplicationOutdated = false //nolint[gochecknoglobals]
|
||||
log = logrus.WithField("pkg", "bridge") //nolint[gochecknoglobals]
|
||||
isApplicationOutdated = false //nolint[gochecknoglobals]
|
||||
)
|
||||
|
||||
// Bridge is a struct handling users.
|
||||
@ -65,7 +64,8 @@ type Bridge struct {
|
||||
|
||||
lock sync.RWMutex
|
||||
|
||||
cancel chan struct{}
|
||||
// stopAll can be closed to stop all goroutines from looping (watchBridgeOutdated, watchAPIAuths, heartbeat etc).
|
||||
stopAll chan struct{}
|
||||
|
||||
userAgentClientName string
|
||||
userAgentClientVersion string
|
||||
@ -94,7 +94,7 @@ func New(
|
||||
storeCache: store.NewCache(config.GetIMAPCachePath()),
|
||||
idleUpdates: make(chan interface{}),
|
||||
lock: sync.RWMutex{},
|
||||
cancel: make(chan struct{}),
|
||||
stopAll: make(chan struct{}),
|
||||
}
|
||||
|
||||
// Allow DoH before starting bridge if the user has previously set this setting.
|
||||
@ -146,7 +146,7 @@ func (b *Bridge) heartbeat() {
|
||||
b.pref.Set(preferences.NextHeartbeatKey, strconv.FormatInt(nextTime.Unix(), 10))
|
||||
}
|
||||
|
||||
case <-b.cancel:
|
||||
case <-b.stopAll:
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -191,7 +191,7 @@ func (b *Bridge) watchBridgeOutdated() {
|
||||
isApplicationOutdated = true
|
||||
b.closeAllConnections()
|
||||
|
||||
case <-b.cancel:
|
||||
case <-b.stopAll:
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -218,7 +218,7 @@ func (b *Bridge) watchAPIAuths() {
|
||||
Error("User logout failed while watching API auths")
|
||||
}
|
||||
|
||||
case <-b.cancel:
|
||||
case <-b.stopAll:
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -568,7 +568,7 @@ func (b *Bridge) CheckConnection() error {
|
||||
|
||||
// StopWatchers stops all bridge goroutines.
|
||||
func (b *Bridge) StopWatchers() {
|
||||
close(b.cancel)
|
||||
close(b.stopAll)
|
||||
}
|
||||
|
||||
func (b *Bridge) updateCurrentUserAgent() {
|
||||
|
||||
6
internal/bridge/bridge_test_exports.go
Normal file
6
internal/bridge/bridge_test_exports.go
Normal file
@ -0,0 +1,6 @@
|
||||
package bridge
|
||||
|
||||
// IsAuthorized returns whether the user has received an Auth from the API yet.
|
||||
func (u *User) IsAuthorized() bool {
|
||||
return u.isAuthorized
|
||||
}
|
||||
@ -27,14 +27,13 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/ProtonMail/proton-bridge/pkg/logs"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const sep = "\x00"
|
||||
|
||||
var (
|
||||
log = logs.GetLogEntry("bridge") //nolint[gochecknoglobals]
|
||||
log = logrus.WithField("pkg", "bridge") //nolint[gochecknoglobals]
|
||||
|
||||
ErrWrongFormat = errors.New("backend/creds: malformed password")
|
||||
)
|
||||
|
||||
@ -164,7 +164,7 @@ func (u *User) SetIMAPIdleUpdateChannel() {
|
||||
// it tries to connect it.
|
||||
func (u *User) authorizeIfNecessary(emitEvent bool) (err error) {
|
||||
// If user is connected and has an auth channel, then perfect, nothing to do here.
|
||||
if u.creds.IsConnected() && u.HasAPIAuth() {
|
||||
if u.creds.IsConnected() && u.isAuthorized {
|
||||
// The keyring unlock is triggered here to resolve state where apiClient
|
||||
// is authenticated (we have auth token) but it was not possible to download
|
||||
// and unlock the keys (internet not reachable).
|
||||
@ -585,7 +585,3 @@ func (u *User) CloseConnection(address string) {
|
||||
func (u *User) GetStore() *store.Store {
|
||||
return u.store
|
||||
}
|
||||
|
||||
func (u *User) HasAPIAuth() bool {
|
||||
return u.isAuthorized
|
||||
}
|
||||
|
||||
@ -24,13 +24,13 @@ import (
|
||||
"github.com/ProtonMail/proton-bridge/internal/preferences"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/config"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/listener"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/logs"
|
||||
|
||||
"github.com/abiosoft/ishell"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var (
|
||||
log = logs.GetLogEntry("frontend/cli") //nolint[gochecknoglobals]
|
||||
log = logrus.WithField("pkg", "frontend/cli") //nolint[gochecknoglobals]
|
||||
)
|
||||
|
||||
type frontendCLI struct {
|
||||
|
||||
@ -26,11 +26,11 @@ import (
|
||||
"github.com/ProtonMail/proton-bridge/internal/frontend/types"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/config"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/listener"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/logs"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var (
|
||||
log = logs.GetLogEntry("frontend") // nolint[unused]
|
||||
log = logrus.WithField("pkg", "frontend") // nolint[unused]
|
||||
)
|
||||
|
||||
// Frontend is an interface to be implemented by each frontend type (cli, gui, html).
|
||||
|
||||
@ -43,9 +43,9 @@ import (
|
||||
"github.com/ProtonMail/proton-bridge/internal/frontend/types"
|
||||
"github.com/ProtonMail/proton-bridge/internal/preferences"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/config"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/logs"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/ports"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/useragent"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
//"github.com/ProtonMail/proton-bridge/pkg/keychain"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/listener"
|
||||
@ -59,7 +59,7 @@ import (
|
||||
"github.com/therecipe/qt/widgets"
|
||||
)
|
||||
|
||||
var log = logs.GetLogEntry("frontend-qt")
|
||||
var log = logrus.WithField("pkg", "frontend-qt")
|
||||
var accountMutex = &sync.Mutex{}
|
||||
|
||||
// API between Bridge and Qt.
|
||||
|
||||
@ -26,10 +26,10 @@ import (
|
||||
"github.com/ProtonMail/proton-bridge/internal/frontend/types"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/config"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/listener"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/logs"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var log = logs.GetLogEntry("frontend-nogui") //nolint[gochecknoglobals]
|
||||
var log = logrus.WithField("pkg", "frontend-nogui") //nolint[gochecknoglobals]
|
||||
|
||||
type FrontendHeadless struct{}
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
|
||||
package imap
|
||||
|
||||
import "github.com/ProtonMail/proton-bridge/pkg/logs"
|
||||
import "github.com/sirupsen/logrus"
|
||||
|
||||
const (
|
||||
fetchMessagesWorkers = 5 // In how many workers to fetch message (group list on IMAP).
|
||||
@ -31,5 +31,5 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
log = logs.GetLogEntry("imap") //nolint[gochecknoglobals]
|
||||
log = logrus.WithField("pkg", "imap") //nolint[gochecknoglobals]
|
||||
)
|
||||
|
||||
@ -18,8 +18,8 @@
|
||||
// Package smtp provides SMTP server of the Bridge.
|
||||
package smtp
|
||||
|
||||
import "github.com/ProtonMail/proton-bridge/pkg/logs"
|
||||
import "github.com/sirupsen/logrus"
|
||||
|
||||
var (
|
||||
log = logs.GetLogEntry("smtp") //nolint[gochecknoglobals]
|
||||
log = logrus.WithField("pkg", "smtp") //nolint[gochecknoglobals]
|
||||
)
|
||||
|
||||
@ -247,7 +247,7 @@ func (loop *eventLoop) processNextEvent() (more bool, err error) { // nolint[fun
|
||||
}
|
||||
|
||||
if event == nil {
|
||||
return
|
||||
return false, errors.New("received empty event")
|
||||
}
|
||||
|
||||
l = l.WithField("newEventID", event.EventID)
|
||||
|
||||
@ -19,7 +19,6 @@ package store
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
|
||||
@ -56,7 +55,7 @@ func (store *Store) TestGetStoreFilePath() string {
|
||||
func (store *Store) TestDumpDB(tb assert.TestingT) {
|
||||
if store == nil || store.db == nil {
|
||||
fmt.Printf(">>>>>>>> NIL STORE / DB <<<<<\n\n")
|
||||
assert.NoError(tb, errors.New("store or database is nil"))
|
||||
assert.Fail(tb, "store or database is nil")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user