diff --git a/cmd/crowdsec-cli/clihub/hub.go b/cmd/crowdsec-cli/clihub/hub.go index 83a9a7cdb9e..9571b3d866d 100644 --- a/cmd/crowdsec-cli/clihub/hub.go +++ b/cmd/crowdsec-cli/clihub/hub.go @@ -198,9 +198,9 @@ func (cli *cliHub) upgrade(ctx context.Context, yes bool, dryRun bool, force boo func (cli *cliHub) newUpgradeCmd() *cobra.Command { var ( - yes bool + yes bool dryRun bool - force bool + force bool ) cmd := &cobra.Command{ diff --git a/cmd/crowdsec-cli/cliitem/item.go b/cmd/crowdsec-cli/cliitem/item.go index 04a6735316a..637bd3023cf 100644 --- a/cmd/crowdsec-cli/cliitem/item.go +++ b/cmd/crowdsec-cli/cliitem/item.go @@ -123,7 +123,7 @@ func (cli cliItem) install(ctx context.Context, args []string, yes bool, dryRun func (cli cliItem) newInstallCmd() *cobra.Command { var ( - yes bool + yes bool dryRun bool downloadOnly bool force bool @@ -182,6 +182,7 @@ func (cli cliItem) removePlan(hub *cwhub.Hub, args []string, purge bool, force b if err := plan.AddCommand(hubops.NewDisableCommand(item, force)); err != nil { return nil, err } + if purge { if err := plan.AddCommand(hubops.NewPurgeCommand(item, force)); err != nil { return nil, err @@ -213,12 +214,11 @@ func (cli cliItem) removePlan(hub *cwhub.Hub, args []string, purge bool, force b if err := plan.AddCommand(hubops.NewDisableCommand(item, force)); err != nil { return nil, err - } + if purge { if err := plan.AddCommand(hubops.NewPurgeCommand(item, force)); err != nil { return nil, err - } } } @@ -226,7 +226,6 @@ func (cli cliItem) removePlan(hub *cwhub.Hub, args []string, purge bool, force b return plan, nil } - func (cli cliItem) remove(ctx context.Context, args []string, yes bool, dryRun bool, purge bool, force bool, all bool) error { cfg := cli.cfg() @@ -255,7 +254,7 @@ func (cli cliItem) remove(ctx context.Context, args []string, yes bool, dryRun b func (cli cliItem) newRemoveCmd() *cobra.Command { var ( - yes bool + yes bool dryRun bool purge bool force bool @@ -353,10 +352,10 @@ func (cli cliItem) upgrade(ctx context.Context, args []string, yes bool, dryRun func (cli cliItem) newUpgradeCmd() *cobra.Command { var ( - yes bool + yes bool dryRun bool - all bool - force bool + all bool + force bool ) cmd := &cobra.Command{ diff --git a/cmd/crowdsec-cli/clisetup/setup.go b/cmd/crowdsec-cli/clisetup/setup.go index 0de85e63548..77c357e7251 100644 --- a/cmd/crowdsec-cli/clisetup/setup.go +++ b/cmd/crowdsec-cli/clisetup/setup.go @@ -95,7 +95,7 @@ func (cli *cliSetup) newDetectCmd() *cobra.Command { func (cli *cliSetup) newInstallHubCmd() *cobra.Command { var ( - yes bool + yes bool dryRun bool ) diff --git a/cmd/crowdsec-cli/clisupport/support.go b/cmd/crowdsec-cli/clisupport/support.go index 0f4d503da54..5f6032a17bd 100644 --- a/cmd/crowdsec-cli/clisupport/support.go +++ b/cmd/crowdsec-cli/clisupport/support.go @@ -493,7 +493,7 @@ func (cli *cliSupport) dump(ctx context.Context, outFile string) error { hub, err := require.Hub(cfg, nil) if err != nil { - log.Warn("Could not init hub, running on LAPI ? Hub related information will not be collected") + log.Warn("Could not init hub, running on LAPI? Hub related information will not be collected") // XXX: lapi status check requires scenarios, will return an error } diff --git a/pkg/cwhub/download.go b/pkg/cwhub/download.go index 2c97d74015f..48cb2382668 100644 --- a/pkg/cwhub/download.go +++ b/pkg/cwhub/download.go @@ -14,9 +14,9 @@ import ( // Downloader is used to retrieve index and items from a remote hub, with cache control. type Downloader struct { - Branch string - URLTemplate string - IndexPath string + Branch string + URLTemplate string + IndexPath string } // IndexProvider retrieves and writes .index.json @@ -29,7 +29,6 @@ type ContentProvider interface { FetchContent(ctx context.Context, remotePath, destPath, wantHash string, logger *logrus.Logger) (bool, string, error) } - // urlTo builds the URL to download a file from the remote hub. func (d *Downloader) urlTo(remotePath string) (string, error) { // the template must contain two string placeholders @@ -82,7 +81,7 @@ func (d *Downloader) FetchIndex(ctx context.Context, destPath string, withConten CompareContent(). WithLogger(logger.WithField("url", url)). BeforeRequest(func(_ *http.Request) { - fmt.Println("Downloading "+destPath) + fmt.Println("Downloading " + destPath) }). Download(ctx, url) if err != nil { diff --git a/pkg/cwhub/download_test.go b/pkg/cwhub/download_test.go index edfed469157..ec07862abcf 100644 --- a/pkg/cwhub/download_test.go +++ b/pkg/cwhub/download_test.go @@ -3,11 +3,11 @@ package cwhub import ( "context" "io" - "os" - "testing" "net/http" "net/http/httptest" + "os" "path/filepath" + "testing" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" diff --git a/pkg/cwhub/fetch.go b/pkg/cwhub/fetch.go index e8f0b395325..dd1a520d7e2 100644 --- a/pkg/cwhub/fetch.go +++ b/pkg/cwhub/fetch.go @@ -10,7 +10,6 @@ import ( "path/filepath" ) - // writeEmbeddedContentTo writes the embedded content to the specified path and checks the hash. // If the content is base64 encoded, it will be decoded before writing. Check for item.Content // before calling this method. diff --git a/pkg/cwhub/hub.go b/pkg/cwhub/hub.go index 5e0eda9b3fa..3722ceaafcd 100644 --- a/pkg/cwhub/hub.go +++ b/pkg/cwhub/hub.go @@ -235,6 +235,7 @@ func (h *Hub) GetItemsByType(itemType string, sorted bool) []*Item { } idx := 0 + for _, item := range items { ret[idx] = item idx += 1 @@ -266,6 +267,7 @@ func (h *Hub) GetInstalledListForAPI() []string { ret := make([]string, len(scenarios)+len(appsecRules)) idx := 0 + for _, item := range scenarios { ret[idx] = item.Name idx += 1 diff --git a/pkg/hubops/download.go b/pkg/hubops/download.go index 49895963468..72aed542115 100644 --- a/pkg/hubops/download.go +++ b/pkg/hubops/download.go @@ -9,9 +9,9 @@ import ( "os" "time" + "github.com/fatih/color" "github.com/sirupsen/logrus" "gopkg.in/yaml.v3" - "github.com/fatih/color" "github.com/crowdsecurity/go-cs-lib/downloader" @@ -19,15 +19,14 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/types" ) - // DownloadCommand handles the downloading of hub items. // It ensures that items are fetched from the hub (or from the index file if it also has content) // managing dependencies and verifying the integrity of downloaded content. // This is used by "cscli install" and "cscli upgrade". // Tainted items require the force parameter, local items are skipped. type DownloadCommand struct { - Item *cwhub.Item - Force bool + Item *cwhub.Item + Force bool contentProvider cwhub.ContentProvider } diff --git a/pkg/hubtest/hubtest.go b/pkg/hubtest/hubtest.go index 5fd1ce78884..ce9efcec601 100644 --- a/pkg/hubtest/hubtest.go +++ b/pkg/hubtest/hubtest.go @@ -14,8 +14,8 @@ type HubTest struct { CrowdSecPath string CscliPath string HubPath string - HubTestPath string //generic parser/scenario tests .tests - HubAppsecTestPath string //dir specific to appsec tests .appsec-tests + HubTestPath string // generic parser/scenario tests .tests + HubAppsecTestPath string // dir specific to appsec tests .appsec-tests HubIndexFile string TemplateConfigPath string TemplateProfilePath string diff --git a/pkg/leakybucket/buckets_test.go b/pkg/leakybucket/buckets_test.go index d34583b5af2..90a751160cb 100644 --- a/pkg/leakybucket/buckets_test.go +++ b/pkg/leakybucket/buckets_test.go @@ -140,6 +140,7 @@ func testOneBucket(t *testing.T, hub *cwhub.Hub, dir string, tomb *tomb.Tomb) er } scenarios := []*cwhub.Item{} + for _, x := range stages { // XXX: LoadBuckets should take an interface, BucketProvider ScenarioProvider or w/e item := &cwhub.Item{ diff --git a/pkg/setup/install.go b/pkg/setup/install.go index d1d3dbc4262..42634672912 100644 --- a/pkg/setup/install.go +++ b/pkg/setup/install.go @@ -72,6 +72,7 @@ func InstallHubItems(ctx context.Context, hub *cwhub.Hub, contentProvider cwhub. } plan.AddCommand(hubops.NewDownloadCommand(item, contentProvider, forceAction)) + if !downloadOnly { plan.AddCommand(hubops.NewEnableCommand(item, forceAction)) } @@ -84,6 +85,7 @@ func InstallHubItems(ctx context.Context, hub *cwhub.Hub, contentProvider cwhub. } plan.AddCommand(hubops.NewDownloadCommand(item, contentProvider, forceAction)) + if !downloadOnly { plan.AddCommand(hubops.NewEnableCommand(item, forceAction)) } @@ -96,6 +98,7 @@ func InstallHubItems(ctx context.Context, hub *cwhub.Hub, contentProvider cwhub. } plan.AddCommand(hubops.NewDownloadCommand(item, contentProvider, forceAction)) + if !downloadOnly { plan.AddCommand(hubops.NewEnableCommand(item, forceAction)) } @@ -108,6 +111,7 @@ func InstallHubItems(ctx context.Context, hub *cwhub.Hub, contentProvider cwhub. } plan.AddCommand(hubops.NewDownloadCommand(item, contentProvider, forceAction)) + if !downloadOnly { plan.AddCommand(hubops.NewEnableCommand(item, forceAction)) }