mirror of
https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin.git
synced 2026-07-21 11:38:59 +02:00
💄 fix lint
This commit is contained in:
@@ -20,6 +20,8 @@ const (
|
|||||||
StreamMode = "stream"
|
StreamMode = "stream"
|
||||||
LiveMode = "live"
|
LiveMode = "live"
|
||||||
NoneMode = "none"
|
NoneMode = "none"
|
||||||
|
Https = "https"
|
||||||
|
Http = "http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config the plugin configuration.
|
// Config the plugin configuration.
|
||||||
@@ -62,7 +64,7 @@ func New() *Config {
|
|||||||
Enabled: false,
|
Enabled: false,
|
||||||
LogLevel: "INFO",
|
LogLevel: "INFO",
|
||||||
CrowdsecMode: LiveMode,
|
CrowdsecMode: LiveMode,
|
||||||
CrowdsecLapiScheme: "http",
|
CrowdsecLapiScheme: Http,
|
||||||
CrowdsecLapiHost: "crowdsec:8080",
|
CrowdsecLapiHost: "crowdsec:8080",
|
||||||
CrowdsecLapiKey: "",
|
CrowdsecLapiKey: "",
|
||||||
CrowdsecLapiTLSInsecureVerify: false,
|
CrowdsecLapiTLSInsecureVerify: false,
|
||||||
@@ -143,7 +145,7 @@ func ValidateParams(config *Config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Case https to contact Crowdsec LAPI and certificate must be provided
|
// Case https to contact Crowdsec LAPI and certificate must be provided
|
||||||
if config.CrowdsecLapiScheme == "https" && !config.CrowdsecLapiTLSInsecureVerify {
|
if config.CrowdsecLapiScheme == Https && !config.CrowdsecLapiTLSInsecureVerify {
|
||||||
err = validateParamsTLS(config)
|
err = validateParamsTLS(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -203,17 +205,18 @@ func validateParamsRequired(config *Config) error {
|
|||||||
if !contains([]string{NoneMode, LiveMode, StreamMode}, config.CrowdsecMode) {
|
if !contains([]string{NoneMode, LiveMode, StreamMode}, config.CrowdsecMode) {
|
||||||
return fmt.Errorf("CrowdsecMode: must be one of 'none', 'live' or 'stream'")
|
return fmt.Errorf("CrowdsecMode: must be one of 'none', 'live' or 'stream'")
|
||||||
}
|
}
|
||||||
if !contains([]string{"http", "https"}, config.CrowdsecLapiScheme) {
|
if !contains([]string{Http, Https}, config.CrowdsecLapiScheme) {
|
||||||
return fmt.Errorf("CrowdsecLapiScheme: must be one of 'http' or 'https'")
|
return fmt.Errorf("CrowdsecLapiScheme: must be one of 'http' or 'https'")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetTLSConfigCrowdsec get TLS config from Config
|
||||||
func GetTLSConfigCrowdsec(config *Config) (*tls.Config, error) {
|
func GetTLSConfigCrowdsec(config *Config) (*tls.Config, error) {
|
||||||
tlsConfig := new(tls.Config)
|
tlsConfig := new(tls.Config)
|
||||||
tlsConfig.RootCAs = x509.NewCertPool()
|
tlsConfig.RootCAs = x509.NewCertPool()
|
||||||
//nolint:gocritic
|
//nolint:gocritic
|
||||||
if config.CrowdsecLapiScheme != "https" {
|
if config.CrowdsecLapiScheme != Https {
|
||||||
logger.Debug("getTLSConfigCrowdsec:CrowdsecLapiScheme not https")
|
logger.Debug("getTLSConfigCrowdsec:CrowdsecLapiScheme not https")
|
||||||
return tlsConfig, nil
|
return tlsConfig, nil
|
||||||
} else if config.CrowdsecLapiTLSInsecureVerify {
|
} else if config.CrowdsecLapiTLSInsecureVerify {
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package configuration
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"testing"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getMinimalConfig() *Config {
|
func getMinimalConfig() *Config {
|
||||||
@@ -45,7 +45,7 @@ func Test_GetVariable(t *testing.T) {
|
|||||||
config *Config
|
config *Config
|
||||||
key string
|
key string
|
||||||
}
|
}
|
||||||
tests := []struct{
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
args args
|
args args
|
||||||
want string
|
want string
|
||||||
@@ -77,10 +77,10 @@ func Test_ValidateParams(t *testing.T) {
|
|||||||
cfg5 := getMinimalConfig()
|
cfg5 := getMinimalConfig()
|
||||||
cfg5.ClientTrustedIPs = []string{0: "bad"}
|
cfg5.ClientTrustedIPs = []string{0: "bad"}
|
||||||
cfg6 := getMinimalConfig()
|
cfg6 := getMinimalConfig()
|
||||||
cfg6.CrowdsecLapiScheme = "https"
|
cfg6.CrowdsecLapiScheme = Https
|
||||||
cfg6.CrowdsecLapiTLSInsecureVerify = true
|
cfg6.CrowdsecLapiTLSInsecureVerify = true
|
||||||
cfg8 := getMinimalConfig()
|
cfg8 := getMinimalConfig()
|
||||||
cfg8.CrowdsecLapiScheme = "https"
|
cfg8.CrowdsecLapiScheme = Https
|
||||||
type args struct {
|
type args struct {
|
||||||
config *Config
|
config *Config
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user