diff options
-rw-r--r-- | pkg/atlas/config.go | 12 | ||||
-rw-r--r-- | pkg/atlas/server.go | 52 |
2 files changed, 52 insertions, 12 deletions
diff --git a/pkg/atlas/config.go b/pkg/atlas/config.go index 2829fce..05bd2a6 100644 --- a/pkg/atlas/config.go +++ b/pkg/atlas/config.go @@ -194,6 +194,18 @@ type Config struct { // restarts. Highly recommended. OriginPersist string `env:"ATLAS_ORIGIN_PERSIST"` + // Override the EAX EA App version. If specified, updates will not be + // checked automatically. + EAXUpdateVersion string `env:"EAX_UPDATE_VERSION"` + + // EAXUpdateInterval is the min interval at which to check for EA App + // updates. + EAXUpdateInterval time.Duration `env:"EAX_UPDATE_INTERVAL=24h"` + + // EAXUpdateBucket is the update bucket to use when checking for EA App + // updates. + EAXUpdateBucket int `env:"EAX_UPDATE_BUCKET=0"` + // Secret token for accessing internal metrics. If it begins with @, it is // treated as the name of a systemd credential to load. MetricsSecret string `env:"ATLAS_METRICS_SECRET" sdcreds:"load,trimspace"` diff --git a/pkg/atlas/server.go b/pkg/atlas/server.go index 40d2abf..8b32978 100644 --- a/pkg/atlas/server.go +++ b/pkg/atlas/server.go @@ -26,6 +26,7 @@ import ( "github.com/r2northstar/atlas/db/pdatadb" "github.com/r2northstar/atlas/pkg/api/api0" "github.com/r2northstar/atlas/pkg/cloudflare" + "github.com/r2northstar/atlas/pkg/eax" "github.com/r2northstar/atlas/pkg/memstore" "github.com/r2northstar/atlas/pkg/origin" "github.com/r2northstar/atlas/pkg/regionmap" @@ -299,6 +300,11 @@ func NewServer(c *Config) (*Server, error) { } else { return nil, fmt.Errorf("initialize origin auth: %w", err) } + if exc, err := configureEAX(c, s.Logger.With().Str("component", "eax").Logger()); err == nil { + s.API0.EAXClient = exc + } else { + return nil, fmt.Errorf("initialize eax: %w", err) + } if x, err := configureUsernameSource(c); err == nil { s.API0.UsernameSource = x } else { @@ -496,18 +502,7 @@ func configureOrigin(c *Config, l zerolog.Logger) (*origin.AuthMgr, error) { Credentials: func() (email, password, otpsecret string, err error) { return c.OriginEmail, c.OriginPassword, c.OriginTOTP, nil }, - Backoff: func(_ error, last time.Time, count int) bool { - var hmax, hmaxat, hrate float64 = 24, 8, 2.3 - // ~5m, ~10m, ~23m, ~52m, ~2h, ~4.6h, ~10.5h, 24h - - var next float64 - if count >= int(hmaxat) { - next = hmax - } else { - next = math.Pow(hrate, float64(count)) * hmax / math.Pow(hrate, hmaxat) - } - return time.Since(last).Hours() >= next - }, + Backoff: expbackoff, Updated: func(as origin.AuthState, err error) { mu.Lock() defer mu.Unlock() @@ -615,6 +610,39 @@ func configureOrigin(c *Config, l zerolog.Logger) (*origin.AuthMgr, error) { return mgr, nil } +func configureEAX(c *Config, l zerolog.Logger) (*eax.Client, error) { + mgr := &eax.UpdateMgr{ + AutoUpdateBackoff: expbackoff, + AutoUpdateHook: func(ver string, err error) { + if err != nil { + l.Err(err).Msg("eax update error") + } + }, + } + if v := c.EAXUpdateVersion; v != "" { + mgr.SetVersion(v) + } else { + mgr.AutoUpdateInterval = c.EAXUpdateInterval + mgr.AutoUpdateBucket = c.EAXUpdateBucket + } + return &eax.Client{ + UpdateMgr: mgr, + }, nil +} + +func expbackoff(_ error, last time.Time, count int) bool { + var hmax, hmaxat, hrate float64 = 24, 8, 2.3 + // ~5m, ~10m, ~23m, ~52m, ~2h, ~4.6h, ~10.5h, 24h + + var next float64 + if count >= int(hmaxat) { + next = hmax + } else { + next = math.Pow(hrate, float64(count)) * hmax / math.Pow(hrate, hmaxat) + } + return time.Since(last).Hours() >= next +} + func configureUsernameSource(c *Config) (api0.UsernameSource, error) { switch typ := c.UsernameSource; typ { case "none": |