mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-23 02:26:42 +00:00
GODT-1815: Start with missing gluon files
This commit is contained in:
@ -45,37 +45,37 @@ func (user *User) HasSync() bool {
|
||||
return user.vault.getUser(user.userID).HasSync
|
||||
}
|
||||
|
||||
func (user *User) UpdateKeyPass(keyPass []byte) error {
|
||||
func (user *User) SetKeyPass(keyPass []byte) error {
|
||||
return user.vault.modUser(user.userID, func(data *UserData) {
|
||||
data.KeyPass = keyPass
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateAuth updates the auth secrets for the given user.
|
||||
func (user *User) UpdateAuth(authUID, authRef string) error {
|
||||
// SetAuth updates the auth secrets for the given user.
|
||||
func (user *User) SetAuth(authUID, authRef string) error {
|
||||
return user.vault.modUser(user.userID, func(data *UserData) {
|
||||
data.AuthUID = authUID
|
||||
data.AuthRef = authRef
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateGluonData updates the gluon ID and key for the given user.
|
||||
func (user *User) UpdateGluonData(gluonID string, gluonKey []byte) error {
|
||||
// SetGluonAuth updates the gluon ID and key for the given user.
|
||||
func (user *User) SetGluonAuth(gluonID string, gluonKey []byte) error {
|
||||
return user.vault.modUser(user.userID, func(data *UserData) {
|
||||
data.GluonID = gluonID
|
||||
data.GluonKey = gluonKey
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateEventID updates the event ID for the given user.
|
||||
func (user *User) UpdateEventID(eventID string) error {
|
||||
// SetEventID updates the event ID for the given user.
|
||||
func (user *User) SetEventID(eventID string) error {
|
||||
return user.vault.modUser(user.userID, func(data *UserData) {
|
||||
data.EventID = eventID
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateSync updates the sync state for the given user.
|
||||
func (user *User) UpdateSync(hasSync bool) error {
|
||||
// SetSync updates the sync state for the given user.
|
||||
func (user *User) SetSync(hasSync bool) error {
|
||||
return user.vault.modUser(user.userID, func(data *UserData) {
|
||||
data.HasSync = hasSync
|
||||
})
|
||||
|
||||
@ -24,16 +24,16 @@ func TestUser(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Set event IDs for user 1 and 2.
|
||||
require.NoError(t, user1.UpdateEventID("eventID1"))
|
||||
require.NoError(t, user2.UpdateEventID("eventID2"))
|
||||
require.NoError(t, user1.SetEventID("eventID1"))
|
||||
require.NoError(t, user2.SetEventID("eventID2"))
|
||||
|
||||
// Set sync state for user 1 and 2.
|
||||
require.NoError(t, user1.UpdateSync(true))
|
||||
require.NoError(t, user2.UpdateSync(false))
|
||||
require.NoError(t, user1.SetSync(true))
|
||||
require.NoError(t, user2.SetSync(false))
|
||||
|
||||
// Set gluon data for user 1 and 2.
|
||||
require.NoError(t, user1.UpdateGluonData("gluonID1", []byte("gluonKey1")))
|
||||
require.NoError(t, user2.UpdateGluonData("gluonID2", []byte("gluonKey2")))
|
||||
require.NoError(t, user1.SetGluonAuth("gluonID1", []byte("gluonKey1")))
|
||||
require.NoError(t, user2.SetGluonAuth("gluonID2", []byte("gluonKey2")))
|
||||
|
||||
// List available users.
|
||||
require.ElementsMatch(t, []string{"userID1", "userID2"}, s.GetUserIDs())
|
||||
|
||||
@ -74,6 +74,22 @@ func (vault *Vault) GetUser(userID string) (*User, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ForUser executes a callback for each user in the vault.
|
||||
func (vault *Vault) ForUser(fn func(*User) error) error {
|
||||
for _, userID := range vault.GetUserIDs() {
|
||||
user, err := vault.GetUser(userID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := fn(user); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddUser creates a new user in the vault with the given ID and username.
|
||||
// A bridge password is generated using the package's token generator.
|
||||
func (vault *Vault) AddUser(userID, username, authUID, authRef string, keyPass []byte) (*User, error) {
|
||||
Reference in New Issue
Block a user