Files
kor-elf-shield/internal/setting/analyzer/analyzer.go
T
kor-elf b49889ef58 Add brute force protection to analyzer settings
- Introduced `BruteForceProtection` structure with validation and default settings.
- Integrated brute force protection logic into `Setting` methods for initialization, validation, and source generation.
- Added group-based brute force rate-limiting functionality with `_default` group included.
2026-02-25 23:57:33 +05:00

81 lines
1.7 KiB
Go

package analyzer
import (
"git.kor-elf.net/kor-elf-shield/kor-elf-shield/internal/daemon/analyzer/config"
"git.kor-elf.net/kor-elf-shield/kor-elf-shield/internal/setting/validate"
"github.com/spf13/viper"
)
type Setting struct {
Login Login
LogAlert LogAlert
BruteForceProtection BruteForceProtection
}
func InitSetting(path string) (Setting, error) {
if err := validate.IsTomlFile(path, "otherSettingsPath.analyzer"); err != nil {
return Setting{}, err
}
setting := settingDefault()
v := viper.New()
v.SetConfigType("toml")
v.SetConfigFile(path)
if err := v.ReadInConfig(); err != nil {
return Setting{}, err
}
if err := v.Unmarshal(&setting); err != nil {
return Setting{}, err
}
return setting, nil
}
func settingDefault() Setting {
return Setting{
Login: defaultLogin(),
LogAlert: defaultLogAlert(),
BruteForceProtection: defaultBruteForceProtection(),
}
}
func (s Setting) ToSources() ([]*config.Source, error) {
var sources []*config.Source
loginSources, err := s.Login.ToSources()
if err != nil {
return sources, err
}
sources = append(sources, loginSources...)
alertSources, err := s.LogAlert.ToSources()
if err != nil {
return sources, err
}
sources = append(sources, alertSources...)
bruteForceSources, err := s.BruteForceProtection.ToSources()
if err != nil {
return sources, err
}
sources = append(sources, bruteForceSources...)
return sources, nil
}
func (s Setting) Validate() error {
if err := s.Login.Validate(); err != nil {
return err
}
if err := s.LogAlert.Validate(); err != nil {
return err
}
if err := s.BruteForceProtection.Validate(); err != nil {
return err
}
return nil
}