authelia/internal/configuration/validator/ntp.go
James Elliott 6276883f04
refactor(configuration): utilize time duration decode hook (#2938)
This enhances the existing time.Duration parser to allow multiple units, and implements a decode hook which can be used by koanf to decode string/integers into time.Durations as applicable.
2022-03-02 17:40:26 +11:00

25 lines
680 B
Go

package validator
import (
"fmt"
"github.com/authelia/authelia/v4/internal/configuration/schema"
)
// ValidateNTP validates and update NTP configuration.
func ValidateNTP(config *schema.Configuration, validator *schema.StructValidator) {
if config.NTP.Address == "" {
config.NTP.Address = schema.DefaultNTPConfiguration.Address
}
if config.NTP.Version == 0 {
config.NTP.Version = schema.DefaultNTPConfiguration.Version
} else if config.NTP.Version < 3 || config.NTP.Version > 4 {
validator.Push(fmt.Errorf(errFmtNTPVersion, config.NTP.Version))
}
if config.NTP.MaximumDesync == 0 {
config.NTP.MaximumDesync = schema.DefaultNTPConfiguration.MaximumDesync
}
}