/
ntp.go
28 lines (22 loc) · 918 Bytes
/
ntp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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 == nil {
config.NTP.Address = schema.DefaultNTPConfiguration.Address
}
if !config.NTP.Address.IsUDP() {
validator.Push(fmt.Errorf(errFmtNTPAddressScheme, config.NTP.Address.String(), fmt.Errorf("scheme must be one of 'udp', 'udp4', or 'udp6' but is configured as '%s'", config.NTP.Address.Scheme())))
}
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
}
}