mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-17 23:56:56 +00:00
refactor: GetBridgeAuthChannel --> GetAuthUpdateChannel
This commit is contained in:
@ -25,7 +25,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/ProtonMail/proton-bridge/internal/events"
|
||||
m "github.com/ProtonMail/proton-bridge/internal/metrics"
|
||||
"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"
|
||||
@ -117,7 +117,7 @@ func New(
|
||||
}
|
||||
|
||||
if pref.GetBool(preferences.FirstStartKey) {
|
||||
b.SendMetric(m.New(m.Setup, m.FirstStart, m.Label(version)))
|
||||
b.SendMetric(metrics.New(metrics.Setup, metrics.FirstStart, metrics.Label(version)))
|
||||
}
|
||||
|
||||
go b.heartbeat()
|
||||
@ -134,7 +134,7 @@ func (b *Bridge) heartbeat() {
|
||||
}
|
||||
nextTime := time.Unix(next, 0)
|
||||
if time.Now().After(nextTime) {
|
||||
b.SendMetric(m.New(m.Heartbeat, m.Daily, m.NoLabel))
|
||||
b.SendMetric(metrics.New(metrics.Heartbeat, metrics.Daily, metrics.NoLabel))
|
||||
nextTime = nextTime.Add(24 * time.Hour)
|
||||
b.pref.Set(preferences.NextHeartbeatKey, strconv.FormatInt(nextTime.Unix(), 10))
|
||||
}
|
||||
@ -180,7 +180,7 @@ func (b *Bridge) watchBridgeOutdated() {
|
||||
|
||||
// watchAPIAuths receives auths from the client manager and sends them to the appropriate user.
|
||||
func (b *Bridge) watchAPIAuths() {
|
||||
for auth := range b.clientManager.GetBridgeAuthChannel() {
|
||||
for auth := range b.clientManager.GetAuthUpdateChannel() {
|
||||
logrus.Debug("Bridge received auth from ClientManager")
|
||||
|
||||
user, ok := b.hasUser(auth.UserID)
|
||||
@ -296,6 +296,9 @@ func (b *Bridge) connectExistingUser(user *User, auth *pmapi.Auth, hashedPasswor
|
||||
|
||||
// addNewUser adds a new bridge user to the bridge.
|
||||
func (b *Bridge) addNewUser(user *pmapi.User, auth *pmapi.Auth, hashedPassword string) (err error) {
|
||||
b.lock.Lock()
|
||||
defer b.lock.Unlock()
|
||||
|
||||
client := b.clientManager.GetClient(user.ID)
|
||||
|
||||
if auth, err = client.AuthRefresh(auth.GenToken()); err != nil {
|
||||
@ -325,7 +328,7 @@ func (b *Bridge) addNewUser(user *pmapi.User, auth *pmapi.Auth, hashedPassword s
|
||||
return errors.Wrap(err, "failed to initialise user")
|
||||
}
|
||||
|
||||
b.SendMetric(m.New(m.Setup, m.NewUser, m.NoLabel))
|
||||
b.SendMetric(metrics.New(metrics.Setup, metrics.NewUser, metrics.NoLabel))
|
||||
|
||||
return
|
||||
}
|
||||
@ -459,7 +462,7 @@ func (b *Bridge) ReportBug(osType, osVersion, description, accountName, address,
|
||||
}
|
||||
|
||||
// SendMetric sends a metric. We don't want to return any errors, only log them.
|
||||
func (b *Bridge) SendMetric(m m.Metric) {
|
||||
func (b *Bridge) SendMetric(m metrics.Metric) {
|
||||
c := b.clientManager.GetClient("metric_reporter")
|
||||
defer c.Logout()
|
||||
|
||||
|
||||
@ -214,7 +214,7 @@ func testNewBridge(t *testing.T, m mocks) *Bridge {
|
||||
m.config.EXPECT().GetDBDir().Return("/tmp").AnyTimes()
|
||||
m.config.EXPECT().GetIMAPCachePath().Return(cacheFile.Name()).AnyTimes()
|
||||
m.eventListener.EXPECT().Add(events.UpgradeApplicationEvent, gomock.Any())
|
||||
m.clientManager.EXPECT().GetBridgeAuthChannel().Return(make(chan *pmapi.ClientAuth))
|
||||
m.clientManager.EXPECT().GetAuthUpdateChannel().Return(make(chan *pmapi.ClientAuth))
|
||||
|
||||
bridge := New(m.config, m.prefProvider, m.PanicHandler, m.eventListener, "ver", m.clientManager, m.credentialsStore)
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// Code generated by ./credits.sh at Thu Apr 16 13:43:04 CEST 2020. DO NOT EDIT.
|
||||
// Code generated by ./credits.sh at Fri Apr 17 13:33:28 CEST 2020. DO NOT EDIT.
|
||||
|
||||
package bridge
|
||||
|
||||
|
||||
@ -264,18 +264,18 @@ func (mr *MockClientManagerMockRecorder) GetAnonymousClient() *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAnonymousClient", reflect.TypeOf((*MockClientManager)(nil).GetAnonymousClient))
|
||||
}
|
||||
|
||||
// GetBridgeAuthChannel mocks base method
|
||||
func (m *MockClientManager) GetBridgeAuthChannel() chan pmapi.ClientAuth {
|
||||
// GetAuthUpdateChannel mocks base method
|
||||
func (m *MockClientManager) GetAuthUpdateChannel() chan pmapi.ClientAuth {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetBridgeAuthChannel")
|
||||
ret := m.ctrl.Call(m, "GetAuthUpdateChannel")
|
||||
ret0, _ := ret[0].(chan pmapi.ClientAuth)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetBridgeAuthChannel indicates an expected call of GetBridgeAuthChannel
|
||||
func (mr *MockClientManagerMockRecorder) GetBridgeAuthChannel() *gomock.Call {
|
||||
// GetAuthUpdateChannel indicates an expected call of GetBridgeAuthChannel
|
||||
func (mr *MockClientManagerMockRecorder) GetAuthUpdateChannel() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBridgeAuthChannel", reflect.TypeOf((*MockClientManager)(nil).GetBridgeAuthChannel))
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAuthUpdateChannel", reflect.TypeOf((*MockClientManager)(nil).GetBridgeAuthChannel))
|
||||
}
|
||||
|
||||
// GetClient mocks base method
|
||||
|
||||
@ -57,5 +57,5 @@ type ClientManager interface {
|
||||
GetAnonymousClient() pmapi.Client
|
||||
AllowProxy()
|
||||
DisallowProxy()
|
||||
GetBridgeAuthChannel() chan pmapi.ClientAuth
|
||||
GetAuthUpdateChannel() chan pmapi.ClientAuth
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user