Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Mar 5, 2024
1 parent fb402dd commit 46f9423
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
5 changes: 3 additions & 2 deletions cmd/crowdsec/crowdsec.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func runCrowdsec(cConfig *csconfig.Config, parsers *parser.Parsers, hub *cwhub.H
inputEventChan = make(chan types.Event)
inputLineChan = make(chan types.Event)

//start go-routines for parsing, buckets pour and outputs.
// start go-routines for parsing, buckets pour and outputs.
parserWg := &sync.WaitGroup{}

parsersTomb.Go(func() error {
Expand All @@ -68,7 +68,8 @@ func runCrowdsec(cConfig *csconfig.Config, parsers *parser.Parsers, hub *cwhub.H
parsersTomb.Go(func() error {
defer trace.CatchPanic("crowdsec/runParse")

if err := runParse(inputLineChan, inputEventChan, *parsers.Ctx, parsers.Nodes); err != nil { //this error will never happen as parser.Parse is not able to return errors
if err := runParse(inputLineChan, inputEventChan, *parsers.Ctx, parsers.Nodes); err != nil {
// this error will never happen as parser.Parse is not able to return errors
log.Fatalf("starting parse error : %s", err)
return err
}
Expand Down
13 changes: 8 additions & 5 deletions cmd/crowdsec/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"flag"
"fmt"
_ "net/http/pprof"
Expand All @@ -10,7 +11,6 @@ import (
"strings"
"time"

"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"gopkg.in/tomb.v2"

Expand Down Expand Up @@ -95,7 +95,7 @@ func LoadBuckets(cConfig *csconfig.Config, hub *cwhub.Hub) error {
holders, outputEventChan, err = leakybucket.LoadBuckets(cConfig.Crowdsec, hub, files, &bucketsTomb, buckets, flags.OrderEvent)

if err != nil {
return fmt.Errorf("scenario loading failed: %v", err)
return fmt.Errorf("scenario loading failed: %w", err)
}

if cConfig.Prometheus != nil && cConfig.Prometheus.Enabled {
Expand All @@ -116,7 +116,7 @@ func LoadAcquisition(cConfig *csconfig.Config) ([]acquisition.DataSource, error)

dataSources, err = acquisition.LoadAcquisitionFromDSN(flags.OneShotDSN, flags.Labels, flags.Transform)
if err != nil {
return nil, errors.Wrapf(err, "failed to configure datasource for %s", flags.OneShotDSN)
return nil, fmt.Errorf("failed to configure datasource for %s: %w", flags.OneShotDSN, err)
}
} else {
dataSources, err = acquisition.LoadAcquisitionFromFile(cConfig.Crowdsec)
Expand All @@ -126,7 +126,7 @@ func LoadAcquisition(cConfig *csconfig.Config) ([]acquisition.DataSource, error)
}

if len(dataSources) == 0 {
return nil, fmt.Errorf("no datasource enabled")
return nil, errors.New("no datasource enabled")
}

return dataSources, nil
Expand Down Expand Up @@ -272,7 +272,7 @@ func LoadConfig(configFile string, disableAgent bool, disableAPI bool, quiet boo
}

if cConfig.DisableAPI && cConfig.DisableAgent {
return nil, errors.New("You must run at least the API Server or crowdsec")
return nil, errors.New("you must run at least the API Server or crowdsec")
}

if flags.OneShotDSN != "" && flags.SingleFileType == "" {
Expand Down Expand Up @@ -360,11 +360,14 @@ func main() {
if err != nil {
log.Fatalf("could not create CPU profile: %s", err)
}

log.Infof("CPU profile will be written to %s", flags.CpuProfile)

if err := pprof.StartCPUProfile(f); err != nil {
f.Close()
log.Fatalf("could not start CPU profile: %s", err)
}

defer f.Close()
defer pprof.StopCPUProfile()
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/crowdsec/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func drainChan(c chan types.Event) {
for {
select {
case _, ok := <-c:
if !ok { //closed
if !ok { // closed
return
}
default:
Expand All @@ -256,8 +256,8 @@ func HandleSignals(cConfig *csconfig.Config) error {

exitChan := make(chan error)

//Always try to stop CPU profiling to avoid passing flags around
//It's a noop if profiling is not enabled
// Always try to stop CPU profiling to avoid passing flags around
// It's a noop if profiling is not enabled
defer pprof.StopCPUProfile()

go func() {
Expand Down
6 changes: 6 additions & 0 deletions pkg/csconfig/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,27 @@ func (c *ConsoleConfig) EnabledOptions() []string {
if c == nil {
return ret
}

Check warning on line 44 in pkg/csconfig/console.go

View check run for this annotation

Codecov / codecov/patch

pkg/csconfig/console.go#L40-L44

Added lines #L40 - L44 were not covered by tests

if c.ShareCustomScenarios != nil && *c.ShareCustomScenarios {
ret = append(ret, SEND_CUSTOM_SCENARIOS)
}

Check warning on line 48 in pkg/csconfig/console.go

View check run for this annotation

Codecov / codecov/patch

pkg/csconfig/console.go#L46-L48

Added lines #L46 - L48 were not covered by tests

if c.ShareTaintedScenarios != nil && *c.ShareTaintedScenarios {
ret = append(ret, SEND_TAINTED_SCENARIOS)
}

Check warning on line 52 in pkg/csconfig/console.go

View check run for this annotation

Codecov / codecov/patch

pkg/csconfig/console.go#L50-L52

Added lines #L50 - L52 were not covered by tests

if c.ShareManualDecisions != nil && *c.ShareManualDecisions {
ret = append(ret, SEND_MANUAL_SCENARIOS)
}

Check warning on line 56 in pkg/csconfig/console.go

View check run for this annotation

Codecov / codecov/patch

pkg/csconfig/console.go#L54-L56

Added lines #L54 - L56 were not covered by tests

if c.ConsoleManagement != nil && *c.ConsoleManagement {
ret = append(ret, CONSOLE_MANAGEMENT)
}

Check warning on line 60 in pkg/csconfig/console.go

View check run for this annotation

Codecov / codecov/patch

pkg/csconfig/console.go#L58-L60

Added lines #L58 - L60 were not covered by tests

if c.ShareContext != nil && *c.ShareContext {
ret = append(ret, SEND_CONTEXT)
}

Check warning on line 64 in pkg/csconfig/console.go

View check run for this annotation

Codecov / codecov/patch

pkg/csconfig/console.go#L62-L64

Added lines #L62 - L64 were not covered by tests

return ret

Check warning on line 66 in pkg/csconfig/console.go

View check run for this annotation

Codecov / codecov/patch

pkg/csconfig/console.go#L66

Added line #L66 was not covered by tests
}

Expand Down

0 comments on commit 46f9423

Please sign in to comment.