Fix profile config parsing

This commit is contained in:
Daniel 2022-02-15 14:35:41 +01:00
parent 888b33918a
commit 3be1c78e16
3 changed files with 14 additions and 24 deletions

View file

@ -131,12 +131,8 @@ func (h *databaseHook) PrePut(r record.Record) (record.Record, error) {
// clean config
config.CleanHierarchicalConfig(profile.Config)
// prepare config
err = profile.prepConfig()
if err != nil {
// error here, warning when loading
return nil, err
}
// prepare profile
profile.prepProfile()
// parse config
err = profile.parseConfig()

View file

@ -178,11 +178,8 @@ func prepProfile(r record.Record) (*Profile, error) {
return nil, err
}
// prepare config
err = profile.prepConfig()
if err != nil {
log.Errorf("profiles: profile %s has (partly) invalid configuration: %s", profile.ID, err)
}
// prepare profile
profile.prepProfile()
// parse config
err = profile.parseConfig()

View file

@ -137,28 +137,27 @@ type Profile struct { //nolint:maligned // not worth the effort
savedInternally bool
}
func (profile *Profile) prepConfig() (err error) {
func (profile *Profile) prepProfile() {
// prepare configuration
profile.configPerspective, err = config.NewPerspective(profile.Config)
profile.outdated = abool.New()
profile.lastActive = new(int64)
return
}
func (profile *Profile) parseConfig() error {
if profile.configPerspective == nil {
return errors.New("config not prepared")
}
// check if already parsed
// Check if already parsed.
if profile.dataParsed {
return nil
}
// Create new perspective and marked as parsed.
var err error
profile.configPerspective, err = config.NewPerspective(profile.Config)
if err != nil {
return fmt.Errorf("failed to create config perspective: %w", err)
}
profile.dataParsed = true
var err error
var lastErr error
action, ok := profile.configPerspective.GetAsString(CfgOptionDefaultActionKey)
profile.defaultAction = DefaultActionNotSet
if ok {
@ -238,9 +237,7 @@ func New(
profile.makeKey()
// Prepare and parse initial profile config.
if err := profile.prepConfig(); err != nil {
log.Errorf("profile: failed to prep new profile: %s", err)
}
profile.prepProfile()
if err := profile.parseConfig(); err != nil {
log.Errorf("profile: failed to parse new profile: %s", err)
}