aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpg9182 <96569817+pg9182@users.noreply.github.com>2023-02-27 00:40:23 -0500
committerpg9182 <96569817+pg9182@users.noreply.github.com>2023-03-04 00:49:32 -0500
commitb0522c97465a3c0d49d2fe784a23e6fe8b908c6b (patch)
tree370d8e455724771669aa5dc0b2f507891b316d49
parentd704eaddcb833b14b5e18756925a47081b429163 (diff)
downloadAtlas-b0522c97465a3c0d49d2fe784a23e6fe8b908c6b.tar.gz
Atlas-b0522c97465a3c0d49d2fe784a23e6fe8b908c6b.zip
pkg/atlas: Add EAX client configuration
-rw-r--r--pkg/atlas/config.go12
-rw-r--r--pkg/atlas/server.go52
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":