Manager: simplify config processing
This commit is contained in:
parent
0284dc4e4d
commit
f61522f396
@ -182,12 +182,7 @@ func getConf() (Conf, error) {
|
|||||||
func DefaultConfig(override ...func(c *Conf)) Conf {
|
func DefaultConfig(override ...func(c *Conf)) Conf {
|
||||||
c := defaultConfig
|
c := defaultConfig
|
||||||
c.Meta.Version = latestConfigVersion
|
c.Meta.Version = latestConfigVersion
|
||||||
for _, overrideFunc := range override {
|
c.processAfterLoading(override...)
|
||||||
overrideFunc(&c)
|
|
||||||
}
|
|
||||||
c.addImplicitVariables()
|
|
||||||
c.ensureVariablesUnique()
|
|
||||||
c.constructVariableLookupTable(zerolog.TraceLevel)
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,19 +220,26 @@ func loadConf(filename string, overrides ...func(c *Conf)) (Conf, error) {
|
|||||||
return c, fmt.Errorf("unable to parse %s: %w", filename, err)
|
return c, fmt.Errorf("unable to parse %s: %w", filename, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, overrideFunc := range overrides {
|
c.processAfterLoading(overrides...)
|
||||||
overrideFunc(&c)
|
|
||||||
|
return c, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// processAfterLoading processes and checks the loaded config.
|
||||||
|
// This is called not just after loading from disk, but also after getting the
|
||||||
|
// default configuration.
|
||||||
|
func (c *Conf) processAfterLoading(override ...func(c *Conf)) {
|
||||||
|
for _, overrideFunc := range override {
|
||||||
|
overrideFunc(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.addImplicitVariables()
|
c.addImplicitVariables()
|
||||||
c.ensureVariablesUnique()
|
c.ensureVariablesUnique()
|
||||||
c.constructVariableLookupTable(zerolog.DebugLevel)
|
c.constructVariableLookupTable()
|
||||||
c.parseURLs()
|
c.parseURLs()
|
||||||
c.checkDatabase()
|
c.checkDatabase()
|
||||||
c.checkVariables()
|
c.checkVariables()
|
||||||
c.checkTLS()
|
c.checkTLS()
|
||||||
|
|
||||||
return c, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conf) addImplicitVariables() {
|
func (c *Conf) addImplicitVariables() {
|
||||||
@ -280,20 +282,20 @@ func (c *Conf) ensureVariablesUnique() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conf) constructVariableLookupTable(logLevel zerolog.Level) {
|
func (c *Conf) constructVariableLookupTable() {
|
||||||
if c.VariablesLookup == nil {
|
if c.VariablesLookup == nil {
|
||||||
c.VariablesLookup = map[VariableAudience]map[VariablePlatform]map[string]string{}
|
c.VariablesLookup = map[VariableAudience]map[VariablePlatform]map[string]string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.constructVariableLookupTableForVars(logLevel, c.Variables)
|
c.constructVariableLookupTableForVars(c.Variables)
|
||||||
c.constructVariableLookupTableForVars(logLevel, c.implicitVariables)
|
c.constructVariableLookupTableForVars(c.implicitVariables)
|
||||||
|
|
||||||
log.Trace().
|
log.Trace().
|
||||||
Interface("variables", c.Variables).
|
Interface("variables", c.Variables).
|
||||||
Msg("constructed lookup table")
|
Msg("constructed lookup table")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conf) constructVariableLookupTableForVars(logLevel zerolog.Level, vars map[string]Variable) {
|
func (c *Conf) constructVariableLookupTableForVars(vars map[string]Variable) {
|
||||||
// Construct a list of all audiences except "" and "all"
|
// Construct a list of all audiences except "" and "all"
|
||||||
concreteAudiences := []VariableAudience{}
|
concreteAudiences := []VariableAudience{}
|
||||||
isWildcard := map[VariableAudience]bool{"": true, VariableAudienceAll: true}
|
isWildcard := map[VariableAudience]bool{"": true, VariableAudienceAll: true}
|
||||||
@ -338,7 +340,7 @@ func (c *Conf) constructVariableLookupTableForVars(logLevel zerolog.Level, vars
|
|||||||
|
|
||||||
// Construct the lookup table for each audience+platform+name
|
// Construct the lookup table for each audience+platform+name
|
||||||
for name, variable := range vars {
|
for name, variable := range vars {
|
||||||
log.WithLevel(logLevel).
|
log.Trace().
|
||||||
Str("name", name).
|
Str("name", name).
|
||||||
Interface("variable", variable).
|
Interface("variable", variable).
|
||||||
Msg("handling variable")
|
Msg("handling variable")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user