From 22e3febb45564a06bee782e1b97042db3e7bf6a9 Mon Sep 17 00:00:00 2001 From: Max Lerebourg Date: Mon, 5 Dec 2022 08:15:47 +0100 Subject: [PATCH] :lipstick: fix lint --- pkg/configuration/configuration.go | 19 +++++++++++-------- pkg/configuration/configuration_test.go | 8 ++++---- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/pkg/configuration/configuration.go b/pkg/configuration/configuration.go index 8b859f3..747b887 100644 --- a/pkg/configuration/configuration.go +++ b/pkg/configuration/configuration.go @@ -17,9 +17,11 @@ import ( // Enums for crowdsec mode. const ( - StreamMode = "stream" - LiveMode = "live" - NoneMode = "none" + StreamMode = "stream" + LiveMode = "live" + NoneMode = "none" + Https = "https" + Http = "http" ) // Config the plugin configuration. @@ -62,7 +64,7 @@ func New() *Config { Enabled: false, LogLevel: "INFO", CrowdsecMode: LiveMode, - CrowdsecLapiScheme: "http", + CrowdsecLapiScheme: Http, CrowdsecLapiHost: "crowdsec:8080", CrowdsecLapiKey: "", CrowdsecLapiTLSInsecureVerify: false, @@ -143,7 +145,7 @@ func ValidateParams(config *Config) error { } // 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) if err != nil { return err @@ -203,17 +205,18 @@ func validateParamsRequired(config *Config) error { if !contains([]string{NoneMode, LiveMode, StreamMode}, config.CrowdsecMode) { 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 nil } +// GetTLSConfigCrowdsec get TLS config from Config func GetTLSConfigCrowdsec(config *Config) (*tls.Config, error) { tlsConfig := new(tls.Config) tlsConfig.RootCAs = x509.NewCertPool() //nolint:gocritic - if config.CrowdsecLapiScheme != "https" { + if config.CrowdsecLapiScheme != Https { logger.Debug("getTLSConfigCrowdsec:CrowdsecLapiScheme not https") return tlsConfig, nil } else if config.CrowdsecLapiTLSInsecureVerify { @@ -253,4 +256,4 @@ func GetTLSConfigCrowdsec(config *Config) (*tls.Config, error) { tlsConfig.Certificates = append(tlsConfig.Certificates, clientCert) return tlsConfig, nil -} \ No newline at end of file +} diff --git a/pkg/configuration/configuration_test.go b/pkg/configuration/configuration_test.go index f91d394..a72de77 100644 --- a/pkg/configuration/configuration_test.go +++ b/pkg/configuration/configuration_test.go @@ -2,8 +2,8 @@ package configuration import ( "crypto/tls" - "testing" "reflect" + "testing" ) func getMinimalConfig() *Config { @@ -45,7 +45,7 @@ func Test_GetVariable(t *testing.T) { config *Config key string } - tests := []struct{ + tests := []struct { name string args args want string @@ -77,10 +77,10 @@ func Test_ValidateParams(t *testing.T) { cfg5 := getMinimalConfig() cfg5.ClientTrustedIPs = []string{0: "bad"} cfg6 := getMinimalConfig() - cfg6.CrowdsecLapiScheme = "https" + cfg6.CrowdsecLapiScheme = Https cfg6.CrowdsecLapiTLSInsecureVerify = true cfg8 := getMinimalConfig() - cfg8.CrowdsecLapiScheme = "https" + cfg8.CrowdsecLapiScheme = Https type args struct { config *Config }