mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2026-02-04 00:08:33 +00:00
feat(BRIDGE-278): Rollout Feature Flag stickiness support; a new UUID 'sticky' value has been added to the vault"
This commit is contained in:
@ -17,17 +17,22 @@
|
||||
|
||||
package vault
|
||||
|
||||
import "github.com/google/uuid"
|
||||
|
||||
type Data struct {
|
||||
Settings Settings
|
||||
Users []UserData
|
||||
Cookies []byte
|
||||
Certs Certs
|
||||
Migrated bool
|
||||
// FeatureFlagStickyKey a utility value for ensuring rollout feature flags "stick" to a particular Bridge client.
|
||||
FeatureFlagStickyKey uuid.UUID
|
||||
}
|
||||
|
||||
func newDefaultData(gluonDir string) Data {
|
||||
return Data{
|
||||
Settings: newDefaultSettings(gluonDir),
|
||||
Certs: newDefaultCerts(),
|
||||
Settings: newDefaultSettings(gluonDir),
|
||||
Certs: newDefaultCerts(),
|
||||
FeatureFlagStickyKey: uuid.New(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,6 +32,7 @@ import (
|
||||
"github.com/ProtonMail/gluon/async"
|
||||
"github.com/bradenaw/juniper/parallel"
|
||||
"github.com/bradenaw/juniper/xslices"
|
||||
"github.com/google/uuid"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -76,6 +77,10 @@ func New(vaultDir, gluonCacheDir string, key []byte, panicHandler async.PanicHan
|
||||
return nil, corrupt, err
|
||||
}
|
||||
|
||||
if err := vault.setFeatureFlagStickyKeyIfEmpty(); err != nil {
|
||||
return vault, corrupt, err
|
||||
}
|
||||
|
||||
vault.panicHandler = panicHandler
|
||||
|
||||
return vault, corrupt, nil
|
||||
@ -91,6 +96,22 @@ func (vault *Vault) GetUserIDs() []string {
|
||||
})
|
||||
}
|
||||
|
||||
// GetFeatureFlagStickyKey - the sticky key is a utility value for ensuring rollout feature flags "stick" to a particular Bridge client.
|
||||
func (vault *Vault) GetFeatureFlagStickyKey() uuid.UUID {
|
||||
return vault.getSafe().FeatureFlagStickyKey
|
||||
}
|
||||
|
||||
// setFeatureFlagStickyKeyIfEmpty - checks if the sticky key is nil in the vault and if so generates a new one.
|
||||
func (vault *Vault) setFeatureFlagStickyKeyIfEmpty() error {
|
||||
if vault.getSafe().FeatureFlagStickyKey != uuid.Nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return vault.modSafe(func(data *Data) {
|
||||
data.FeatureFlagStickyKey = uuid.New()
|
||||
})
|
||||
}
|
||||
|
||||
func (vault *Vault) getUsers() ([]*User, error) {
|
||||
vault.lock.Lock()
|
||||
defer vault.lock.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user