internal: fix race conditions when accessing settings before bootstrap
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
@ -9,7 +9,6 @@ import (
|
||||
"strings"
|
||||
|
||||
env "github.com/Netflix/go-env"
|
||||
"github.com/imdario/mergo"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
@ -18,8 +17,9 @@ var cfg *Config
|
||||
|
||||
func Get() *Config {
|
||||
if cfg == nil {
|
||||
cfg = defaultConfig()
|
||||
cfg.Setup()
|
||||
c := defaultConfig()
|
||||
c.Setup()
|
||||
cfg = c
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
@ -28,10 +28,12 @@ func defaultConfig() *Config {
|
||||
return &Config{
|
||||
Debug: false,
|
||||
Listen: ListenConfig{
|
||||
HTTP: "localhost:9000",
|
||||
HTTPS: "localhost:9443",
|
||||
LDAP: "localhost:3389",
|
||||
LDAPS: "localhost:6636",
|
||||
HTTP: "0.0.0.0:9000",
|
||||
HTTPS: "0.0.0.0:9443",
|
||||
LDAP: "0.0.0.0:3389",
|
||||
LDAPS: "0.0.0.0:6636",
|
||||
Metrics: "0.0.0.0:9300",
|
||||
Debug: "0.0.0.0:9900",
|
||||
},
|
||||
Paths: PathsConfig{
|
||||
Media: "./media",
|
||||
@ -64,28 +66,20 @@ func (c *Config) LoadConfig(path string) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to load config file: %w", err)
|
||||
}
|
||||
nc := Config{}
|
||||
err = yaml.Unmarshal(raw, &nc)
|
||||
err = yaml.Unmarshal(raw, c)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to parse YAML: %w", err)
|
||||
}
|
||||
if err := mergo.Merge(c, nc, mergo.WithOverride); err != nil {
|
||||
return fmt.Errorf("failed to overlay config: %w", err)
|
||||
}
|
||||
c.walkScheme(c)
|
||||
log.WithField("path", path).Debug("Loaded config")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Config) fromEnv() error {
|
||||
nc := Config{}
|
||||
_, err := env.UnmarshalFromEnviron(&nc)
|
||||
_, err := env.UnmarshalFromEnviron(c)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to load environment variables: %w", err)
|
||||
}
|
||||
if err := mergo.Merge(c, nc, mergo.WithOverride); err != nil {
|
||||
return fmt.Errorf("failed to overlay config: %w", err)
|
||||
}
|
||||
c.walkScheme(c)
|
||||
log.Debug("Loaded config from environment")
|
||||
return nil
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
package config
|
||||
|
||||
type Config struct {
|
||||
Debug bool `yaml:"debug" env:"AUTHENTIK_DEBUG"`
|
||||
SecretKey string `yaml:"secret_key" env:"AUTHENTIK_SECRET_KEY"`
|
||||
Listen ListenConfig `yaml:"listen"`
|
||||
Paths PathsConfig `yaml:"paths"`
|
||||
LogLevel string `yaml:"log_level" env:"AUTHENTIK_LOG_LEVEL"`
|
||||
ErrorReporting ErrorReportingConfig `yaml:"error_reporting"`
|
||||
Redis RedisConfig `yaml:"redis"`
|
||||
DisableEmbeddedOutpost bool `yaml:"disable_embedded_outpost" env:"AUTHENTIK_WEB__DISABLE_EMBEDDED_OUTPOST"`
|
||||
Debug bool `yaml:"debug" env:"AUTHENTIK_DEBUG"`
|
||||
SecretKey string `yaml:"secret_key" env:"AUTHENTIK_SECRET_KEY"`
|
||||
Listen ListenConfig `yaml:"listen"`
|
||||
Paths PathsConfig `yaml:"paths"`
|
||||
LogLevel string `yaml:"log_level" env:"AUTHENTIK_LOG_LEVEL"`
|
||||
ErrorReporting ErrorReportingConfig `yaml:"error_reporting"`
|
||||
Redis RedisConfig `yaml:"redis"`
|
||||
Outposts OutpostConfig `yaml:"outposts" `
|
||||
}
|
||||
|
||||
type RedisConfig struct {
|
||||
@ -30,10 +30,10 @@ type RedisConfig struct {
|
||||
type ListenConfig struct {
|
||||
HTTP string `yaml:"listen_http" env:"AUTHENTIK_LISTEN__HTTP"`
|
||||
HTTPS string `yaml:"listen_https" env:"AUTHENTIK_LISTEN__HTTPS"`
|
||||
LDAP string `yaml:"listen_ldap" env:"AUTHENTIK_LISTEN__LDAP,default=0.0.0.0:3389"`
|
||||
LDAPS string `yaml:"listen_ldaps" env:"AUTHENTIK_LISTEN__LDAPS,default=0.0.0.0:6636"`
|
||||
Metrics string `yaml:"listen_metrics" env:"AUTHENTIK_LISTEN__METRICS,default=0.0.0.0:9300"`
|
||||
Debug string `yaml:"listen_debug" env:"AUTHENTIK_LISTEN__DEBUG,default=0.0.0.0:9900"`
|
||||
LDAP string `yaml:"listen_ldap" env:"AUTHENTIK_LISTEN__LDAP"`
|
||||
LDAPS string `yaml:"listen_ldaps" env:"AUTHENTIK_LISTEN__LDAPS"`
|
||||
Metrics string `yaml:"listen_metrics" env:"AUTHENTIK_LISTEN__METRICS"`
|
||||
Debug string `yaml:"listen_debug" env:"AUTHENTIK_LISTEN__DEBUG"`
|
||||
}
|
||||
|
||||
type PathsConfig struct {
|
||||
@ -47,3 +47,9 @@ type ErrorReportingConfig struct {
|
||||
DSN string
|
||||
SampleRate float64 `yaml:"sample_rate" env:"AUTHENTIK_ERROR_REPORTING__SAMPLE_RATE"`
|
||||
}
|
||||
|
||||
type OutpostConfig struct {
|
||||
ContainerImageBase string `yaml:"container_image_base" env:"AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE"`
|
||||
Discover bool `yaml:"discover" env:"AUTHENTIK_OUTPOSTS__DISCOVER"`
|
||||
DisableEmbeddedOutpost bool `yaml:"disable_embedded_outpost" env:"AUTHENTIK_OUTPOSTS__DISABLE_EMBEDDED_OUTPOST"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user