Add check to load param

This commit is contained in:
MathieuHa
2022-11-17 09:21:57 +01:00
parent c1f2131bc2
commit d2f0a9416d
6 changed files with 14 additions and 574 deletions
+10 -2
View File
@@ -53,7 +53,7 @@ type Config struct {
func CreateConfig() *Config {
return &Config{
Enabled: false,
LogLevel: "INFO",
LogLevel: "DEBUG",
CrowdsecMode: liveMode,
CrowdsecLapiScheme: "http",
CrowdsecLapiHost: "crowdsec:8080",
@@ -98,7 +98,7 @@ func New(ctx context.Context, next http.Handler, config *Config, name string) (h
}
checker, _ := ip.NewChecker(config.ForwardedHeadersTrustedIPs)
checkerTrusted, _ := ip.NewChecker(config.TrustedIPs)
checkerTrusted, err := ip.NewChecker(config.TrustedIPs)
bouncer := &Bouncer{
next: next,
@@ -401,6 +401,14 @@ func validateParams(config *Config) error {
} else {
logger.Debug("No IP provided for ForwardedHeadersTrustedIPs")
}
if len(config.TrustedIPs) > 0 {
_, err = ip.NewChecker(config.TrustedIPs)
if err != nil {
return fmt.Errorf("TrustedIPs must be a list of IP/CIDR :%w", err)
}
} else {
logger.Debug("No IP provided for TrustedIPs")
}
return nil
}