From 53485916a559f026c3126b4104c96b01b8a460e2 Mon Sep 17 00:00:00 2001 From: marco Date: Tue, 14 Jan 2025 15:44:28 +0100 Subject: [PATCH] lint: gocritic/typeDefFirst (ensure type definitions come before methods) --- .golangci.yml | 1 - cmd/crowdsec-cli/clialert/alerts.go | 14 +++--- cmd/crowdsec-cli/clidecision/decisions.go | 14 +++--- cmd/crowdsec-cli/clisupport/support.go | 12 ++--- pkg/csconfig/api.go | 60 +++++++++++------------ 5 files changed, 50 insertions(+), 51 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index b3be5adb687..3afa4571b10 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -213,7 +213,6 @@ linters-settings: gocritic: enable-all: true disabled-checks: - - typeDefFirst - paramTypeCombine - httpNoBody - ifElseChain diff --git a/cmd/crowdsec-cli/clialert/alerts.go b/cmd/crowdsec-cli/clialert/alerts.go index 4ae72919a9e..891a720d169 100644 --- a/cmd/crowdsec-cli/clialert/alerts.go +++ b/cmd/crowdsec-cli/clialert/alerts.go @@ -29,6 +29,13 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/types" ) +type configGetter func() *csconfig.Config + +type cliAlerts struct { + client *apiclient.ApiClient + cfg configGetter +} + func decisionsFromAlert(alert *models.Alert) string { ret := "" decMap := make(map[string]int) @@ -183,13 +190,6 @@ func (cli *cliAlerts) displayOneAlert(alert *models.Alert, withDetail bool) erro return nil } -type configGetter func() *csconfig.Config - -type cliAlerts struct { - client *apiclient.ApiClient - cfg configGetter -} - func New(getconfig configGetter) *cliAlerts { return &cliAlerts{ cfg: getconfig, diff --git a/cmd/crowdsec-cli/clidecision/decisions.go b/cmd/crowdsec-cli/clidecision/decisions.go index b5865bab6e0..e7b7c5f084a 100644 --- a/cmd/crowdsec-cli/clidecision/decisions.go +++ b/cmd/crowdsec-cli/clidecision/decisions.go @@ -24,6 +24,13 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/types" ) +type configGetter func() *csconfig.Config + +type cliDecisions struct { + client *apiclient.ApiClient + cfg configGetter +} + func (cli *cliDecisions) decisionsToTable(alerts *models.GetAlertsResponse, printMachine bool) error { /*here we cheat a bit : to make it more readable for the user, we dedup some entries*/ spamLimit := make(map[string]bool) @@ -115,13 +122,6 @@ func (cli *cliDecisions) decisionsToTable(alerts *models.GetAlertsResponse, prin return nil } -type configGetter func() *csconfig.Config - -type cliDecisions struct { - client *apiclient.ApiClient - cfg configGetter -} - func New(cfg configGetter) *cliDecisions { return &cliDecisions{ cfg: cfg, diff --git a/cmd/crowdsec-cli/clisupport/support.go b/cmd/crowdsec-cli/clisupport/support.go index eb3e03df253..ed52e3792f0 100644 --- a/cmd/crowdsec-cli/clisupport/support.go +++ b/cmd/crowdsec-cli/clisupport/support.go @@ -85,6 +85,12 @@ func stripAnsiString(str string) string { return reStripAnsi.ReplaceAllString(str, "") } +type configGetter func() *csconfig.Config + +type cliSupport struct { + cfg configGetter +} + func (cli *cliSupport) dumpMetrics(ctx context.Context, db *database.Client, zw *zip.Writer) error { log.Info("Collecting prometheus metrics") @@ -393,12 +399,6 @@ func (cli *cliSupport) dumpCrash(zw *zip.Writer) error { return nil } -type configGetter func() *csconfig.Config - -type cliSupport struct { - cfg configGetter -} - func New(cfg configGetter) *cliSupport { return &cliSupport{ cfg: cfg, diff --git a/pkg/csconfig/api.go b/pkg/csconfig/api.go index d94d90aaf19..8aa99686c2a 100644 --- a/pkg/csconfig/api.go +++ b/pkg/csconfig/api.go @@ -209,6 +209,36 @@ func (l *LocalApiClientCfg) Load() error { return nil } +/*local api service configuration*/ +type LocalApiServerCfg struct { + Enable *bool `yaml:"enable"` + ListenURI string `yaml:"listen_uri,omitempty"` // 127.0.0.1:8080 + ListenSocket string `yaml:"listen_socket,omitempty"` + TLS *TLSCfg `yaml:"tls"` + DbConfig *DatabaseCfg `yaml:"-"` + LogDir string `yaml:"-"` + LogMedia string `yaml:"-"` + OnlineClient *OnlineApiClientCfg `yaml:"online_client"` + ProfilesPath string `yaml:"profiles_path,omitempty"` + ConsoleConfigPath string `yaml:"console_path,omitempty"` + ConsoleConfig *ConsoleConfig `yaml:"-"` + Profiles []*ProfileCfg `yaml:"-"` + LogLevel *log.Level `yaml:"log_level"` + UseForwardedForHeaders bool `yaml:"use_forwarded_for_headers,omitempty"` + TrustedProxies *[]string `yaml:"trusted_proxies,omitempty"` + CompressLogs *bool `yaml:"-"` + LogMaxSize int `yaml:"-"` + LogMaxAge int `yaml:"-"` + LogMaxFiles int `yaml:"-"` + LogFormat string `yaml:"-"` + TrustedIPs []string `yaml:"trusted_ips,omitempty"` + PapiLogLevel *log.Level `yaml:"papi_log_level"` + DisableRemoteLapiRegistration bool `yaml:"disable_remote_lapi_registration,omitempty"` + CapiWhitelistsPath string `yaml:"capi_whitelists_path,omitempty"` + CapiWhitelists *CapiWhitelist `yaml:"-"` + AutoRegister *LocalAPIAutoRegisterCfg `yaml:"auto_registration,omitempty"` +} + func (c *LocalApiServerCfg) GetTrustedIPs() ([]net.IPNet, error) { trustedIPs := make([]net.IPNet, 0) @@ -250,36 +280,6 @@ type LocalAPIAutoRegisterCfg struct { AllowedRangesParsed []*net.IPNet `yaml:"-"` } -/*local api service configuration*/ -type LocalApiServerCfg struct { - Enable *bool `yaml:"enable"` - ListenURI string `yaml:"listen_uri,omitempty"` // 127.0.0.1:8080 - ListenSocket string `yaml:"listen_socket,omitempty"` - TLS *TLSCfg `yaml:"tls"` - DbConfig *DatabaseCfg `yaml:"-"` - LogDir string `yaml:"-"` - LogMedia string `yaml:"-"` - OnlineClient *OnlineApiClientCfg `yaml:"online_client"` - ProfilesPath string `yaml:"profiles_path,omitempty"` - ConsoleConfigPath string `yaml:"console_path,omitempty"` - ConsoleConfig *ConsoleConfig `yaml:"-"` - Profiles []*ProfileCfg `yaml:"-"` - LogLevel *log.Level `yaml:"log_level"` - UseForwardedForHeaders bool `yaml:"use_forwarded_for_headers,omitempty"` - TrustedProxies *[]string `yaml:"trusted_proxies,omitempty"` - CompressLogs *bool `yaml:"-"` - LogMaxSize int `yaml:"-"` - LogMaxAge int `yaml:"-"` - LogMaxFiles int `yaml:"-"` - LogFormat string `yaml:"-"` - TrustedIPs []string `yaml:"trusted_ips,omitempty"` - PapiLogLevel *log.Level `yaml:"papi_log_level"` - DisableRemoteLapiRegistration bool `yaml:"disable_remote_lapi_registration,omitempty"` - CapiWhitelistsPath string `yaml:"capi_whitelists_path,omitempty"` - CapiWhitelists *CapiWhitelist `yaml:"-"` - AutoRegister *LocalAPIAutoRegisterCfg `yaml:"auto_registration,omitempty"` -} - func (c *LocalApiServerCfg) ClientURL() string { if c == nil { return ""