forked from Silverfish/proton-bridge
feat(GODT-2710): Send config success on IMAP/SMTP connection..
This commit is contained in:
62
internal/user/config_status.go
Normal file
62
internal/user/config_status.go
Normal file
@ -0,0 +1,62 @@
|
||||
// Copyright (c) 2023 Proton AG
|
||||
//
|
||||
// This file is part of Proton Mail Bridge.
|
||||
//
|
||||
// Proton Mail 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.
|
||||
//
|
||||
// Proton Mail 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 Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/ProtonMail/gluon/reporter"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/configstatus"
|
||||
)
|
||||
|
||||
func (user *User) SendConfigStatusSuccess() {
|
||||
if !user.telemetryManager.IsTelemetryAvailable() {
|
||||
return
|
||||
}
|
||||
|
||||
if !user.configStatus.IsPending() {
|
||||
return
|
||||
}
|
||||
|
||||
var builder configstatus.ConfigSuccessBuilder
|
||||
success := builder.New(user.configStatus.Data)
|
||||
data, err := json.Marshal(success)
|
||||
if err != nil {
|
||||
if err := user.reporter.ReportMessageWithContext("Cannot parse config_success data.", reporter.Context{
|
||||
"error": err,
|
||||
}); err != nil {
|
||||
user.log.WithError(err).Error("Failed to parse config_success data.")
|
||||
}
|
||||
}
|
||||
|
||||
if err := user.SendTelemetry(context.Background(), data); err == nil {
|
||||
if err := user.configStatus.ApplySuccess(); err != nil {
|
||||
user.log.WithError(err).Error("Failed to ApplySuccess on config_status.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (user *User) SendConfigStatusAbort() {
|
||||
}
|
||||
|
||||
func (user *User) SendConfigStatusRecovery() {
|
||||
}
|
||||
|
||||
func (user *User) SendConfigStatusProgress() {
|
||||
}
|
||||
@ -86,6 +86,8 @@ func (conn *imapConnector) Authorize(username string, password []byte) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
conn.User.SendConfigStatusSuccess()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@ -40,6 +40,7 @@ import (
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/events"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/logging"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/safe"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/telemetry"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/vault"
|
||||
"github.com/ProtonMail/proton-bridge/v3/pkg/algo"
|
||||
"github.com/bradenaw/juniper/xslices"
|
||||
@ -95,7 +96,8 @@ type User struct {
|
||||
|
||||
panicHandler async.PanicHandler
|
||||
|
||||
configStatus *configstatus.ConfigurationStatus
|
||||
configStatus *configstatus.ConfigurationStatus
|
||||
telemetryManager telemetry.Availability
|
||||
}
|
||||
|
||||
// New returns a new user.
|
||||
@ -108,7 +110,8 @@ func New(
|
||||
crashHandler async.PanicHandler,
|
||||
showAllMail bool,
|
||||
maxSyncMemory uint64,
|
||||
cacheDir string,
|
||||
statsDir string,
|
||||
telemetryManager telemetry.Availability,
|
||||
) (*User, error) {
|
||||
logrus.WithField("userID", apiUser.ID).Info("Creating new user")
|
||||
|
||||
@ -130,7 +133,7 @@ func New(
|
||||
"numLabels": len(apiLabels),
|
||||
}).Info("Creating user object")
|
||||
|
||||
configStatusFile := filepath.Join(cacheDir, apiUser.ID+".json")
|
||||
configStatusFile := filepath.Join(statsDir, apiUser.ID+".json")
|
||||
configStatus, err := configstatus.LoadConfigurationStatus(configStatusFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to init configuration status file: %w", err)
|
||||
@ -169,7 +172,8 @@ func New(
|
||||
|
||||
panicHandler: crashHandler,
|
||||
|
||||
configStatus: configStatus,
|
||||
configStatus: configStatus,
|
||||
telemetryManager: telemetryManager,
|
||||
}
|
||||
|
||||
// Initialize the user's update channels for its current address mode.
|
||||
|
||||
@ -26,8 +26,10 @@ import (
|
||||
"github.com/ProtonMail/go-proton-api/server"
|
||||
"github.com/ProtonMail/go-proton-api/server/backend"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/certs"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/telemetry/mocks"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/vault"
|
||||
"github.com/ProtonMail/proton-bridge/v3/tests"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/goleak"
|
||||
)
|
||||
@ -143,7 +145,10 @@ func withUser(tb testing.TB, ctx context.Context, _ *server.Server, m *proton.Ma
|
||||
vaultUser, err := v.AddUser(apiUser.ID, username, username+"@pm.me", apiAuth.UID, apiAuth.RefreshToken, saltedKeyPass)
|
||||
require.NoError(tb, err)
|
||||
|
||||
user, err := New(ctx, vaultUser, client, nil, apiUser, nil, true, vault.DefaultMaxSyncMemory, tb.TempDir())
|
||||
ctl := gomock.NewController(tb)
|
||||
defer ctl.Finish()
|
||||
manager := mocks.NewMockHeartbeatManager(ctl)
|
||||
user, err := New(ctx, vaultUser, client, nil, apiUser, nil, true, vault.DefaultMaxSyncMemory, tb.TempDir(), manager)
|
||||
require.NoError(tb, err)
|
||||
defer user.Close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user