refactor: no more pmapifactory

This commit is contained in:
James Houlahan
2020-04-08 13:07:13 +02:00
parent 5bf4d9c6f5
commit db02eb694d
22 changed files with 70 additions and 76 deletions

View File

@ -31,11 +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"
)
var (
log = config.GetLogEntry("api") //nolint[gochecknoglobals]
log = logs.GetLogEntry("api") //nolint[gochecknoglobals]
)
type apiServer struct {

View File

@ -28,8 +28,8 @@ import (
"github.com/ProtonMail/proton-bridge/internal/metrics"
"github.com/ProtonMail/proton-bridge/internal/preferences"
"github.com/ProtonMail/proton-bridge/internal/store"
"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/pmapi"
"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"
@ -37,8 +37,8 @@ import (
)
var (
log = config.GetLogEntry("bridge") //nolint[gochecknoglobals]
isApplicationOutdated = false //nolint[gochecknoglobals]
log = logs.GetLogEntry("bridge") //nolint[gochecknoglobals]
isApplicationOutdated = false //nolint[gochecknoglobals]
)
// Bridge is a struct handling users.

View File

@ -27,14 +27,14 @@ import (
"fmt"
"strings"
"github.com/ProtonMail/proton-bridge/pkg/config"
"github.com/ProtonMail/proton-bridge/pkg/logs"
"github.com/sirupsen/logrus"
)
const sep = "\x00"
var (
log = config.GetLogEntry("bridge") //nolint[gochecknoglobals]
log = logs.GetLogEntry("bridge") //nolint[gochecknoglobals]
ErrWrongFormat = errors.New("backend/creds: malformed password")
)

View File

@ -24,12 +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"
)
var (
log = config.GetLogEntry("frontend/cli") //nolint[gochecknoglobals]
log = logs.GetLogEntry("frontend/cli") //nolint[gochecknoglobals]
)
type frontendCLI struct {

View File

@ -26,10 +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"
)
var (
log = config.GetLogEntry("frontend") // nolint[unused]
log = logs.GetLogEntry("frontend") // nolint[unused]
)
// Frontend is an interface to be implemented by each frontend type (cli, gui, html).

View File

@ -43,6 +43,7 @@ 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"
@ -58,7 +59,7 @@ import (
"github.com/therecipe/qt/widgets"
)
var log = config.GetLogEntry("frontend-qt")
var log = logs.GetLogEntry("frontend-qt")
var accountMutex = &sync.Mutex{}
// API between Bridge and Qt.

View File

@ -26,9 +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"
)
var log = config.GetLogEntry("frontend-nogui") //nolint[gochecknoglobals]
var log = logs.GetLogEntry("frontend-nogui") //nolint[gochecknoglobals]
type FrontendHeadless struct{}

View File

@ -17,7 +17,7 @@
package imap
import "github.com/ProtonMail/proton-bridge/pkg/config"
import "github.com/ProtonMail/proton-bridge/pkg/logs"
const (
fetchMessagesWorkers = 5 // In how many workers to fetch message (group list on IMAP).
@ -31,5 +31,5 @@ const (
)
var (
log = config.GetLogEntry("imap") //nolint[gochecknoglobals]
log = logs.GetLogEntry("imap") //nolint[gochecknoglobals]
)

View File

@ -1,34 +0,0 @@
// Copyright (c) 2020 Proton Technologies AG
//
// This file is part of ProtonMail Bridge.
//
// ProtonMail Bridge is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ProtonMail Bridge is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
// +build !pmapi_prod
// Package pmapifactory creates pmapi client instances.
package pmapifactory
import (
"github.com/ProtonMail/proton-bridge/pkg/listener"
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
)
func GetClientConfig(clientConfig *pmapi.ClientConfig) *pmapi.ClientConfig {
return clientConfig
}
func SetClientRoundTripper(_ *pmapi.ClientManager, _ *pmapi.ClientConfig, _ listener.Listener) {
// Use the default roundtripper; do nothing.
}

View File

@ -1,51 +0,0 @@
// Copyright (c) 2020 Proton Technologies AG
//
// This file is part of ProtonMail Bridge.
//
// ProtonMail Bridge is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ProtonMail Bridge is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
// +build pmapi_prod
// Package pmapifactory creates pmapi client instances.
package pmapifactory
import (
"time"
"github.com/ProtonMail/proton-bridge/internal/events"
"github.com/ProtonMail/proton-bridge/pkg/listener"
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
"github.com/sirupsen/logrus"
)
func GetClientConfig(clientConfig *pmapi.ClientConfig) *pmapi.ClientConfig {
// We set additional timeouts/thresholds for the request as a whole:
clientConfig.Timeout = 10 * time.Minute // Overall request timeout (~25MB / 10 mins => ~40kB/s, should be reasonable).
clientConfig.FirstReadTimeout = 30 * time.Second // 30s to match 30s response header timeout.
clientConfig.MinSpeed = 1 << 13 // Enforce minimum download speed of 8kB/s.
return clientConfig
}
func SetClientRoundTripper(cm *pmapi.ClientManager, cfg *pmapi.ClientConfig, listener listener.Listener) {
logrus.Info("Setting ClientManager to create clients with key pinning")
pin := pmapi.NewDialerWithPinning(cm, cfg.AppVersion)
pin.ReportCertIssueLocal = func() {
listener.Emit(events.TLSCertIssue, "")
}
cm.SetRoundTripper(pin.TransportWithPinning())
}

View File

@ -18,8 +18,8 @@
// Package smtp provides SMTP server of the Bridge.
package smtp
import "github.com/ProtonMail/proton-bridge/pkg/config"
import "github.com/ProtonMail/proton-bridge/pkg/logs"
var (
log = config.GetLogEntry("smtp") //nolint[gochecknoglobals]
log = logs.GetLogEntry("smtp") //nolint[gochecknoglobals]
)