mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
3c81e75d79
This adds an access-control command that checks the policy enforcement for a given criteria using a configuration file and refactors the configuration validation command to include all configuration sources.
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package validator
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/authelia/authelia/v4/internal/configuration/schema"
|
|
"github.com/authelia/authelia/v4/internal/utils"
|
|
)
|
|
|
|
// ValidateRegulation validates and update regulator configuration.
|
|
func ValidateRegulation(config *schema.Configuration, validator *schema.StructValidator) {
|
|
if config.Regulation == nil {
|
|
config.Regulation = &schema.DefaultRegulationConfiguration
|
|
|
|
return
|
|
}
|
|
|
|
if config.Regulation.FindTime == "" {
|
|
config.Regulation.FindTime = schema.DefaultRegulationConfiguration.FindTime // 2 min.
|
|
}
|
|
|
|
if config.Regulation.BanTime == "" {
|
|
config.Regulation.BanTime = schema.DefaultRegulationConfiguration.BanTime // 5 min.
|
|
}
|
|
|
|
findTime, err := utils.ParseDurationString(config.Regulation.FindTime)
|
|
if err != nil {
|
|
validator.Push(fmt.Errorf(errFmtRegulationParseDuration, "find_time", err))
|
|
}
|
|
|
|
banTime, err := utils.ParseDurationString(config.Regulation.BanTime)
|
|
if err != nil {
|
|
validator.Push(fmt.Errorf(errFmtRegulationParseDuration, "ban_time", err))
|
|
}
|
|
|
|
if findTime > banTime {
|
|
validator.Push(fmt.Errorf(errFmtRegulationFindTimeGreaterThanBanTime))
|
|
}
|
|
}
|