mirror of
https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin.git
synced 2025-11-08 15:15:05 +01:00
🔧 Add support for logLevel in any case (#231)
This commit is contained in:
@@ -15,7 +15,7 @@ linters-settings:
|
||||
locale: US
|
||||
funlen:
|
||||
lines: -1
|
||||
statements: 50
|
||||
statements: 60
|
||||
godox:
|
||||
keywords:
|
||||
- FIXME
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 != "" {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user