2020-04-05 19:37:21 +07:00
|
|
|
package validator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2021-08-11 08:04:35 +07:00
|
|
|
"github.com/authelia/authelia/v4/internal/configuration/schema"
|
2020-04-05 19:37:21 +07:00
|
|
|
)
|
|
|
|
|
2020-04-21 04:03:38 +07:00
|
|
|
// ValidateRegulation validates and update regulator configuration.
|
2022-02-28 10:15:01 +07:00
|
|
|
func ValidateRegulation(config *schema.Configuration, validator *schema.StructValidator) {
|
2022-03-02 13:40:26 +07:00
|
|
|
if config.Regulation.FindTime == 0 {
|
2022-02-28 10:15:01 +07:00
|
|
|
config.Regulation.FindTime = schema.DefaultRegulationConfiguration.FindTime // 2 min.
|
2020-04-05 19:37:21 +07:00
|
|
|
}
|
2020-05-06 02:35:32 +07:00
|
|
|
|
2022-03-02 13:40:26 +07:00
|
|
|
if config.Regulation.BanTime == 0 {
|
2022-02-28 10:15:01 +07:00
|
|
|
config.Regulation.BanTime = schema.DefaultRegulationConfiguration.BanTime // 5 min.
|
2020-04-05 19:37:21 +07:00
|
|
|
}
|
2020-05-06 02:35:32 +07:00
|
|
|
|
2022-03-02 13:40:26 +07:00
|
|
|
if config.Regulation.FindTime > config.Regulation.BanTime {
|
2022-02-28 10:15:01 +07:00
|
|
|
validator.Push(fmt.Errorf(errFmtRegulationFindTimeGreaterThanBanTime))
|
2020-04-05 19:37:21 +07:00
|
|
|
}
|
|
|
|
}
|