2020-04-05 12:37:21 +00:00
|
|
|
package validator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2021-08-11 01:04:35 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/configuration/schema"
|
|
|
|
"github.com/authelia/authelia/v4/internal/utils"
|
2020-04-05 12:37:21 +00:00
|
|
|
)
|
|
|
|
|
2020-04-20 21:03:38 +00:00
|
|
|
// ValidateRegulation validates and update regulator configuration.
|
2020-04-05 12:37:21 +00:00
|
|
|
func ValidateRegulation(configuration *schema.RegulationConfiguration, validator *schema.StructValidator) {
|
|
|
|
if configuration.FindTime == "" {
|
2022-01-31 05:25:15 +00:00
|
|
|
configuration.FindTime = schema.DefaultRegulationConfiguration.FindTime // 2 min.
|
2020-04-05 12:37:21 +00:00
|
|
|
}
|
2020-05-05 19:35:32 +00:00
|
|
|
|
2020-04-05 12:37:21 +00:00
|
|
|
if configuration.BanTime == "" {
|
2022-01-31 05:25:15 +00:00
|
|
|
configuration.BanTime = schema.DefaultRegulationConfiguration.BanTime // 5 min.
|
2020-04-05 12:37:21 +00:00
|
|
|
}
|
2020-05-05 19:35:32 +00:00
|
|
|
|
2020-04-05 12:37:21 +00:00
|
|
|
findTime, err := utils.ParseDurationString(configuration.FindTime)
|
|
|
|
if err != nil {
|
2020-04-09 01:05:17 +00:00
|
|
|
validator.Push(fmt.Errorf("Error occurred parsing regulation find_time string: %s", err))
|
2020-04-05 12:37:21 +00:00
|
|
|
}
|
2020-05-05 19:35:32 +00:00
|
|
|
|
2020-04-05 12:37:21 +00:00
|
|
|
banTime, err := utils.ParseDurationString(configuration.BanTime)
|
|
|
|
if err != nil {
|
2020-04-09 01:05:17 +00:00
|
|
|
validator.Push(fmt.Errorf("Error occurred parsing regulation ban_time string: %s", err))
|
2020-04-05 12:37:21 +00:00
|
|
|
}
|
2020-05-05 19:35:32 +00:00
|
|
|
|
2020-04-05 12:37:21 +00:00
|
|
|
if findTime > banTime {
|
2020-04-09 01:05:17 +00:00
|
|
|
validator.Push(fmt.Errorf("find_time cannot be greater than ban_time"))
|
2020-04-05 12:37:21 +00:00
|
|
|
}
|
|
|
|
}
|