diff --git a/cmd/crowdsec-cli/clialert/alerts.go b/cmd/crowdsec-cli/clialert/alerts.go index c5e27394f77..757a84927e5 100644 --- a/cmd/crowdsec-cli/clialert/alerts.go +++ b/cmd/crowdsec-cli/clialert/alerts.go @@ -29,7 +29,7 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/types" ) -func DecisionsFromAlert(alert *models.Alert) string { +func decisionsFromAlert(alert *models.Alert) string { ret := "" decMap := make(map[string]int) @@ -77,7 +77,7 @@ func (cli *cliAlerts) alertsToTable(alerts *models.GetAlertsResponse, printMachi *alertItem.Scenario, alertItem.Source.Cn, alertItem.Source.GetAsNumberName(), - DecisionsFromAlert(alertItem), + decisionsFromAlert(alertItem), *alertItem.StartAt, } if printMachine { @@ -227,10 +227,10 @@ func (cli *cliAlerts) NewCommand() *cobra.Command { }, } - cmd.AddCommand(cli.NewListCmd()) - cmd.AddCommand(cli.NewInspectCmd()) - cmd.AddCommand(cli.NewFlushCmd()) - cmd.AddCommand(cli.NewDeleteCmd()) + cmd.AddCommand(cli.newListCmd()) + cmd.AddCommand(cli.newInspectCmd()) + cmd.AddCommand(cli.newFlushCmd()) + cmd.AddCommand(cli.newDeleteCmd()) return cmd } @@ -323,7 +323,7 @@ func (cli *cliAlerts) list(alertListFilter apiclient.AlertsListOpts, limit *int, return nil } -func (cli *cliAlerts) NewListCmd() *cobra.Command { +func (cli *cliAlerts) newListCmd() *cobra.Command { alertListFilter := apiclient.AlertsListOpts{ ScopeEquals: new(string), ValueEquals: new(string), @@ -377,53 +377,53 @@ cscli alerts list --type ban`, return cmd } -func (cli *cliAlerts) delete(alertDeleteFilter apiclient.AlertsDeleteOpts, ActiveDecision *bool, AlertDeleteAll bool, delAlertByID string, contained *bool) error { +func (cli *cliAlerts) delete(delFilter apiclient.AlertsDeleteOpts, activeDecision *bool, deleteAll bool, delAlertByID string, contained *bool) error { var err error - if !AlertDeleteAll { - *alertDeleteFilter.ScopeEquals, err = SanitizeScope(*alertDeleteFilter.ScopeEquals, *alertDeleteFilter.IPEquals, *alertDeleteFilter.RangeEquals) + if !deleteAll { + *delFilter.ScopeEquals, err = SanitizeScope(*delFilter.ScopeEquals, *delFilter.IPEquals, *delFilter.RangeEquals) if err != nil { return err } - if ActiveDecision != nil { - alertDeleteFilter.ActiveDecisionEquals = ActiveDecision + if activeDecision != nil { + delFilter.ActiveDecisionEquals = activeDecision } - if *alertDeleteFilter.ScopeEquals == "" { - alertDeleteFilter.ScopeEquals = nil + if *delFilter.ScopeEquals == "" { + delFilter.ScopeEquals = nil } - if *alertDeleteFilter.ValueEquals == "" { - alertDeleteFilter.ValueEquals = nil + if *delFilter.ValueEquals == "" { + delFilter.ValueEquals = nil } - if *alertDeleteFilter.ScenarioEquals == "" { - alertDeleteFilter.ScenarioEquals = nil + if *delFilter.ScenarioEquals == "" { + delFilter.ScenarioEquals = nil } - if *alertDeleteFilter.IPEquals == "" { - alertDeleteFilter.IPEquals = nil + if *delFilter.IPEquals == "" { + delFilter.IPEquals = nil } - if *alertDeleteFilter.RangeEquals == "" { - alertDeleteFilter.RangeEquals = nil + if *delFilter.RangeEquals == "" { + delFilter.RangeEquals = nil } if contained != nil && *contained { - alertDeleteFilter.Contains = new(bool) + delFilter.Contains = new(bool) } limit := 0 - alertDeleteFilter.Limit = &limit + delFilter.Limit = &limit } else { limit := 0 - alertDeleteFilter = apiclient.AlertsDeleteOpts{Limit: &limit} + delFilter = apiclient.AlertsDeleteOpts{Limit: &limit} } var alerts *models.DeleteAlertsResponse if delAlertByID == "" { - alerts, _, err = cli.client.Alerts.Delete(context.Background(), alertDeleteFilter) + alerts, _, err = cli.client.Alerts.Delete(context.Background(), delFilter) if err != nil { return fmt.Errorf("unable to delete alerts: %w", err) } @@ -439,14 +439,14 @@ func (cli *cliAlerts) delete(alertDeleteFilter apiclient.AlertsDeleteOpts, Activ return nil } -func (cli *cliAlerts) NewDeleteCmd() *cobra.Command { +func (cli *cliAlerts) newDeleteCmd() *cobra.Command { var ( - ActiveDecision *bool - AlertDeleteAll bool + activeDecision *bool + deleteAll bool delAlertByID string ) - alertDeleteFilter := apiclient.AlertsDeleteOpts{ + delFilter := apiclient.AlertsDeleteOpts{ ScopeEquals: new(string), ValueEquals: new(string), ScenarioEquals: new(string), @@ -467,12 +467,12 @@ cscli alerts delete -s crowdsecurity/ssh-bf"`, Aliases: []string{"remove"}, Args: cobra.ExactArgs(0), PreRunE: func(cmd *cobra.Command, _ []string) error { - if AlertDeleteAll { + if deleteAll { return nil } - if *alertDeleteFilter.ScopeEquals == "" && *alertDeleteFilter.ValueEquals == "" && - *alertDeleteFilter.ScenarioEquals == "" && *alertDeleteFilter.IPEquals == "" && - *alertDeleteFilter.RangeEquals == "" && delAlertByID == "" { + if *delFilter.ScopeEquals == "" && *delFilter.ValueEquals == "" && + *delFilter.ScenarioEquals == "" && *delFilter.IPEquals == "" && + *delFilter.RangeEquals == "" && delAlertByID == "" { _ = cmd.Usage() return errors.New("at least one filter or --all must be specified") } @@ -480,19 +480,19 @@ cscli alerts delete -s crowdsecurity/ssh-bf"`, return nil }, RunE: func(cmd *cobra.Command, _ []string) error { - return cli.delete(alertDeleteFilter, ActiveDecision, AlertDeleteAll, delAlertByID, contained) + return cli.delete(delFilter, activeDecision, deleteAll, delAlertByID, contained) }, } flags := cmd.Flags() flags.SortFlags = false - flags.StringVar(alertDeleteFilter.ScopeEquals, "scope", "", "the scope (ie. ip,range)") - flags.StringVarP(alertDeleteFilter.ValueEquals, "value", "v", "", "the value to match for in the specified scope") - flags.StringVarP(alertDeleteFilter.ScenarioEquals, "scenario", "s", "", "the scenario (ie. crowdsecurity/ssh-bf)") - flags.StringVarP(alertDeleteFilter.IPEquals, "ip", "i", "", "Source ip (shorthand for --scope ip --value )") - flags.StringVarP(alertDeleteFilter.RangeEquals, "range", "r", "", "Range source ip (shorthand for --scope range --value )") + flags.StringVar(delFilter.ScopeEquals, "scope", "", "the scope (ie. ip,range)") + flags.StringVarP(delFilter.ValueEquals, "value", "v", "", "the value to match for in the specified scope") + flags.StringVarP(delFilter.ScenarioEquals, "scenario", "s", "", "the scenario (ie. crowdsecurity/ssh-bf)") + flags.StringVarP(delFilter.IPEquals, "ip", "i", "", "Source ip (shorthand for --scope ip --value )") + flags.StringVarP(delFilter.RangeEquals, "range", "r", "", "Range source ip (shorthand for --scope range --value )") flags.StringVar(&delAlertByID, "id", "", "alert ID") - flags.BoolVarP(&AlertDeleteAll, "all", "a", false, "delete all alerts") + flags.BoolVarP(&deleteAll, "all", "a", false, "delete all alerts") flags.BoolVar(contained, "contained", false, "query decisions contained by range") return cmd @@ -538,7 +538,7 @@ func (cli *cliAlerts) inspect(details bool, alertIDs ...string) error { return nil } -func (cli *cliAlerts) NewInspectCmd() *cobra.Command { +func (cli *cliAlerts) newInspectCmd() *cobra.Command { var details bool cmd := &cobra.Command{ @@ -561,7 +561,7 @@ func (cli *cliAlerts) NewInspectCmd() *cobra.Command { return cmd } -func (cli *cliAlerts) NewFlushCmd() *cobra.Command { +func (cli *cliAlerts) newFlushCmd() *cobra.Command { var ( maxItems int maxAge string diff --git a/cmd/crowdsec-cli/clialert/table.go b/cmd/crowdsec-cli/clialert/table.go index 5dec63ec152..1416e1e435c 100644 --- a/cmd/crowdsec-cli/clialert/table.go +++ b/cmd/crowdsec-cli/clialert/table.go @@ -38,7 +38,7 @@ func alertsTable(out io.Writer, wantColor string, alerts *models.GetAlertsRespon *alertItem.Scenario, alertItem.Source.Cn, alertItem.Source.GetAsNumberName(), - DecisionsFromAlert(alertItem), + decisionsFromAlert(alertItem), *alertItem.StartAt, } diff --git a/cmd/crowdsec-cli/clihub/item_metrics.go b/cmd/crowdsec-cli/clihub/item_metrics.go index aaee63d1d38..f4af8f635db 100644 --- a/cmd/crowdsec-cli/clihub/item_metrics.go +++ b/cmd/crowdsec-cli/clihub/item_metrics.go @@ -16,22 +16,22 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/cwhub" ) -func ShowMetrics(prometheusURL string, hubItem *cwhub.Item, wantColor string) error { +func showMetrics(prometheusURL string, hubItem *cwhub.Item, wantColor string) error { switch hubItem.Type { case cwhub.PARSERS: - metrics := GetParserMetric(prometheusURL, hubItem.Name) + metrics := getParserMetric(prometheusURL, hubItem.Name) parserMetricsTable(color.Output, wantColor, hubItem.Name, metrics) case cwhub.SCENARIOS: - metrics := GetScenarioMetric(prometheusURL, hubItem.Name) + metrics := getScenarioMetric(prometheusURL, hubItem.Name) scenarioMetricsTable(color.Output, wantColor, hubItem.Name, metrics) case cwhub.COLLECTIONS: for _, sub := range hubItem.SubItems() { - if err := ShowMetrics(prometheusURL, sub, wantColor); err != nil { + if err := showMetrics(prometheusURL, sub, wantColor); err != nil { return err } } case cwhub.APPSEC_RULES: - metrics := GetAppsecRuleMetric(prometheusURL, hubItem.Name) + metrics := getAppsecRuleMetric(prometheusURL, hubItem.Name) appsecMetricsTable(color.Output, wantColor, hubItem.Name, metrics) default: // no metrics for this item type } @@ -39,11 +39,11 @@ func ShowMetrics(prometheusURL string, hubItem *cwhub.Item, wantColor string) er return nil } -// GetParserMetric is a complete rip from prom2json -func GetParserMetric(url string, itemName string) map[string]map[string]int { +// getParserMetric is a complete rip from prom2json +func getParserMetric(url string, itemName string) map[string]map[string]int { stats := make(map[string]map[string]int) - result := GetPrometheusMetric(url) + result := getPrometheusMetric(url) for idx, fam := range result { if !strings.HasPrefix(fam.Name, "cs_") { continue @@ -131,7 +131,7 @@ func GetParserMetric(url string, itemName string) map[string]map[string]int { return stats } -func GetScenarioMetric(url string, itemName string) map[string]int { +func getScenarioMetric(url string, itemName string) map[string]int { stats := make(map[string]int) stats["instantiation"] = 0 @@ -140,7 +140,7 @@ func GetScenarioMetric(url string, itemName string) map[string]int { stats["pour"] = 0 stats["underflow"] = 0 - result := GetPrometheusMetric(url) + result := getPrometheusMetric(url) for idx, fam := range result { if !strings.HasPrefix(fam.Name, "cs_") { continue @@ -195,13 +195,13 @@ func GetScenarioMetric(url string, itemName string) map[string]int { return stats } -func GetAppsecRuleMetric(url string, itemName string) map[string]int { +func getAppsecRuleMetric(url string, itemName string) map[string]int { stats := make(map[string]int) stats["inband_hits"] = 0 stats["outband_hits"] = 0 - results := GetPrometheusMetric(url) + results := getPrometheusMetric(url) for idx, fam := range results { if !strings.HasPrefix(fam.Name, "cs_") { continue @@ -260,7 +260,7 @@ func GetAppsecRuleMetric(url string, itemName string) map[string]int { return stats } -func GetPrometheusMetric(url string) []*prom2json.Family { +func getPrometheusMetric(url string) []*prom2json.Family { mfChan := make(chan *dto.MetricFamily, 1024) // Start with the DefaultTransport for sane defaults. diff --git a/cmd/crowdsec-cli/clihub/items.go b/cmd/crowdsec-cli/clihub/items.go index 4dd3c46e0f9..0ab89654dac 100644 --- a/cmd/crowdsec-cli/clihub/items.go +++ b/cmd/crowdsec-cli/clihub/items.go @@ -146,7 +146,7 @@ func ListItems(out io.Writer, wantColor string, itemTypes []string, items map[st return nil } -func InspectItem(item *cwhub.Item, showMetrics bool, output string, prometheusURL string, wantColor string) error { +func InspectItem(item *cwhub.Item, wantMetrics bool, output string, prometheusURL string, wantColor string) error { switch output { case "human", "raw": enc := yaml.NewEncoder(os.Stdout) @@ -174,10 +174,10 @@ func InspectItem(item *cwhub.Item, showMetrics bool, output string, prometheusUR fmt.Println() } - if showMetrics { + if wantMetrics { fmt.Printf("\nCurrent metrics: \n") - if err := ShowMetrics(prometheusURL, item, wantColor); err != nil { + if err := showMetrics(prometheusURL, item, wantColor); err != nil { return err } } diff --git a/cmd/crowdsec-cli/clihubtest/clean.go b/cmd/crowdsec-cli/clihubtest/clean.go index 075d7961d84..e3b40b6bd57 100644 --- a/cmd/crowdsec-cli/clihubtest/clean.go +++ b/cmd/crowdsec-cli/clihubtest/clean.go @@ -6,7 +6,7 @@ import ( "github.com/spf13/cobra" ) -func (cli *cliHubTest) NewCleanCmd() *cobra.Command { +func (cli *cliHubTest) newCleanCmd() *cobra.Command { cmd := &cobra.Command{ Use: "clean", Short: "clean [test_name]", diff --git a/cmd/crowdsec-cli/clihubtest/coverage.go b/cmd/crowdsec-cli/clihubtest/coverage.go index b6e5b1e9c01..5a4f231caf5 100644 --- a/cmd/crowdsec-cli/clihubtest/coverage.go +++ b/cmd/crowdsec-cli/clihubtest/coverage.go @@ -140,7 +140,7 @@ func (cli *cliHubTest) coverage(showScenarioCov bool, showParserCov bool, showAp return nil } -func (cli *cliHubTest) NewCoverageCmd() *cobra.Command { +func (cli *cliHubTest) newCoverageCmd() *cobra.Command { var ( showParserCov bool showScenarioCov bool diff --git a/cmd/crowdsec-cli/clihubtest/create.go b/cmd/crowdsec-cli/clihubtest/create.go index 523c9740cf7..e0834f7e569 100644 --- a/cmd/crowdsec-cli/clihubtest/create.go +++ b/cmd/crowdsec-cli/clihubtest/create.go @@ -13,7 +13,7 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/hubtest" ) -func (cli *cliHubTest) NewCreateCmd() *cobra.Command { +func (cli *cliHubTest) newCreateCmd() *cobra.Command { var ( ignoreParsers bool labels map[string]string diff --git a/cmd/crowdsec-cli/clihubtest/eval.go b/cmd/crowdsec-cli/clihubtest/eval.go index 204a0bc420e..83e9eae9c15 100644 --- a/cmd/crowdsec-cli/clihubtest/eval.go +++ b/cmd/crowdsec-cli/clihubtest/eval.go @@ -6,7 +6,7 @@ import ( "github.com/spf13/cobra" ) -func (cli *cliHubTest) NewEvalCmd() *cobra.Command { +func (cli *cliHubTest) newEvalCmd() *cobra.Command { var evalExpression string cmd := &cobra.Command{ diff --git a/cmd/crowdsec-cli/clihubtest/explain.go b/cmd/crowdsec-cli/clihubtest/explain.go index 4183b6a515d..dbe10fa7ec0 100644 --- a/cmd/crowdsec-cli/clihubtest/explain.go +++ b/cmd/crowdsec-cli/clihubtest/explain.go @@ -8,7 +8,6 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/dumps" ) - func (cli *cliHubTest) explain(testName string, details bool, skipOk bool) error { test, err := HubTest.LoadTestItem(testName) if err != nil { @@ -39,7 +38,7 @@ func (cli *cliHubTest) explain(testName string, details bool, skipOk bool) error opts := dumps.DumpOpts{ Details: details, - SkipOk: skipOk, + SkipOk: skipOk, } dumps.DumpTree(*test.ParserAssert.TestData, *test.ScenarioAssert.PourData, opts) @@ -47,8 +46,7 @@ func (cli *cliHubTest) explain(testName string, details bool, skipOk bool) error return nil } - -func (cli *cliHubTest) NewExplainCmd() *cobra.Command { +func (cli *cliHubTest) newExplainCmd() *cobra.Command { var ( details bool skipOk bool diff --git a/cmd/crowdsec-cli/clihubtest/hubtest.go b/cmd/crowdsec-cli/clihubtest/hubtest.go index 22607336177..3420e21e1e2 100644 --- a/cmd/crowdsec-cli/clihubtest/hubtest.go +++ b/cmd/crowdsec-cli/clihubtest/hubtest.go @@ -68,14 +68,14 @@ func (cli *cliHubTest) NewCommand() *cobra.Command { cmd.PersistentFlags().StringVar(&cscliPath, "cscli", "cscli", "Path to cscli") cmd.PersistentFlags().BoolVar(&isAppsecTest, "appsec", false, "Command relates to appsec tests") - cmd.AddCommand(cli.NewCreateCmd()) - cmd.AddCommand(cli.NewRunCmd()) - cmd.AddCommand(cli.NewCleanCmd()) - cmd.AddCommand(cli.NewInfoCmd()) - cmd.AddCommand(cli.NewListCmd()) - cmd.AddCommand(cli.NewCoverageCmd()) - cmd.AddCommand(cli.NewEvalCmd()) - cmd.AddCommand(cli.NewExplainCmd()) + cmd.AddCommand(cli.newCreateCmd()) + cmd.AddCommand(cli.newRunCmd()) + cmd.AddCommand(cli.newCleanCmd()) + cmd.AddCommand(cli.newInfoCmd()) + cmd.AddCommand(cli.newListCmd()) + cmd.AddCommand(cli.newCoverageCmd()) + cmd.AddCommand(cli.newEvalCmd()) + cmd.AddCommand(cli.newExplainCmd()) return cmd } diff --git a/cmd/crowdsec-cli/clihubtest/info.go b/cmd/crowdsec-cli/clihubtest/info.go index 2e3fd132340..a5d760eea01 100644 --- a/cmd/crowdsec-cli/clihubtest/info.go +++ b/cmd/crowdsec-cli/clihubtest/info.go @@ -10,7 +10,7 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/hubtest" ) -func (cli *cliHubTest) NewInfoCmd() *cobra.Command { +func (cli *cliHubTest) newInfoCmd() *cobra.Command { cmd := &cobra.Command{ Use: "info", Short: "info [test_name]", diff --git a/cmd/crowdsec-cli/clihubtest/list.go b/cmd/crowdsec-cli/clihubtest/list.go index 76c51927897..3e76824a18e 100644 --- a/cmd/crowdsec-cli/clihubtest/list.go +++ b/cmd/crowdsec-cli/clihubtest/list.go @@ -9,7 +9,7 @@ import ( "github.com/spf13/cobra" ) -func (cli *cliHubTest) NewListCmd() *cobra.Command { +func (cli *cliHubTest) newListCmd() *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "list", diff --git a/cmd/crowdsec-cli/clihubtest/run.go b/cmd/crowdsec-cli/clihubtest/run.go index 552ee87c16e..57956ce67dc 100644 --- a/cmd/crowdsec-cli/clihubtest/run.go +++ b/cmd/crowdsec-cli/clihubtest/run.go @@ -16,15 +16,15 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/hubtest" ) -func (cli *cliHubTest) run(runAll bool, NucleiTargetHost string, AppSecHost string, args []string) error { +func (cli *cliHubTest) run(runAll bool, nucleiTargetHost string, appSecHost string, args []string) error { cfg := cli.cfg() if !runAll && len(args) == 0 { return errors.New("please provide test to run or --all flag") } - hubPtr.NucleiTargetHost = NucleiTargetHost - hubPtr.AppSecHost = AppSecHost + hubPtr.NucleiTargetHost = nucleiTargetHost + hubPtr.AppSecHost = appSecHost if runAll { if err := hubPtr.LoadAllTests(); err != nil { @@ -56,13 +56,13 @@ func (cli *cliHubTest) run(runAll bool, NucleiTargetHost string, AppSecHost stri return nil } -func (cli *cliHubTest) NewRunCmd() *cobra.Command { +func (cli *cliHubTest) newRunCmd() *cobra.Command { var ( noClean bool runAll bool forceClean bool - NucleiTargetHost string - AppSecHost string + nucleiTargetHost string + appSecHost string ) cmd := &cobra.Command{ @@ -70,7 +70,7 @@ func (cli *cliHubTest) NewRunCmd() *cobra.Command { Short: "run [test_name]", DisableAutoGenTag: true, RunE: func(_ *cobra.Command, args []string) error { - return cli.run(runAll, NucleiTargetHost, AppSecHost, args) + return cli.run(runAll, nucleiTargetHost, appSecHost, args) }, PersistentPostRunE: func(_ *cobra.Command, _ []string) error { cfg := cli.cfg() @@ -187,8 +187,8 @@ func (cli *cliHubTest) NewRunCmd() *cobra.Command { cmd.Flags().BoolVar(&noClean, "no-clean", false, "Don't clean runtime environment if test succeed") cmd.Flags().BoolVar(&forceClean, "clean", false, "Clean runtime environment if test fail") - cmd.Flags().StringVar(&NucleiTargetHost, "target", hubtest.DefaultNucleiTarget, "Target for AppSec Test") - cmd.Flags().StringVar(&AppSecHost, "host", hubtest.DefaultAppsecHost, "Address to expose AppSec for hubtest") + cmd.Flags().StringVar(&nucleiTargetHost, "target", hubtest.DefaultNucleiTarget, "Target for AppSec Test") + cmd.Flags().StringVar(&appSecHost, "host", hubtest.DefaultAppsecHost, "Address to expose AppSec for hubtest") cmd.Flags().BoolVar(&runAll, "all", false, "Run all tests") return cmd diff --git a/cmd/crowdsec-cli/clinotifications/notifications.go b/cmd/crowdsec-cli/clinotifications/notifications.go index 87a94243c5d..eb568ca5fa6 100644 --- a/cmd/crowdsec-cli/clinotifications/notifications.go +++ b/cmd/crowdsec-cli/clinotifications/notifications.go @@ -72,10 +72,10 @@ func (cli *cliNotifications) NewCommand() *cobra.Command { }, } - cmd.AddCommand(cli.NewListCmd()) - cmd.AddCommand(cli.NewInspectCmd()) - cmd.AddCommand(cli.NewReinjectCmd()) - cmd.AddCommand(cli.NewTestCmd()) + cmd.AddCommand(cli.newListCmd()) + cmd.AddCommand(cli.newInspectCmd()) + cmd.AddCommand(cli.newReinjectCmd()) + cmd.AddCommand(cli.newTestCmd()) return cmd } @@ -152,7 +152,7 @@ func (cli *cliNotifications) getProfilesConfigs() (map[string]NotificationsCfg, return ncfgs, nil } -func (cli *cliNotifications) NewListCmd() *cobra.Command { +func (cli *cliNotifications) newListCmd() *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "list notifications plugins", @@ -201,7 +201,7 @@ func (cli *cliNotifications) NewListCmd() *cobra.Command { return cmd } -func (cli *cliNotifications) NewInspectCmd() *cobra.Command { +func (cli *cliNotifications) newInspectCmd() *cobra.Command { cmd := &cobra.Command{ Use: "inspect", Short: "Inspect notifications plugin", @@ -260,7 +260,7 @@ func (cli *cliNotifications) notificationConfigFilter(cmd *cobra.Command, args [ return ret, cobra.ShellCompDirectiveNoFileComp } -func (cli cliNotifications) NewTestCmd() *cobra.Command { +func (cli cliNotifications) newTestCmd() *cobra.Command { var ( pluginBroker csplugin.PluginBroker pluginTomb tomb.Tomb @@ -351,7 +351,7 @@ func (cli cliNotifications) NewTestCmd() *cobra.Command { return cmd } -func (cli *cliNotifications) NewReinjectCmd() *cobra.Command { +func (cli *cliNotifications) newReinjectCmd() *cobra.Command { var ( alertOverride string alert *models.Alert diff --git a/cmd/crowdsec-cli/clisetup/setup.go b/cmd/crowdsec-cli/clisetup/setup.go index 2a1a2bd0560..8aee45b4287 100644 --- a/cmd/crowdsec-cli/clisetup/setup.go +++ b/cmd/crowdsec-cli/clisetup/setup.go @@ -39,10 +39,10 @@ func (cli *cliSetup) NewCommand() *cobra.Command { DisableAutoGenTag: true, } - cmd.AddCommand(cli.NewDetectCmd()) - cmd.AddCommand(cli.NewInstallHubCmd()) - cmd.AddCommand(cli.NewDataSourcesCmd()) - cmd.AddCommand(cli.NewValidateCmd()) + cmd.AddCommand(cli.newDetectCmd()) + cmd.AddCommand(cli.newInstallHubCmd()) + cmd.AddCommand(cli.newDataSourcesCmd()) + cmd.AddCommand(cli.newValidateCmd()) return cmd } @@ -76,23 +76,24 @@ func (f *detectFlags) bind(cmd *cobra.Command) { flags.BoolVar(&f.outYaml, "yaml", false, "output yaml, not json") } -func (cli *cliSetup) NewDetectCmd() *cobra.Command { +func (cli *cliSetup) newDetectCmd() *cobra.Command { f := detectFlags{} cmd := &cobra.Command{ Use: "detect", Short: "detect running services, generate a setup file", DisableAutoGenTag: true, - RunE: func(_ *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { return cli.detect(f) }, } f.bind(cmd) + return cmd } -func (cli *cliSetup) NewInstallHubCmd() *cobra.Command { +func (cli *cliSetup) newInstallHubCmd() *cobra.Command { var dryRun bool cmd := &cobra.Command{ @@ -100,7 +101,7 @@ func (cli *cliSetup) NewInstallHubCmd() *cobra.Command { Short: "install items from a setup file", Args: cobra.ExactArgs(1), DisableAutoGenTag: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, args []string) error { return cli.install(cmd.Context(), dryRun, args[0]) }, } @@ -111,7 +112,7 @@ func (cli *cliSetup) NewInstallHubCmd() *cobra.Command { return cmd } -func (cli *cliSetup) NewDataSourcesCmd() *cobra.Command { +func (cli *cliSetup) newDataSourcesCmd() *cobra.Command { var toDir string cmd := &cobra.Command{ @@ -119,7 +120,7 @@ func (cli *cliSetup) NewDataSourcesCmd() *cobra.Command { Short: "generate datasource (acquisition) configuration from a setup file", Args: cobra.ExactArgs(1), DisableAutoGenTag: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, args []string) error { return cli.dataSources(args[0], toDir) }, } @@ -130,13 +131,13 @@ func (cli *cliSetup) NewDataSourcesCmd() *cobra.Command { return cmd } -func (cli *cliSetup) NewValidateCmd() *cobra.Command { +func (cli *cliSetup) newValidateCmd() *cobra.Command { cmd := &cobra.Command{ Use: "validate [setup_file]", Short: "validate a setup file", Args: cobra.ExactArgs(1), DisableAutoGenTag: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, args []string) error { return cli.validate(args[0]) }, } @@ -165,7 +166,7 @@ func (cli *cliSetup) detect(f detectFlags) error { } if !f.snubSystemd { - _, err := exec.LookPath("systemctl") + _, err = exec.LookPath("systemctl") if err != nil { log.Debug("systemctl not available: snubbing systemd") diff --git a/cmd/crowdsec-cli/clisimulation/simulation.go b/cmd/crowdsec-cli/clisimulation/simulation.go index bf986f82c06..9d9defd78e7 100644 --- a/cmd/crowdsec-cli/clisimulation/simulation.go +++ b/cmd/crowdsec-cli/clisimulation/simulation.go @@ -55,14 +55,14 @@ cscli simulation disable crowdsecurity/ssh-bf`, cmd.Flags().SortFlags = false cmd.PersistentFlags().SortFlags = false - cmd.AddCommand(cli.NewEnableCmd()) - cmd.AddCommand(cli.NewDisableCmd()) - cmd.AddCommand(cli.NewStatusCmd()) + cmd.AddCommand(cli.newEnableCmd()) + cmd.AddCommand(cli.newDisableCmd()) + cmd.AddCommand(cli.newStatusCmd()) return cmd } -func (cli *cliSimulation) NewEnableCmd() *cobra.Command { +func (cli *cliSimulation) newEnableCmd() *cobra.Command { var forceGlobalSimulation bool cmd := &cobra.Command{ @@ -122,7 +122,7 @@ func (cli *cliSimulation) NewEnableCmd() *cobra.Command { return cmd } -func (cli *cliSimulation) NewDisableCmd() *cobra.Command { +func (cli *cliSimulation) newDisableCmd() *cobra.Command { var forceGlobalSimulation bool cmd := &cobra.Command{ @@ -169,7 +169,7 @@ func (cli *cliSimulation) NewDisableCmd() *cobra.Command { return cmd } -func (cli *cliSimulation) NewStatusCmd() *cobra.Command { +func (cli *cliSimulation) newStatusCmd() *cobra.Command { cmd := &cobra.Command{ Use: "status", Short: "Show simulation mode status",