Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Dec 27, 2024
1 parent e73f3e3 commit 96431f7
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 26 deletions.
4 changes: 2 additions & 2 deletions cmd/crowdsec-cli/clihub/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
15 changes: 7 additions & 8 deletions cmd/crowdsec-cli/cliitem/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -213,20 +214,18 @@ 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

}
}
}

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()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec-cli/clisetup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (cli *cliSetup) newDetectCmd() *cobra.Command {

func (cli *cliSetup) newInstallHubCmd() *cobra.Command {
var (
yes bool
yes bool
dryRun bool
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec-cli/clisupport/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Check warning on line 496 in cmd/crowdsec-cli/clisupport/support.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec-cli/clisupport/support.go#L496

Added line #L496 was not covered by tests
// XXX: lapi status check requires scenarios, will return an error
}

Expand Down
9 changes: 4 additions & 5 deletions pkg/cwhub/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cwhub/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion pkg/cwhub/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions pkg/cwhub/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ func (h *Hub) GetItemsByType(itemType string, sorted bool) []*Item {
}

idx := 0

for _, item := range items {
ret[idx] = item
idx += 1
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions pkg/hubops/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,24 @@ 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"

"github.com/crowdsecurity/crowdsec/pkg/cwhub"
"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
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/hubtest/hubtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/leakybucket/buckets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 4 additions & 0 deletions pkg/setup/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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))
}
Expand All @@ -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))
}
Expand All @@ -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))
}
Expand Down

0 comments on commit 96431f7

Please sign in to comment.