From b5d4adbf74d44b218e3bb94569738df70781d629 Mon Sep 17 00:00:00 2001 From: marco Date: Thu, 29 Aug 2024 16:58:09 +0200 Subject: [PATCH] cscli refact: package cliitem --- .../{hubappsec.go => cliitem/appsec.go} | 6 +++--- .../{hubcollection.go => cliitem/collection.go} | 4 ++-- .../{hubcontext.go => cliitem/context.go} | 4 ++-- cmd/crowdsec-cli/{ => cliitem}/hubscenario.go | 4 ++-- cmd/crowdsec-cli/{itemcli.go => cliitem/item.go} | 5 ++++- .../{hubparser.go => cliitem/parser.go} | 4 ++-- .../postoverflow.go} | 4 ++-- .../{item_suggest.go => cliitem/suggest.go} | 2 +- cmd/crowdsec-cli/main.go | 15 ++++++++------- 9 files changed, 26 insertions(+), 22 deletions(-) rename cmd/crowdsec-cli/{hubappsec.go => cliitem/appsec.go} (96%) rename cmd/crowdsec-cli/{hubcollection.go => cliitem/collection.go} (95%) rename cmd/crowdsec-cli/{hubcontext.go => cliitem/context.go} (94%) rename cmd/crowdsec-cli/{ => cliitem}/hubscenario.go (95%) rename cmd/crowdsec-cli/{itemcli.go => cliitem/item.go} (99%) rename cmd/crowdsec-cli/{hubparser.go => cliitem/parser.go} (95%) rename cmd/crowdsec-cli/{hubpostoverflow.go => cliitem/postoverflow.go} (95%) rename cmd/crowdsec-cli/{item_suggest.go => cliitem/suggest.go} (99%) diff --git a/cmd/crowdsec-cli/hubappsec.go b/cmd/crowdsec-cli/cliitem/appsec.go similarity index 96% rename from cmd/crowdsec-cli/hubappsec.go rename to cmd/crowdsec-cli/cliitem/appsec.go index 1df3212f941..db567f86a32 100644 --- a/cmd/crowdsec-cli/hubappsec.go +++ b/cmd/crowdsec-cli/cliitem/appsec.go @@ -1,4 +1,4 @@ -package main +package cliitem import ( "fmt" @@ -13,7 +13,7 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/cwhub" ) -func NewCLIAppsecConfig(cfg configGetter) *cliItem { +func NewAppsecConfig(cfg configGetter) *cliItem { return &cliItem{ cfg: cfg, name: cwhub.APPSEC_CONFIGS, @@ -47,7 +47,7 @@ cscli appsec-configs list crowdsecurity/vpatch`, } } -func NewCLIAppsecRule(cfg configGetter) *cliItem { +func NewAppsecRule(cfg configGetter) *cliItem { inspectDetail := func(item *cwhub.Item) error { // Only show the converted rules in human mode if cfg().Cscli.Output != "human" { diff --git a/cmd/crowdsec-cli/hubcollection.go b/cmd/crowdsec-cli/cliitem/collection.go similarity index 95% rename from cmd/crowdsec-cli/hubcollection.go rename to cmd/crowdsec-cli/cliitem/collection.go index 655b36eb1b8..ea91c1e537a 100644 --- a/cmd/crowdsec-cli/hubcollection.go +++ b/cmd/crowdsec-cli/cliitem/collection.go @@ -1,10 +1,10 @@ -package main +package cliitem import ( "github.com/crowdsecurity/crowdsec/pkg/cwhub" ) -func NewCLICollection(cfg configGetter) *cliItem { +func NewCollection(cfg configGetter) *cliItem { return &cliItem{ cfg: cfg, name: cwhub.COLLECTIONS, diff --git a/cmd/crowdsec-cli/hubcontext.go b/cmd/crowdsec-cli/cliitem/context.go similarity index 94% rename from cmd/crowdsec-cli/hubcontext.go rename to cmd/crowdsec-cli/cliitem/context.go index 2a777327379..7d110b8203d 100644 --- a/cmd/crowdsec-cli/hubcontext.go +++ b/cmd/crowdsec-cli/cliitem/context.go @@ -1,10 +1,10 @@ -package main +package cliitem import ( "github.com/crowdsecurity/crowdsec/pkg/cwhub" ) -func NewCLIContext(cfg configGetter) *cliItem { +func NewContext(cfg configGetter) *cliItem { return &cliItem{ cfg: cfg, name: cwhub.CONTEXTS, diff --git a/cmd/crowdsec-cli/hubscenario.go b/cmd/crowdsec-cli/cliitem/hubscenario.go similarity index 95% rename from cmd/crowdsec-cli/hubscenario.go rename to cmd/crowdsec-cli/cliitem/hubscenario.go index 4434b9a2c45..a5e854b3c82 100644 --- a/cmd/crowdsec-cli/hubscenario.go +++ b/cmd/crowdsec-cli/cliitem/hubscenario.go @@ -1,10 +1,10 @@ -package main +package cliitem import ( "github.com/crowdsecurity/crowdsec/pkg/cwhub" ) -func NewCLIScenario(cfg configGetter) *cliItem { +func NewScenario(cfg configGetter) *cliItem { return &cliItem{ cfg: cfg, name: cwhub.SCENARIOS, diff --git a/cmd/crowdsec-cli/itemcli.go b/cmd/crowdsec-cli/cliitem/item.go similarity index 99% rename from cmd/crowdsec-cli/itemcli.go rename to cmd/crowdsec-cli/cliitem/item.go index a5629b425b9..28828eb9c95 100644 --- a/cmd/crowdsec-cli/itemcli.go +++ b/cmd/crowdsec-cli/cliitem/item.go @@ -1,4 +1,4 @@ -package main +package cliitem import ( "cmp" @@ -18,6 +18,7 @@ import ( "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clihub" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/reload" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/require" + "github.com/crowdsecurity/crowdsec/pkg/csconfig" "github.com/crowdsecurity/crowdsec/pkg/cwhub" ) @@ -30,6 +31,8 @@ type cliHelp struct { example string } +type configGetter func() *csconfig.Config + type cliItem struct { cfg configGetter name string // plural, as used in the hub index diff --git a/cmd/crowdsec-cli/hubparser.go b/cmd/crowdsec-cli/cliitem/parser.go similarity index 95% rename from cmd/crowdsec-cli/hubparser.go rename to cmd/crowdsec-cli/cliitem/parser.go index cc856cbedb9..bc1d96bdaf0 100644 --- a/cmd/crowdsec-cli/hubparser.go +++ b/cmd/crowdsec-cli/cliitem/parser.go @@ -1,10 +1,10 @@ -package main +package cliitem import ( "github.com/crowdsecurity/crowdsec/pkg/cwhub" ) -func NewCLIParser(cfg configGetter) *cliItem { +func NewParser(cfg configGetter) *cliItem { return &cliItem{ cfg: cfg, name: cwhub.PARSERS, diff --git a/cmd/crowdsec-cli/hubpostoverflow.go b/cmd/crowdsec-cli/cliitem/postoverflow.go similarity index 95% rename from cmd/crowdsec-cli/hubpostoverflow.go rename to cmd/crowdsec-cli/cliitem/postoverflow.go index 3fd45fd113d..ea53aef327d 100644 --- a/cmd/crowdsec-cli/hubpostoverflow.go +++ b/cmd/crowdsec-cli/cliitem/postoverflow.go @@ -1,10 +1,10 @@ -package main +package cliitem import ( "github.com/crowdsecurity/crowdsec/pkg/cwhub" ) -func NewCLIPostOverflow(cfg configGetter) *cliItem { +func NewPostOverflow(cfg configGetter) *cliItem { return &cliItem{ cfg: cfg, name: cwhub.POSTOVERFLOWS, diff --git a/cmd/crowdsec-cli/item_suggest.go b/cmd/crowdsec-cli/cliitem/suggest.go similarity index 99% rename from cmd/crowdsec-cli/item_suggest.go rename to cmd/crowdsec-cli/cliitem/suggest.go index 7d3e1e728ae..5b080722af9 100644 --- a/cmd/crowdsec-cli/item_suggest.go +++ b/cmd/crowdsec-cli/cliitem/suggest.go @@ -1,4 +1,4 @@ -package main +package cliitem import ( "fmt" diff --git a/cmd/crowdsec-cli/main.go b/cmd/crowdsec-cli/main.go index 2a1f5ac7ebe..6f8e93e463c 100644 --- a/cmd/crowdsec-cli/main.go +++ b/cmd/crowdsec-cli/main.go @@ -20,6 +20,7 @@ import ( "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/cliexplain" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clihub" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clihubtest" + "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/cliitem" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clilapi" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/climachine" "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/climetrics" @@ -270,13 +271,13 @@ It is meant to allow you to manage bans, parsers/scenarios/etc, api and generall cmd.AddCommand(clinotifications.New(cli.cfg).NewCommand()) cmd.AddCommand(clisupport.New(cli.cfg).NewCommand()) cmd.AddCommand(clipapi.New(cli.cfg).NewCommand()) - cmd.AddCommand(NewCLICollection(cli.cfg).NewCommand()) - cmd.AddCommand(NewCLIParser(cli.cfg).NewCommand()) - cmd.AddCommand(NewCLIScenario(cli.cfg).NewCommand()) - cmd.AddCommand(NewCLIPostOverflow(cli.cfg).NewCommand()) - cmd.AddCommand(NewCLIContext(cli.cfg).NewCommand()) - cmd.AddCommand(NewCLIAppsecConfig(cli.cfg).NewCommand()) - cmd.AddCommand(NewCLIAppsecRule(cli.cfg).NewCommand()) + cmd.AddCommand(cliitem.NewCollection(cli.cfg).NewCommand()) + cmd.AddCommand(cliitem.NewParser(cli.cfg).NewCommand()) + cmd.AddCommand(cliitem.NewScenario(cli.cfg).NewCommand()) + cmd.AddCommand(cliitem.NewPostOverflow(cli.cfg).NewCommand()) + cmd.AddCommand(cliitem.NewContext(cli.cfg).NewCommand()) + cmd.AddCommand(cliitem.NewAppsecConfig(cli.cfg).NewCommand()) + cmd.AddCommand(cliitem.NewAppsecRule(cli.cfg).NewCommand()) if fflag.CscliSetup.IsEnabled() { cmd.AddCommand(clisetup.New(cli.cfg).NewCommand())