fix(config): actually load threshold config (#696)
* fix(config): actually load threshold config Signed-off-by: Xe Iaso <me@xeiaso.net> * chore: spelling Signed-off-by: Xe Iaso <me@xeiaso.net> * test(lib): fix test failures Signed-off-by: Xe Iaso <me@xeiaso.net> --------- Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
parent
226cf36bf7
commit
7aa732c700
12 changed files with 201 additions and 30 deletions
|
|
@ -326,7 +326,7 @@ type fileConfig struct {
|
|||
Bots []BotOrImport `json:"bots"`
|
||||
DNSBL bool `json:"dnsbl"`
|
||||
StatusCodes StatusCodes `json:"status_codes"`
|
||||
Thresholds []Threshold `json:"threshold"`
|
||||
Thresholds []Threshold `json:"thresholds"`
|
||||
}
|
||||
|
||||
func (c *fileConfig) Valid() error {
|
||||
|
|
@ -346,10 +346,6 @@ func (c *fileConfig) Valid() error {
|
|||
errs = append(errs, err)
|
||||
}
|
||||
|
||||
if len(c.Thresholds) == 0 {
|
||||
errs = append(errs, ErrNoThresholdRulesDefined)
|
||||
}
|
||||
|
||||
for i, t := range c.Thresholds {
|
||||
if err := t.Valid(); err != nil {
|
||||
errs = append(errs, fmt.Errorf("threshold %d: %w", i, err))
|
||||
|
|
@ -369,7 +365,6 @@ func Load(fin io.Reader, fname string) (*Config, error) {
|
|||
Challenge: http.StatusOK,
|
||||
Deny: http.StatusOK,
|
||||
},
|
||||
Thresholds: DefaultThresholds,
|
||||
}
|
||||
|
||||
if err := yaml.NewYAMLToJSONDecoder(fin).Decode(&c); err != nil {
|
||||
|
|
@ -407,6 +402,10 @@ func Load(fin io.Reader, fname string) (*Config, error) {
|
|||
}
|
||||
}
|
||||
|
||||
if len(c.Thresholds) == 0 {
|
||||
c.Thresholds = DefaultThresholds
|
||||
}
|
||||
|
||||
for _, t := range c.Thresholds {
|
||||
if err := t.Valid(); err != nil {
|
||||
validationErrs = append(validationErrs, err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue