diff --git a/.golangci.yml b/.golangci.yml index ed57d67..78dd020 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -15,7 +15,7 @@ linters-settings: locale: US funlen: lines: -1 - statements: 50 + statements: 60 godox: keywords: - FIXME diff --git a/bouncer.go b/bouncer.go index 20dbc3f..f0af205 100644 --- a/bouncer.go +++ b/bouncer.go @@ -93,6 +93,7 @@ type Bouncer struct { // New creates the crowdsec bouncer plugin. func New(_ context.Context, next http.Handler, config *configuration.Config, name string) (http.Handler, error) { + config.LogLevel = strings.ToUpper(config.LogLevel) log := logger.New(config.LogLevel, config.LogFilePath) err := configuration.ValidateParams(config) if err != nil { diff --git a/pkg/configuration/configuration.go b/pkg/configuration/configuration.go index cdc0d04..483e8a2 100644 --- a/pkg/configuration/configuration.go +++ b/pkg/configuration/configuration.go @@ -268,8 +268,8 @@ func ValidateParams(config *Config) error { } // Check logging configuration - - if !contains([]string{LogERROR, LogDEBUG, LogINFO}, config.LogLevel) { + // to upper allow of anycase of log level + if !contains([]string{LogERROR, LogDEBUG, LogINFO}, strings.ToUpper(config.LogLevel)) { return fmt.Errorf("LogLevel should be one of (%s,%s,%s)", LogDEBUG, LogINFO, LogERROR) } if config.LogFilePath != "" { diff --git a/pkg/configuration/configuration_test.go b/pkg/configuration/configuration_test.go index 9263e26..cc8885a 100644 --- a/pkg/configuration/configuration_test.go +++ b/pkg/configuration/configuration_test.go @@ -85,8 +85,14 @@ func Test_ValidateParams(t *testing.T) { cfg6 := getMinimalConfig() cfg6.CrowdsecLapiScheme = HTTPS cfg6.CrowdsecLapiTLSInsecureVerify = true + cfg7 := getMinimalConfig() + cfg7.CrowdsecLapiScheme = HTTPS cfg8 := getMinimalConfig() - cfg8.CrowdsecLapiScheme = HTTPS + cfg8.LogLevel = LogINFO + cfg9 := getMinimalConfig() + cfg9.LogLevel = "info" + cfg10 := getMinimalConfig() + cfg10.LogLevel = "Warning" type args struct { config *Config } @@ -104,7 +110,10 @@ func Test_ValidateParams(t *testing.T) { {name: "Not validate a bad clients ips", args: args{config: cfg5}, wantErr: true}, // HTTPS enabled {name: "Validate https config with insecure verify", args: args{config: cfg6}, wantErr: false}, - {name: "Not validate https without cert authority", args: args{config: cfg8}, wantErr: true}, + {name: "Not validate https without cert authority", args: args{config: cfg7}, wantErr: true}, + {name: "Valid log level uppercase INFO", args: args{config: cfg8}, wantErr: false}, + {name: "Valid log level lowercase info", args: args{config: cfg9}, wantErr: false}, + {name: "Invalid log level Warning", args: args{config: cfg10}, wantErr: true}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {