From db9e1e280d2693e21063a0499c08d9db8cf800cf Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Wed, 20 May 2020 10:49:17 +0200 Subject: [PATCH 01/26] fix linter warnings : dead code, simplification --- cmd/crowdsec-cli/api.go | 4 +++- cmd/crowdsec-cli/ban.go | 9 --------- cmd/crowdsec-cli/config.go | 6 ++---- cmd/crowdsec-cli/dashboard.go | 2 +- cmd/crowdsec-cli/install.go | 17 ---------------- cmd/crowdsec-cli/main.go | 4 +++- cmd/crowdsec-cli/upgrade.go | 16 +++++++-------- cmd/crowdsec/main.go | 6 +++--- cmd/crowdsec/metrics.go | 9 ++++++--- cmd/crowdsec/parse.go | 6 +++--- cmd/crowdsec/pour.go | 8 ++++++-- cmd/crowdsec/serve.go | 2 +- pkg/config/crowdsec/config.go | 4 ++-- pkg/cwhub/hubMgmt.go | 31 +++++++++++++++--------------- pkg/cwplugin/backend.go | 4 +++- pkg/leakybucket/bucket.go | 8 ++++---- pkg/leakybucket/buckets_test.go | 9 ++++++--- pkg/leakybucket/manager.go | 8 ++++---- pkg/leakybucket/overflow_filter.go | 2 +- pkg/outputs/ouputs.go | 18 ++++++++++------- pkg/parser/node.go | 30 ++++++++++++++--------------- pkg/parser/parsing_test.go | 8 ++++---- pkg/parser/runtime.go | 10 +++++----- pkg/time/rate/rate_test.go | 4 +++- 24 files changed, 110 insertions(+), 115 deletions(-) diff --git a/cmd/crowdsec-cli/api.go b/cmd/crowdsec-cli/api.go index e7c6cc018..1b9e73159 100644 --- a/cmd/crowdsec-cli/api.go +++ b/cmd/crowdsec-cli/api.go @@ -265,7 +265,9 @@ cscli api credentials # Display your API credentials cmdAPI.AddCommand(cmdAPICreds) cmdAPIEnroll.Flags().StringVarP(&userID, "user", "u", "", "User ID (required)") - cmdAPIEnroll.MarkFlagRequired("user") + if err := cmdAPIEnroll.MarkFlagRequired("user"); err != nil { + log.Errorf("'user' flag : %s", err) + } cmdAPI.AddCommand(cmdAPIEnroll) cmdAPI.AddCommand(cmdAPIResetPassword) cmdAPI.AddCommand(cmdAPIRegister) diff --git a/cmd/crowdsec-cli/ban.go b/cmd/crowdsec-cli/ban.go index de7b950aa..8c852a093 100644 --- a/cmd/crowdsec-cli/ban.go +++ b/cmd/crowdsec-cli/ban.go @@ -164,15 +164,6 @@ func BanAdd(target string, duration string, reason string, action string) error return nil } -func banFlush() error { - allBa := types.BanApplication{} - records := dbctx.Db.Delete(&allBa) - if records.Error != nil { - return records.Error - } - return nil -} - func NewBanCmds() *cobra.Command { /*TODO : add a remediation type*/ var cmdBan = &cobra.Command{ diff --git a/cmd/crowdsec-cli/config.go b/cmd/crowdsec-cli/config.go index 8dec02147..c29647e07 100644 --- a/cmd/crowdsec-cli/config.go +++ b/cmd/crowdsec-cli/config.go @@ -16,10 +16,8 @@ import ( /*CliCfg is the cli configuration structure, might be unexported*/ type cliConfig struct { configured bool - simulation bool /*are we in simulation mode*/ - configFolder string `yaml:"cliconfig,omitempty"` /*overload ~/.cscli/*/ - output string /*output is human, json*/ - logLevel log.Level /*debug,info,warning,error*/ + configFolder string `yaml:"cliconfig,omitempty"` /*overload ~/.cscli/*/ + output string /*output is human, json*/ hubFolder string InstallFolder string `yaml:"installdir"` /*/etc/crowdsec/*/ BackendPluginFolder string `yaml:"backend"` diff --git a/cmd/crowdsec-cli/dashboard.go b/cmd/crowdsec-cli/dashboard.go index afb0b4e88..21bee6c46 100644 --- a/cmd/crowdsec-cli/dashboard.go +++ b/cmd/crowdsec-cli/dashboard.go @@ -128,7 +128,7 @@ func downloadMetabaseDB(force bool) error { metabaseDBSubpath := path.Join(metabaseDbPath, "metabase.db") _, err := os.Stat(metabaseDBSubpath) - if err == nil && force == false { + if err == nil && !force { log.Printf("%s exists, skip.", metabaseDBSubpath) return nil } diff --git a/cmd/crowdsec-cli/install.go b/cmd/crowdsec-cli/install.go index 189ea2f9d..fe90af7bd 100644 --- a/cmd/crowdsec-cli/install.go +++ b/cmd/crowdsec-cli/install.go @@ -41,23 +41,6 @@ func InstallItem(name string, obtype string) { /*iterate of pkg index data*/ } -func InstallScenario(name string) { - InstallItem(name, cwhub.SCENARIOS) -} - -func InstallCollection(name string) { - InstallItem(name, cwhub.COLLECTIONS) - -} - -func InstallParser(name string) { - InstallItem(name, cwhub.PARSERS) -} - -func InstallPostoverflow(name string) { - InstallItem(name, cwhub.PARSERS_OVFLW) -} - func NewInstallCmd() *cobra.Command { /* ---- INSTALL COMMAND */ diff --git a/cmd/crowdsec-cli/main.go b/cmd/crowdsec-cli/main.go index 798350eda..9f80c70c5 100644 --- a/cmd/crowdsec-cli/main.go +++ b/cmd/crowdsec-cli/main.go @@ -135,5 +135,7 @@ API interaction: rootCmd.AddCommand(NewDashboardCmd()) rootCmd.AddCommand(NewInspectCmd()) - rootCmd.Execute() + if err := rootCmd.Execute(); err != nil { + log.Fatalf("While executing root command : %s", err) + } } diff --git a/cmd/crowdsec-cli/upgrade.go b/cmd/crowdsec-cli/upgrade.go index 456ddb47c..b0c0b9fcc 100644 --- a/cmd/crowdsec-cli/upgrade.go +++ b/cmd/crowdsec-cli/upgrade.go @@ -51,9 +51,9 @@ func UpgradeConfig(ttype string, name string) { } cwhub.HubIdx[ttype][v.Name] = v } - if found == false { + if !found { log.Errorf("Didn't find %s", name) - } else if updated == 0 && found == true { + } else if updated == 0 && found { log.Errorf("Nothing to update") } else if updated != 0 { log.Infof("Upgraded %d items", updated) @@ -93,14 +93,14 @@ cscli upgrade --force # Overwrite tainted configuration return nil }, Run: func(cmd *cobra.Command, args []string) { - if upgrade_all == false && len(args) < 2 { + if !upgrade_all && len(args) < 2 { _ = cmd.Help() return } if err := cwhub.GetHubIdx(); err != nil { log.Fatalf("Failed to get Hub index : %v", err) } - if upgrade_all == true && len(args) == 0 { + if upgrade_all && len(args) == 0 { log.Warningf("Upgrade all : parsers, scenarios, collections.") UpgradeConfig(cwhub.PARSERS, "") UpgradeConfig(cwhub.PARSERS_OVFLW, "") @@ -127,7 +127,7 @@ cscli upgrade --force # Overwrite tainted configuration if len(args) == 1 { UpgradeConfig(cwhub.PARSERS, args[0]) //UpgradeConfig(cwhub.PARSERS_OVFLW, "") - } else if upgrade_all == true { + } else if upgrade_all { UpgradeConfig(cwhub.PARSERS, "") } else { _ = cmd.Help() @@ -148,7 +148,7 @@ cscli upgrade --force # Overwrite tainted configuration } if len(args) == 1 { UpgradeConfig(cwhub.SCENARIOS, args[0]) - } else if upgrade_all == true { + } else if upgrade_all { UpgradeConfig(cwhub.SCENARIOS, "") } else { _ = cmd.Help() @@ -170,7 +170,7 @@ cscli upgrade --force # Overwrite tainted configuration } if len(args) == 1 { UpgradeConfig(cwhub.COLLECTIONS, args[0]) - } else if upgrade_all == true { + } else if upgrade_all { UpgradeConfig(cwhub.COLLECTIONS, "") } else { _ = cmd.Help() @@ -193,7 +193,7 @@ cscli upgrade --force # Overwrite tainted configuration } if len(args) == 1 { UpgradeConfig(cwhub.PARSERS_OVFLW, args[0]) - } else if upgrade_all == true { + } else if upgrade_all { UpgradeConfig(cwhub.PARSERS_OVFLW, "") } else { _ = cmd.Help() diff --git a/cmd/crowdsec/main.go b/cmd/crowdsec/main.go index bca719efd..80ca49a5c 100644 --- a/cmd/crowdsec/main.go +++ b/cmd/crowdsec/main.go @@ -98,7 +98,7 @@ func main() { log.Infof("Crowdwatch %s", cwversion.VersionStr()) - if cConfig.Prometheus == true { + if cConfig.Prometheus { registerPrometheus() cConfig.Profiling = true } @@ -117,7 +117,7 @@ func main() { } /*enable profiling*/ - if cConfig.Profiling == true { + if cConfig.Profiling { go runTachymeter(cConfig.HTTPListen) parserCTX.Profiling = true postOverflowCTX.Profiling = true @@ -233,7 +233,7 @@ func main() { log.Fatalf("unable to restore buckets : %s", err) } } - if cConfig.Profiling == true { + if cConfig.Profiling { //force the profiling in all buckets for holderIndex := range holders { holders[holderIndex].Profiling = true diff --git a/cmd/crowdsec/metrics.go b/cmd/crowdsec/metrics.go index 0c1608b06..2d822a5fd 100644 --- a/cmd/crowdsec/metrics.go +++ b/cmd/crowdsec/metrics.go @@ -10,9 +10,10 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" - log "github.com/sirupsen/logrus" "net/http" + log "github.com/sirupsen/logrus" + "runtime" ) @@ -67,7 +68,7 @@ var globalBucketPourOk = prometheus.NewCounter( func dumpMetrics() { - if cConfig.DumpBuckets == true { + if cConfig.DumpBuckets { log.Infof("!! Dumping buckets state") if err := leaky.DumpBucketsStateAt("buckets_state.json", time.Now(), buckets); err != nil { log.Fatalf("Failed dumping bucket state : %s", err) @@ -98,7 +99,9 @@ func dumpMetrics() { log.Infof("Lines never poured : %d (%.2f%%)", linesPouredKO, float64(linesPouredKO)/float64(linesPouredOK)*100.0) } log.Infof("Writting metrics dump to %s", cConfig.WorkingFolder+"/crowdsec.profile") - prometheus.WriteToTextfile(cConfig.WorkingFolder+"/crowdsec.profile", prometheus.DefaultGatherer) + if err := prometheus.WriteToTextfile(cConfig.WorkingFolder+"/crowdsec.profile", prometheus.DefaultGatherer); err != nil { + log.Errorf("failed to write metrics to %s : %s", cConfig.WorkingFolder+"/crowdsec.profile", err) + } } } diff --git a/cmd/crowdsec/parse.go b/cmd/crowdsec/parse.go index 59ea723a3..1274109f9 100644 --- a/cmd/crowdsec/parse.go +++ b/cmd/crowdsec/parse.go @@ -26,7 +26,7 @@ LOOP: if cConfig.Profiling { start = time.Now() } - if event.Process == false { + if !event.Process { if cConfig.Profiling { atomic.AddUint64(&linesReadKO, 1) } @@ -43,7 +43,7 @@ LOOP: log.Errorf("failed parsing : %v\n", error) return errors.New("parsing failed :/") } - if parsed.Process == false { + if !parsed.Process { if cConfig.Profiling { globalParserHitsKo.With(prometheus.Labels{"source": event.Line.Src}).Inc() atomic.AddUint64(&linesParsedKO, 1) @@ -57,7 +57,7 @@ LOOP: atomic.AddUint64(&linesParsedOK, 1) } processCPT++ - if parsed.Whitelisted == true { + if parsed.Whitelisted { log.Debugf("event whitelisted, discard") continue } diff --git a/cmd/crowdsec/pour.go b/cmd/crowdsec/pour.go index 4bca09447..59c9e7f3a 100644 --- a/cmd/crowdsec/pour.go +++ b/cmd/crowdsec/pour.go @@ -37,7 +37,9 @@ LOOP: log.Warningf("Failed to unmarshal time from event '%s' : %s", parsed.MarshaledTime, err) } else { log.Warningf("Starting buckets garbage collection ...") - leaky.GarbageCollectBuckets(*z, buckets) + if err = leaky.GarbageCollectBuckets(*z, buckets); err != nil { + return fmt.Errorf("failed to start bucket GC : %s", err) + } } } } @@ -57,7 +59,9 @@ LOOP: if cConfig.Profiling { bucketStat.AddTime(time.Since(start)) } - lastProcessedItem.UnmarshalText([]byte(parsed.MarshaledTime)) + if err := lastProcessedItem.UnmarshalText([]byte(parsed.MarshaledTime)); err != nil { + return fmt.Errorf("failed to unmarshal item : %s", err) + } } } log.Infof("Sending signal Bucketify") diff --git a/cmd/crowdsec/serve.go b/cmd/crowdsec/serve.go index fd7ab7edd..61a07600e 100644 --- a/cmd/crowdsec/serve.go +++ b/cmd/crowdsec/serve.go @@ -117,7 +117,7 @@ func serveOneTimeRun(outputRunner outputs.Output) error { func serve(outputRunner outputs.Output) error { var err error - if cConfig.Daemonize == true { + if cConfig.Daemonize { if err = serveDaemon(); err != nil { return fmt.Errorf(err.Error()) } diff --git a/pkg/config/crowdsec/config.go b/pkg/config/crowdsec/config.go index 2b1c6c4a1..3f9c9e2f2 100644 --- a/pkg/config/crowdsec/config.go +++ b/pkg/config/crowdsec/config.go @@ -82,7 +82,7 @@ func (c *Crowdwatch) GetOPT() error { flag.Parse() - if *printVersion == true { + if *printVersion { cwversion.Show() os.Exit(0) } @@ -112,7 +112,7 @@ func (c *Crowdwatch) GetOPT() error { if *AcquisitionFile != "" { c.AcquisitionFile = *AcquisitionFile } - if *dumpMode == true { + if *dumpMode { c.DumpBuckets = true } if *prometheus { diff --git a/pkg/cwhub/hubMgmt.go b/pkg/cwhub/hubMgmt.go index 02518eabd..4729bb5d1 100644 --- a/pkg/cwhub/hubMgmt.go +++ b/pkg/cwhub/hubMgmt.go @@ -187,7 +187,7 @@ func parser_visit(path string, f os.FileInfo, err error) error { } //if it's not a symlink and not in hub, it's a local file, don't bother - if local == true && inhub == false { + if local && !inhub { log.Debugf("%s is a local file, skip", path) skippedLocal++ // log.Printf("local scenario, skip.") @@ -252,8 +252,7 @@ func parser_visit(path string, f os.FileInfo, err error) error { continue } else { /*we got an exact match, update struct*/ - // log.Printf("got exact match") - if inhub == false { + if !inhub { log.Debugf("found exact match for %s, version is %s, latest is %s", v.Name, version, v.Version) v.LocalPath = path v.LocalVersion = version @@ -275,11 +274,11 @@ func parser_visit(path string, f os.FileInfo, err error) error { } } - if match == false { + if !match { log.Debugf("got tainted match for %s : %s", v.Name, path) skippedTainted += 1 //the file and the stage is right, but the hash is wrong, it has been tainted by user - if inhub == false { + if !inhub { v.LocalPath = path v.Installed = true } @@ -321,13 +320,13 @@ func CollecDepsCheck(v *Item) error { } //propagate the state of sub-items to set - if val.Tainted == true { + if val.Tainted { v.Tainted = true return fmt.Errorf("tainted %s %s, tainted.", ptrtype, p) - } else if val.Installed == false && v.Installed == true { + } else if !val.Installed && v.Installed { v.Tainted = true return fmt.Errorf("missing %s %s, tainted.", ptrtype, p) - } else if val.UpToDate == false { + } else if !val.UpToDate { v.UpToDate = false return fmt.Errorf("outdated %s %s", ptrtype, p) } @@ -553,14 +552,14 @@ func DisableItem(target Item, tdir string, hdir string, purge bool) (Item, error func EnableItem(target Item, tdir string, hdir string) (Item, error) { parent_dir := filepath.Clean(tdir + "/" + target.Type + "/" + target.Stage + "/") /*create directories if needed*/ - if target.Installed == true { - if target.Tainted == true { + if target.Installed { + if target.Tainted { return target, fmt.Errorf("%s is tainted, won't enable unless --force", target.Name) } - if target.Local == true { + if target.Local { return target, fmt.Errorf("%s is local, won't enable", target.Name) } - if target.UpToDate == true { + if target.UpToDate { log.Debugf("%s is installed and up-to-date, skip.", target.Name) return target, nil } @@ -690,7 +689,9 @@ func DownloadItem(target Item, tdir string, overwrite bool) (Item, error) { return target, err } h := sha256.New() - h.Write([]byte(body)) + if _, err := h.Write([]byte(body)); err != nil { + return target, fmt.Errorf("%s : failed to write : %s", target.Name, err) + } meow := fmt.Sprintf("%x", h.Sum(nil)) if meow != target.Versions[target.Version].Digest { log.Errorf("Downloaded version doesn't match index, please 'hub update'") @@ -737,7 +738,7 @@ func ItemStatus(v Item) (string, bool, bool, bool) { var Ok, Warning, Managed bool var strret string - if v.Installed == false { + if !v.Installed { strret = "disabled" Ok = false } else { @@ -745,7 +746,7 @@ func ItemStatus(v Item) (string, bool, bool, bool) { strret = "enabled" } - if v.Local == true { + if v.Local { Managed = false strret += ",local" } else { diff --git a/pkg/cwplugin/backend.go b/pkg/cwplugin/backend.go index 809e66503..07f3fb372 100644 --- a/pkg/cwplugin/backend.go +++ b/pkg/cwplugin/backend.go @@ -134,7 +134,9 @@ func (b *BackendManager) DeleteAll() error { // Insert the signal for the plugin specified in the config["plugin"] parameter func (b *BackendManager) InsertOnePlugin(sig types.SignalOccurence, pluginName string) error { if val, ok := b.backendPlugins[pluginName]; ok { - val.funcs.Insert(sig) + if err := val.funcs.Insert(sig); err != nil { + return fmt.Errorf("failed to load %s : %s", pluginName, err) + } } else { return fmt.Errorf("plugin '%s' not loaded", pluginName) } diff --git a/pkg/leakybucket/bucket.go b/pkg/leakybucket/bucket.go index ee1f98714..183fed00b 100644 --- a/pkg/leakybucket/bucket.go +++ b/pkg/leakybucket/bucket.go @@ -135,7 +135,7 @@ func FromFactory(g BucketFactory) *Leaky { } else { limiter = rate.NewLimiter(rate.Every(g.leakspeed), g.Capacity) } - if g.Profiling == true { + if g.Profiling { BucketsInstanciation.With(prometheus.Labels{"name": g.Name}).Inc() } //create the leaky bucket per se @@ -208,7 +208,7 @@ func LeakRoutine(l *Leaky) { l.logger.Tracef("Pour event: %s", spew.Sdump(msg)) l.logger.Debugf("Pouring event.") - if l.Profiling == true { + if l.Profiling { BucketsPour.With(prometheus.Labels{"name": l.Name, "source": msg.Line.Src}).Inc() } l.Pour(l, msg) // glue for now @@ -236,7 +236,7 @@ func LeakRoutine(l *Leaky) { l.logger.Tracef("Overflow event: %s", spew.Sdump(types.Event{Overflow: sig})) mt, _ := l.Ovflw_ts.MarshalText() l.logger.Tracef("overflow time : %s", mt) - if l.Profiling == true { + if l.Profiling { BucketsOverflow.With(prometheus.Labels{"name": l.Name}).Inc() } l.AllOut <- types.Event{Overflow: sig, Type: types.OVFLW, MarshaledTime: string(mt)} @@ -249,7 +249,7 @@ func LeakRoutine(l *Leaky) { sig := types.SignalOccurence{MapKey: l.Mapkey} if l.timedOverflow { - if l.Profiling == true { + if l.Profiling { BucketsOverflow.With(prometheus.Labels{"name": l.Name}).Inc() } sig = FormatOverflow(l, ofw) diff --git a/pkg/leakybucket/buckets_test.go b/pkg/leakybucket/buckets_test.go index 368164716..371f8eae9 100644 --- a/pkg/leakybucket/buckets_test.go +++ b/pkg/leakybucket/buckets_test.go @@ -82,7 +82,10 @@ func testOneBucket(t *testing.T, dir string) error { files = append(files, x.Filename) } holders, response, err := LoadBuckets(files) - if testFile(t, dir+"/test.yaml", dir+"/in-buckets_state.json", holders, response) == false { + if err != nil { + t.Fatalf("failed loading bucket : %s", err) + } + if !testFile(t, dir+"/test.yaml", dir+"/in-buckets_state.json", holders, response) { t.Fatalf("the test failed") } return nil @@ -241,7 +244,7 @@ POLL_AGAIN: //CheckFailed: - if valid == true { + if valid { log.Warningf("The test is valid, remove entry %d from expects, and %d from t.Results", eidx, ridx) //don't do this at home : delete current element from list and redo results[eidx] = results[len(results)-1] @@ -252,7 +255,7 @@ POLL_AGAIN: } } } - if valid == false { + if !valid { t.Fatalf("mismatching entries left") } else { log.Warningf("entry valid at end of loop") diff --git a/pkg/leakybucket/manager.go b/pkg/leakybucket/manager.go index 977e920d5..377f1282a 100644 --- a/pkg/leakybucket/manager.go +++ b/pkg/leakybucket/manager.go @@ -189,7 +189,7 @@ func LoadBucketDir(dir string) ([]BucketFactory, chan types.Event, error) { /* Init recursively process yaml files from a directory and loads them as BucketFactory */ func LoadBucket(g *BucketFactory) error { var err error - if g.Debug == true { + if g.Debug { var clog = logrus.New() clog.SetFormatter(&log.TextFormatter{FullTimestamp: true}) clog.SetLevel(log.DebugLevel) @@ -326,12 +326,12 @@ func LoadBucketsState(file string, buckets *Buckets, holders []BucketFactory) er tbucket.Total_count = v.Total_count buckets.Bucket_map.Store(k, tbucket) go LeakRoutine(tbucket) - _ = <-tbucket.Signal + <-tbucket.Signal found = true break } } - if found == false { + if !found { log.Fatalf("Unable to find holder for bucket %s : %s", k, spew.Sdump(v)) } } @@ -530,7 +530,7 @@ func PourItemToHolders(parsed types.Event, holders []BucketFactory, buckets *Buc go LeakRoutine(fresh_bucket) log.Debugf("Created new bucket %s", buckey) //wait for signal to be opened - _ = <-fresh_bucket.Signal + <-fresh_bucket.Signal continue } diff --git a/pkg/leakybucket/overflow_filter.go b/pkg/leakybucket/overflow_filter.go index ec3a16be1..7df119d3f 100644 --- a/pkg/leakybucket/overflow_filter.go +++ b/pkg/leakybucket/overflow_filter.go @@ -50,7 +50,7 @@ func (u *OverflowFilter) OnBucketOverflow(Bucket *BucketFactory) func(*Leaky, ty return s, q } /*filter returned false, event is blackholded*/ - if element == false { + if !element { l.logger.Infof("Event is discard by overflow filter (%s)", u.Filter) return types.SignalOccurence{ MapKey: l.Mapkey, diff --git a/pkg/outputs/ouputs.go b/pkg/outputs/ouputs.go index 8f870d0dc..feaf33d52 100644 --- a/pkg/outputs/ouputs.go +++ b/pkg/outputs/ouputs.go @@ -35,11 +35,11 @@ func OvflwToOrder(sig types.SignalOccurence, prof types.Profile) (*types.BanOrde var warn error //Identify remediation type - if prof.Remediation.Ban == true { + if prof.Remediation.Ban { ordr.MeasureType = "ban" - } else if prof.Remediation.Slow == true { + } else if prof.Remediation.Slow { ordr.MeasureType = "slow" - } else if prof.Remediation.Captcha == true { + } else if prof.Remediation.Captcha { ordr.MeasureType = "captcha" } else { /*if the profil has no remediation, no order */ @@ -120,10 +120,10 @@ func (o *Output) ProcessOutput(sig types.SignalOccurence, profiles []types.Profi logger.Warningf("failed to run filter : %v", err) continue } - switch output.(type) { + switch out := output.(type) { case bool: /* filter returned false, don't process Node */ - if output.(bool) == false { + if !out { logger.Debugf("eval(FALSE) '%s'", profile.Filter) continue } @@ -158,7 +158,9 @@ func (o *Output) ProcessOutput(sig types.SignalOccurence, profiles []types.Profi // if ApiPush is nil (not specified in profile configuration) we use global api config (from default.yaml) if profile.ApiPush == nil { if o.API != nil { // if API is not nil, we can push - o.API.AppendSignal((sig)) + if err = o.API.AppendSignal((sig)); err != nil { + return fmt.Errorf("failed to append signal : %s", err) + } } } for _, outputConfig := range profile.OutputConfigs { @@ -173,7 +175,9 @@ func (o *Output) ProcessOutput(sig types.SignalOccurence, profiles []types.Profi continue } } - o.bManager.InsertOnePlugin(sig, pluginName) + if err = o.bManager.InsertOnePlugin(sig, pluginName); err != nil { + return fmt.Errorf("failed to insert plugin %s : %s", pluginName, err) + } } } } diff --git a/pkg/parser/node.go b/pkg/parser/node.go index 2d71afcc8..d51ce407c 100644 --- a/pkg/parser/node.go +++ b/pkg/parser/node.go @@ -92,7 +92,7 @@ func (n *Node) validate(pctx *UnixParserCtx) error { break } } - if method_found == false { + if !method_found { return fmt.Errorf("the method '%s' doesn't exist", static.Method) } } else { @@ -120,10 +120,10 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) { clog.Debugf("Event leaving node : ko") return false, nil } - switch output.(type) { + switch out := output.(type) { case bool: /* filter returned false, don't process Node */ - if output.(bool) == false { + if !out { NodeState = false clog.Debugf("eval(FALSE) '%s'", n.Filter) clog.Debugf("Event leaving node : ko") @@ -142,7 +142,7 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) { NodeState = true } - if n.Profiling == true && n.Name != "" { + if n.Profiling && n.Name != "" { NodesHits.With(prometheus.Labels{"source": p.Line.Src, "name": n.Name}).Inc() } set := false @@ -188,14 +188,14 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) { switch output.(type) { case bool: /* filter returned false, don't process Node */ - if output.(bool) == true { + if output.(bool) { clog.Infof("Event is whitelisted by Expr !") p.Whitelisted = true set = true } } } - if set == true { + if set { p.WhiteListReason = n.Whitelist.Reason /*huglily wipe the ban order if the event is whitelisted and it's an overflow */ if p.Type == types.OVFLW { /*don't do this at home kids */ @@ -217,7 +217,7 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) { return false, err } clog.Tracef("\tsub-node (%s) ret : %v (strategy:%s)", leaf.rn, ret, n.OnSuccess) - if ret == true { + if ret { NodeState = true /* if chil is successful, stop processing */ if n.OnSuccess == "next_stage" { @@ -280,15 +280,15 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) { } //grok or leafs failed, don't process statics - if NodeState == false { - if n.Profiling == true && n.Name != "" { + if !NodeState { + if n.Profiling && n.Name != "" { NodesHitsKo.With(prometheus.Labels{"source": p.Line.Src, "name": n.Name}).Inc() } clog.Debugf("Event leaving node : ko") return NodeState, nil } - if n.Profiling == true && n.Name != "" { + if n.Profiling && n.Name != "" { NodesHitsOk.With(prometheus.Labels{"source": p.Line.Src, "name": n.Name}).Inc() } if len(n.Statics) > 0 { @@ -302,7 +302,7 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) { clog.Tracef("! No node statics") } - if NodeState == true { + if NodeState { clog.Debugf("Event leaving node : ok") log.Tracef("node is successful, check strategy") if n.OnSuccess == "next_stage" { @@ -336,7 +336,7 @@ func (n *Node) compile(pctx *UnixParserCtx) error { log.Debugf("compile, node is %s", n.Stage) /* if the node has debugging enabled, create a specific logger with debug that will be used only for processing this node ;) */ - if n.Debug == true { + if n.Debug { var clog = logrus.New() clog.SetLevel(log.DebugLevel) n.logger = clog.WithFields(log.Fields{ @@ -414,10 +414,10 @@ func (n *Node) compile(pctx *UnixParserCtx) error { if len(n.SuccessNodes) > 0 { for idx, _ := range n.SuccessNodes { /*propagate debug/stats to child nodes*/ - if n.SuccessNodes[idx].Debug == false && n.Debug == true { + if !n.SuccessNodes[idx].Debug && n.Debug { n.SuccessNodes[idx].Debug = true } - if n.SuccessNodes[idx].Profiling == false && n.Profiling == true { + if !n.SuccessNodes[idx].Profiling && n.Profiling { n.SuccessNodes[idx].Profiling = true } n.SuccessNodes[idx].Stage = n.Stage @@ -468,7 +468,7 @@ func (n *Node) compile(pctx *UnixParserCtx) error { valid = true } - if valid == false { + if !valid { /* node is empty, error force return */ n.logger.Infof("Node is empty: %s", spew.Sdump(n)) n.Stage = "" diff --git a/pkg/parser/parsing_test.go b/pkg/parser/parsing_test.go index fe49fe1b1..61d141e32 100644 --- a/pkg/parser/parsing_test.go +++ b/pkg/parser/parsing_test.go @@ -48,7 +48,7 @@ func testOneParser(t *testing.T, dir string) error { var p UnixParser var pctx *UnixParserCtx var err error - var pnodes []Node = make([]Node, 0) + var pnodes []Node log.SetLevel(log.DebugLevel) @@ -64,7 +64,7 @@ func testOneParser(t *testing.T, dir string) error { //Init the enricher pplugins, err := Loadplugin(datadir) if err != nil { - return fmt.Errorf("Failed to load plugin geoip : %v", err) + return fmt.Errorf("failed to load plugin geoip : %v", err) } ECTX = append(ECTX, pplugins) log.Debugf("Geoip ctx : %v", ECTX) @@ -92,7 +92,7 @@ func testOneParser(t *testing.T, dir string) error { pnodes, err = LoadStages(parser_configs, pctx) if err != nil { - return fmt.Errorf("Unable to load parser config : %s", err) + return fmt.Errorf("unable to load parser config : %s", err) } //TBD: Load post overflows @@ -238,7 +238,7 @@ func testFile(t *testing.T, file string, pctx UnixParserCtx, nodes []Node) bool CheckFailed: - if valid == true { + if valid { //log.Infof("Found result [%s], skip", spew.Sdump(tf.Results[ridx])) log.Warningf("The test is valid, remove entry %d from expects, and %d from t.Results", eidx, ridx) //don't do this at home : delete current element from list and redo diff --git a/pkg/parser/runtime.go b/pkg/parser/runtime.go index 4e01a789c..e87871886 100644 --- a/pkg/parser/runtime.go +++ b/pkg/parser/runtime.go @@ -170,7 +170,7 @@ func ProcessStatics(statics []types.ExtraField, p *types.Event, clog *logrus.Ent clog.Warningf("method '%s' doesn't exist", static.Method) } } - if processed == false { + if !processed { clog.Warningf("method '%s' doesn't exist", static.Method) } } else if static.Parsed != "" { @@ -278,7 +278,7 @@ func /*(u types.UnixParser)*/ Parse(ctx UnixParserCtx, xp types.Event, nodes []N continue } clog.Tracef("Processing node %d/%d -> %s", idx, len(nodes), node.rn) - if ctx.Profiling == true { + if ctx.Profiling { node.Profiling = true } ret, err := node.process(&event, ctx) @@ -286,10 +286,10 @@ func /*(u types.UnixParser)*/ Parse(ctx UnixParserCtx, xp types.Event, nodes []N clog.Fatalf("Error while processing node : %v", err) } clog.Tracef("node (%s) ret : %v", node.rn, ret) - if ret == true { + if ret { isStageOK = true } - if ret == true && node.OnSuccess == "next_stage" { + if ret && node.OnSuccess == "next_stage" { clog.Debugf("node successful, stop end stage %s", stage) break } @@ -299,7 +299,7 @@ func /*(u types.UnixParser)*/ Parse(ctx UnixParserCtx, xp types.Event, nodes []N break } } - if isStageOK == false { + if !isStageOK { log.Debugf("Log didn't finish stage %s", event.Stage) event.Process = false return event, nil diff --git a/pkg/time/rate/rate_test.go b/pkg/time/rate/rate_test.go index b0ed34dfb..14b1ef32d 100644 --- a/pkg/time/rate/rate_test.go +++ b/pkg/time/rate/rate_test.go @@ -472,6 +472,8 @@ func BenchmarkWaitNNoDelay(b *testing.B) { b.ReportAllocs() b.ResetTimer() for i := 0; i < b.N; i++ { - lim.WaitN(ctx, 1) + if err := lim.WaitN(ctx, 1); err != nil { + b.Errorf("failed limiter : %s", err) + } } } From fe689146281049440b57a4de584cf225a0ea76a2 Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Wed, 20 May 2020 11:00:25 +0200 Subject: [PATCH 02/26] more linter fixes (simplicity mostly) --- cmd/crowdsec-cli/api.go | 8 ++------ cmd/crowdsec/acquisition.go | 3 ++- pkg/acquisition/file_reader.go | 4 ++-- pkg/leakybucket/bucket.go | 4 ++-- pkg/parser/node.go | 4 ++-- pkg/parser/runtime.go | 6 ++---- plugins/backend/sqlite.go | 6 +----- 7 files changed, 13 insertions(+), 22 deletions(-) diff --git a/cmd/crowdsec-cli/api.go b/cmd/crowdsec-cli/api.go index 1b9e73159..7ad35b554 100644 --- a/cmd/crowdsec-cli/api.go +++ b/cmd/crowdsec-cli/api.go @@ -10,7 +10,6 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/cwhub" "github.com/crowdsecurity/crowdsec/pkg/outputs" - "github.com/crowdsecurity/crowdsec/pkg/sqlite" "github.com/crowdsecurity/crowdsec/pkg/types" "github.com/denisbrodbeck/machineid" @@ -28,13 +27,10 @@ var ( var ( apiConfigFile = "api.yaml" + userID string // for flag parsing + outputCTX *outputs.Output ) -var userID string // for flag parsing -var dbctx *sqlite.Context - -var outputCTX *outputs.Output - func dumpCredentials() error { if config.output == "json" { credsYaml, err := json.Marshal(&outputCTX.API.Creds) diff --git a/cmd/crowdsec/acquisition.go b/cmd/crowdsec/acquisition.go index 55b1d411d..246cf3945 100644 --- a/cmd/crowdsec/acquisition.go +++ b/cmd/crowdsec/acquisition.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/crowdsecurity/crowdsec/pkg/acquisition" ) @@ -25,7 +26,7 @@ func loadAcquisition() (*acquisition.FileAcquisCtx, error) { if acquisitionCTX == nil { return nil, fmt.Errorf("no inputs to process") } - if cConfig.Profiling == true { + if cConfig.Profiling { acquisitionCTX.Profiling = true } diff --git a/pkg/acquisition/file_reader.go b/pkg/acquisition/file_reader.go index 186c27223..3c09a2a31 100644 --- a/pkg/acquisition/file_reader.go +++ b/pkg/acquisition/file_reader.go @@ -172,7 +172,7 @@ func AcquisStartReading(ctx *FileAcquisCtx, output chan types.Event, AcquisTomb /* start one go routine reading for each file, and pushing to chan output */ for idx, fctx := range ctx.Files { log.Printf("starting reader file %d/%d : %s", idx, len(ctx.Files), fctx.Filename) - if ctx.Profiling == true { + if ctx.Profiling { fctx.Profiling = true } fctx := fctx @@ -227,7 +227,7 @@ LOOP: if line.Text == "" { //skip empty lines continue } - if ctx.Profiling == true { + if ctx.Profiling { ReaderHits.With(prometheus.Labels{"source": ctx.Filename}).Inc() } l.Raw = line.Text diff --git a/pkg/leakybucket/bucket.go b/pkg/leakybucket/bucket.go index 183fed00b..18913f191 100644 --- a/pkg/leakybucket/bucket.go +++ b/pkg/leakybucket/bucket.go @@ -405,9 +405,9 @@ func FormatOverflow(l *Leaky, queue *Queue) types.SignalOccurence { am = fmt.Sprintf("%d IPs", len(sig.Sources)) } else if len(sig.Sources) == 1 { if sig.Source != nil { - am = fmt.Sprintf("%s", sig.Source.Ip.String()) + am = sig.Source.Ip.String() } else { - am = fmt.Sprintf("??") + am = "??" } } else { am = "UNKNOWN" diff --git a/pkg/parser/node.go b/pkg/parser/node.go index d51ce407c..98623561d 100644 --- a/pkg/parser/node.go +++ b/pkg/parser/node.go @@ -185,10 +185,10 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) { clog.Debugf("Event leaving node : ko") return false, nil } - switch output.(type) { + switch out := output.(type) { case bool: /* filter returned false, don't process Node */ - if output.(bool) { + if out { clog.Infof("Event is whitelisted by Expr !") p.Whitelisted = true set = true diff --git a/pkg/parser/runtime.go b/pkg/parser/runtime.go index e87871886..cfe6b2981 100644 --- a/pkg/parser/runtime.go +++ b/pkg/parser/runtime.go @@ -39,10 +39,9 @@ func SetTargetByName(target string, value string, evt *types.Event) bool { if evt == nil { return false } + //it's a hack, we do it for the user - if strings.HasPrefix(target, "evt.") { - target = target[4:] - } + target = strings.TrimPrefix(target, "evt.") log.Debugf("setting target %s to %s", target, value) defer func() { @@ -68,7 +67,6 @@ func SetTargetByName(target string, value string, evt *types.Event) bool { /*if we're in a map and the field doesn't exist, the user wants to add it :) */ if (tmp == reflect.Value{}) || tmp.IsZero() { log.Debugf("map entry is zero in '%s'", target) - //return false } iter.SetMapIndex(reflect.ValueOf(f), reflect.ValueOf(value)) return true diff --git a/plugins/backend/sqlite.go b/plugins/backend/sqlite.go index 8b8579c74..0af1343eb 100644 --- a/plugins/backend/sqlite.go +++ b/plugins/backend/sqlite.go @@ -28,7 +28,7 @@ func (p *pluginDB) Delete(target string) (int, error) { if err != nil { return 0, err } - log.Debugf("deleted '%s' entry from database", nbDel) + log.Debugf("deleted '%d' entry from database", nbDel) return nbDel, nil } @@ -65,9 +65,5 @@ func (p *pluginDB) ReadAT(timeAT time.Time) ([]map[string]string, error) { return ret, nil } -func New() interface{} { - return &pluginDB{} -} - // empty main function is mandatory since we are in a main package func main() {} From e6cad40ac47ffc6f4bdd19026074e4a4a606e777 Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Wed, 20 May 2020 11:26:21 +0200 Subject: [PATCH 03/26] more linting fixes --- pkg/leakybucket/buckets_test.go | 7 ------- pkg/parser/node.go | 6 +++--- pkg/parser/runtime.go | 6 +++--- pkg/sqlite/stats.go | 6 +++--- pkg/time/rate/rate_test.go | 2 +- 5 files changed, 10 insertions(+), 17 deletions(-) diff --git a/pkg/leakybucket/buckets_test.go b/pkg/leakybucket/buckets_test.go index 371f8eae9..1787fe818 100644 --- a/pkg/leakybucket/buckets_test.go +++ b/pkg/leakybucket/buckets_test.go @@ -22,11 +22,6 @@ type TestFile struct { Results []types.Event `yaml:"results,omitempty"` } -func testBucketStates() { - //same as a scenario, but load a bucket state first ? - -} - func TestBucket(t *testing.T) { var envSetting = os.Getenv("TEST_ONLY") @@ -261,7 +256,5 @@ POLL_AGAIN: log.Warningf("entry valid at end of loop") } } - - t.Errorf("failed test") return false } diff --git a/pkg/parser/node.go b/pkg/parser/node.go index 98623561d..1c7d2127c 100644 --- a/pkg/parser/node.go +++ b/pkg/parser/node.go @@ -399,7 +399,7 @@ func (n *Node) compile(pctx *UnixParserCtx) error { /* load grok statics */ if len(n.Grok.Statics) > 0 { //compile expr statics if present - for idx, _ := range n.Grok.Statics { + for idx := range n.Grok.Statics { if n.Grok.Statics[idx].ExpValue != "" { n.Grok.Statics[idx].RunTimeValue, err = expr.Compile(n.Grok.Statics[idx].ExpValue, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}}))) @@ -412,7 +412,7 @@ func (n *Node) compile(pctx *UnixParserCtx) error { } /* compile leafs if present */ if len(n.SuccessNodes) > 0 { - for idx, _ := range n.SuccessNodes { + for idx := range n.SuccessNodes { /*propagate debug/stats to child nodes*/ if !n.SuccessNodes[idx].Debug && n.Debug { n.SuccessNodes[idx].Debug = true @@ -432,7 +432,7 @@ func (n *Node) compile(pctx *UnixParserCtx) error { valid = true } /* load statics if present */ - for idx, _ := range n.Statics { + for idx := range n.Statics { if n.Statics[idx].ExpValue != "" { n.Statics[idx].RunTimeValue, err = expr.Compile(n.Statics[idx].ExpValue, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}}))) if err != nil { diff --git a/pkg/parser/runtime.go b/pkg/parser/runtime.go index cfe6b2981..702356120 100644 --- a/pkg/parser/runtime.go +++ b/pkg/parser/runtime.go @@ -128,11 +128,11 @@ func ProcessStatics(statics []types.ExtraField, p *types.Event, clog *logrus.Ent clog.Warningf("failed to run RunTimeValue : %v", err) continue } - switch output.(type) { + switch out := output.(type) { case string: - value = output.(string) + value = out case int: - value = strconv.Itoa(output.(int)) + value = strconv.Itoa(out) default: clog.Fatalf("unexpected return type for RunTimeValue : %T", output) return errors.New("unexpected return type for RunTimeValue") diff --git a/pkg/sqlite/stats.go b/pkg/sqlite/stats.go index 2a50767f8..c51a6086d 100644 --- a/pkg/sqlite/stats.go +++ b/pkg/sqlite/stats.go @@ -107,7 +107,7 @@ func (c *Context) GetBansAt(at time.Time) ([]map[string]string, error) { bancom["source"] = ba.MeasureSource bancom["events_count"] = "0" bancom["action"] = ba.MeasureType - bancom["until"] = fmt.Sprintf("%s", ba.Until.Sub(time.Now()).Round(time.Second)) + bancom["until"] = time.Until(ba.Until).Round(time.Second).String() bancom["reason"] = ba.Reason rets = append(rets, bancom) continue @@ -134,7 +134,7 @@ func (c *Context) GetBansAt(at time.Time) ([]map[string]string, error) { bancom["scenario"] = "?" bancom["events_count"] = "0" bancom["action"] = ba.MeasureType - bancom["until"] = fmt.Sprintf("%s", ba.Until.Sub(time.Now()).Round(time.Second)) + bancom["until"] = time.Until(ba.Until).Round(time.Second).String() bancom["reason"] = ba.Reason rets = append(rets, bancom) continue @@ -155,7 +155,7 @@ func (c *Context) GetBansAt(at time.Time) ([]map[string]string, error) { bancom["events_count"] = fmt.Sprintf("%d", evtCount) bancom["action"] = ba.MeasureType bancom["source"] = ba.MeasureSource - bancom["until"] = fmt.Sprintf("%s", ba.Until.Sub(time.Now()).Round(time.Second)) + bancom["until"] = time.Until(ba.Until).Round(time.Second).String() bancom["reason"] = so.Scenario rets = append(rets, bancom) } diff --git a/pkg/time/rate/rate_test.go b/pkg/time/rate/rate_test.go index 14b1ef32d..460078723 100644 --- a/pkg/time/rate/rate_test.go +++ b/pkg/time/rate/rate_test.go @@ -400,7 +400,7 @@ type wait struct { func runWait(t *testing.T, lim *Limiter, w wait) { start := time.Now() err := lim.WaitN(w.ctx, w.n) - delay := time.Now().Sub(start) + delay := time.Since(start) if (w.nilErr && err != nil) || (!w.nilErr && err == nil) || w.delay != dFromDuration(delay) { errString := "" if !w.nilErr { From ea289e9518ba4ed462837762e6be5983e29fcbaf Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Wed, 20 May 2020 13:48:21 +0200 Subject: [PATCH 04/26] don't trash this function as it's used by plguins --- plugins/backend/sqlite.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/backend/sqlite.go b/plugins/backend/sqlite.go index 0af1343eb..db711aeec 100644 --- a/plugins/backend/sqlite.go +++ b/plugins/backend/sqlite.go @@ -65,5 +65,9 @@ func (p *pluginDB) ReadAT(timeAT time.Time) ([]map[string]string, error) { return ret, nil } +func New() interface{} { + return &pluginDB{} +} + // empty main function is mandatory since we are in a main package func main() {} From 37caed01590047014ba6fa9382ccc1a6bf87992c Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Wed, 20 May 2020 16:29:51 +0200 Subject: [PATCH 05/26] golangci-lint action --- .github/workflows/golangci-lint.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/golangci-lint.yml diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 000000000..a5588c6e5 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,20 @@ +name: golangci-lint +on: + push: + tags: + - v* + branches: + - master + pull_request: +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v1 + with: + # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. + version: v1.26 + From c3ed78805b2b3a90fdd6ee03c97565899ab78baa Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Wed, 20 May 2020 16:43:19 +0200 Subject: [PATCH 06/26] use latest version --- .github/workflows/golangci-lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index a5588c6e5..36e88de7c 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -16,5 +16,5 @@ jobs: uses: golangci/golangci-lint-action@v1 with: # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.26 + version: v1.27 From d00e0c5f38026496249c7c45623c0fc64d9e8f52 Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Wed, 20 May 2020 16:50:28 +0200 Subject: [PATCH 07/26] comment golangci-lint action --- .github/workflows/golangci-lint.yml | 38 ++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 36e88de7c..231920960 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -1,20 +1,20 @@ -name: golangci-lint -on: - push: - tags: - - v* - branches: - - master - pull_request: -jobs: - golangci: - name: lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: golangci-lint - uses: golangci/golangci-lint-action@v1 - with: - # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.27 +# name: golangci-lint +# on: +# push: +# tags: +# - v* +# branches: +# - master +# pull_request: +# jobs: +# golangci: +# name: lint +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v2 +# - name: golangci-lint +# uses: golangci/golangci-lint-action@v1 +# with: +# # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. +# version: v1.27 From a827f795d6037e3ed6a431597399936e0d23b148 Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Wed, 20 May 2020 16:53:16 +0200 Subject: [PATCH 08/26] remove --- .github/workflows/golangci-lint.yml | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 .github/workflows/golangci-lint.yml diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml deleted file mode 100644 index 231920960..000000000 --- a/.github/workflows/golangci-lint.yml +++ /dev/null @@ -1,20 +0,0 @@ -# name: golangci-lint -# on: -# push: -# tags: -# - v* -# branches: -# - master -# pull_request: -# jobs: -# golangci: -# name: lint -# runs-on: ubuntu-latest -# steps: -# - uses: actions/checkout@v2 -# - name: golangci-lint -# uses: golangci/golangci-lint-action@v1 -# with: -# # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. -# version: v1.27 - From 307f1c0e9eb91c504ee10ecc7fe004fd32def67e Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Wed, 20 May 2020 17:31:38 +0200 Subject: [PATCH 09/26] add again now that actions are working --- .github/workflows/golangci-lint.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/golangci-lint.yml diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 000000000..68d173f07 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,22 @@ +name: golangci-lint +on: + push: + tags: + - v* + branches: + - master + pull_request: +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v1 + with: + # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. + version: v1.26 + + # Optional: golangci-lint command line arguments. + # args: ./the-only-dir-to-analyze/... From e643bb5b31ffcd57193822ac01dfc7a4d2c0cd00 Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Wed, 20 May 2020 17:50:56 +0200 Subject: [PATCH 10/26] linter fixes, inefficient assignments --- cmd/crowdsec-cli/main.go | 4 +++- cmd/crowdsec/serve.go | 2 +- pkg/cwapi/auth.go | 2 +- pkg/leakybucket/buckets_test.go | 3 --- pkg/parser/node.go | 7 +------ pkg/parser/runtime.go | 4 ++-- plugins/backend/sqlite.go | 2 ++ 7 files changed, 10 insertions(+), 14 deletions(-) diff --git a/cmd/crowdsec-cli/main.go b/cmd/crowdsec-cli/main.go index 9f80c70c5..07c3474df 100644 --- a/cmd/crowdsec-cli/main.go +++ b/cmd/crowdsec-cli/main.go @@ -93,7 +93,9 @@ API interaction: Args: cobra.ExactArgs(0), Hidden: true, Run: func(cmd *cobra.Command, args []string) { - doc.GenMarkdownTree(rootCmd, "./doc/") + if err := doc.GenMarkdownTree(rootCmd, "./doc/"); err != nil { + log.Fatalf("Failed to generate cobra doc") + } }, } rootCmd.AddCommand(cmdDocGen) diff --git a/cmd/crowdsec/serve.go b/cmd/crowdsec/serve.go index 61a07600e..cbdd8486a 100644 --- a/cmd/crowdsec/serve.go +++ b/cmd/crowdsec/serve.go @@ -69,7 +69,7 @@ func serveDaemon() error { if d != nil { return nil } - defer daemonCTX.Release() + defer daemonCTX.Release() //nolint:errcheck err = daemon.ServeSignals() if err != nil { return fmt.Errorf("serveDaemon error : %s", err.Error()) diff --git a/pkg/cwapi/auth.go b/pkg/cwapi/auth.go index ee9a49f17..a08fe1358 100644 --- a/pkg/cwapi/auth.go +++ b/pkg/cwapi/auth.go @@ -113,7 +113,7 @@ func (ctx *ApiCtx) Init(cfg string, profile string) error { return err } //start the background go-routine - go ctx.pushLoop() + go ctx.pushLoop() //nolint:errcheck return nil } diff --git a/pkg/leakybucket/buckets_test.go b/pkg/leakybucket/buckets_test.go index 1787fe818..3353780d7 100644 --- a/pkg/leakybucket/buckets_test.go +++ b/pkg/leakybucket/buckets_test.go @@ -216,7 +216,6 @@ POLL_AGAIN: continue } else { log.Infof("(scenario) %s == %s", out.Overflow.Scenario, expected.Overflow.Scenario) - valid = true } //Events_count if out.Overflow.Events_count != expected.Overflow.Events_count { @@ -225,7 +224,6 @@ POLL_AGAIN: continue } else { log.Infof("(Events_count) %d == %d", out.Overflow.Events_count, expected.Overflow.Events_count) - valid = true } //Source_ip if out.Overflow.Source_ip != expected.Overflow.Source_ip { @@ -234,7 +232,6 @@ POLL_AGAIN: continue } else { log.Infof("(Source_ip) %s == %s", out.Overflow.Source_ip, expected.Overflow.Source_ip) - valid = true } //CheckFailed: diff --git a/pkg/parser/node.go b/pkg/parser/node.go index 1c7d2127c..c96a40bd8 100644 --- a/pkg/parser/node.go +++ b/pkg/parser/node.go @@ -108,7 +108,7 @@ func (n *Node) validate(pctx *UnixParserCtx) error { } func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) { - var NodeState bool = true + var NodeState bool clog := n.logger clog.Debugf("Event entering node") @@ -124,7 +124,6 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) { case bool: /* filter returned false, don't process Node */ if !out { - NodeState = false clog.Debugf("eval(FALSE) '%s'", n.Filter) clog.Debugf("Event leaving node : ko") return false, nil @@ -132,7 +131,6 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) { default: clog.Warningf("Expr '%s' returned non-bool, abort : %T", n.Filter, output) clog.Debugf("Event leaving node : ko") - NodeState = false return false, nil } NodeState = true @@ -424,10 +422,7 @@ func (n *Node) compile(pctx *UnixParserCtx) error { err = n.SuccessNodes[idx].compile(pctx) if err != nil { return err - } else { - //n.logger.Debugf("Leaf compilation suceeded: %v\n", n.SuccessNodes[idx]) } - //set child node to parent stage } valid = true } diff --git a/pkg/parser/runtime.go b/pkg/parser/runtime.go index 702356120..b255f21c0 100644 --- a/pkg/parser/runtime.go +++ b/pkg/parser/runtime.go @@ -228,8 +228,8 @@ func stageidx(stage string, stages []string) int { } func /*(u types.UnixParser)*/ Parse(ctx UnixParserCtx, xp types.Event, nodes []Node) (types.Event, error) { - var event types.Event - event = xp + var event types.Event = xp + /* the stage is undefined, probably line is freshly acquired, set to first stage !*/ if event.Stage == "" && len(ctx.Stages) > 0 { event.Stage = ctx.Stages[0] diff --git a/plugins/backend/sqlite.go b/plugins/backend/sqlite.go index db711aeec..7db8e2aa2 100644 --- a/plugins/backend/sqlite.go +++ b/plugins/backend/sqlite.go @@ -8,6 +8,7 @@ import ( log "github.com/sirupsen/logrus" ) +//nolint:unused // pluginDB is the interface for sqlite output plugin type pluginDB struct { CTX *sqlite.Context } @@ -65,6 +66,7 @@ func (p *pluginDB) ReadAT(timeAT time.Time) ([]map[string]string, error) { return ret, nil } +//nolint:unused // New is used by the plugin system func New() interface{} { return &pluginDB{} } From e86b163ba5296917ada4021e01f6ab658a99022a Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Wed, 20 May 2020 18:05:05 +0200 Subject: [PATCH 11/26] linter fixes --- cmd/crowdsec-cli/api.go | 5 ----- pkg/acquisition/file_reader.go | 1 - plugins/backend/sqlite.go | 2 +- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/cmd/crowdsec-cli/api.go b/cmd/crowdsec-cli/api.go index 7ad35b554..355faa043 100644 --- a/cmd/crowdsec-cli/api.go +++ b/cmd/crowdsec-cli/api.go @@ -185,7 +185,6 @@ cscli api credentials # Display your API credentials } fmt.Printf("machine_id: %s\n", outputCTX.API.Creds.User) fmt.Printf("password: %s\n", outputCTX.API.Creds.Password) - return }, } @@ -202,7 +201,6 @@ cscli api credentials # Display your API credentials if err := outputCTX.API.Enroll(userID); err != nil { log.Fatalf(err.Error()) } - return }, } @@ -223,7 +221,6 @@ cscli api credentials # Display your API credentials } fmt.Printf("machine_id: %s\n", outputCTX.API.Creds.User) fmt.Printf("password: %s\n", outputCTX.API.Creds.Password) - return }, } @@ -241,7 +238,6 @@ cscli api credentials # Display your API credentials if err != nil { log.Fatalf(err.Error()) } - return }, } @@ -255,7 +251,6 @@ cscli api credentials # Display your API credentials if err := dumpCredentials(); err != nil { log.Fatalf(err.Error()) } - return }, } diff --git a/pkg/acquisition/file_reader.go b/pkg/acquisition/file_reader.go index 3c09a2a31..116ab2fab 100644 --- a/pkg/acquisition/file_reader.go +++ b/pkg/acquisition/file_reader.go @@ -190,7 +190,6 @@ func AcquisStartReading(ctx *FileAcquisCtx, output chan types.Event, AcquisTomb } } log.Printf("Started %d routines for polling/read", len(ctx.Files)) - return } /*A tail-mode file reader (tail) */ diff --git a/plugins/backend/sqlite.go b/plugins/backend/sqlite.go index 7db8e2aa2..ec6dfe4be 100644 --- a/plugins/backend/sqlite.go +++ b/plugins/backend/sqlite.go @@ -66,7 +66,7 @@ func (p *pluginDB) ReadAT(timeAT time.Time) ([]map[string]string, error) { return ret, nil } -//nolint:unused // New is used by the plugin system +//nolint:deadcode,unused // New is used by the plugin system func New() interface{} { return &pluginDB{} } From 181dfa41b3314528e562ddef8e1044148425a1fa Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Wed, 20 May 2020 18:12:28 +0200 Subject: [PATCH 12/26] only lint new code --- .github/workflows/golangci-lint.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 68d173f07..07771f4f5 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -19,4 +19,5 @@ jobs: version: v1.26 # Optional: golangci-lint command line arguments. - # args: ./the-only-dir-to-analyze/... + args: -n + From 4d4993b75e0b5b236be0e94725ff4ea906d9cfd2 Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Wed, 20 May 2020 18:17:09 +0200 Subject: [PATCH 13/26] only lint new code --- .github/workflows/golangci-lint.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 07771f4f5..0d350df89 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -19,5 +19,6 @@ jobs: version: v1.26 # Optional: golangci-lint command line arguments. - args: -n + args: --new-from-rev=HEAD~ + From 4804ba567c303d8cdc866af93eee7427e906d58c Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Wed, 20 May 2020 18:21:54 +0200 Subject: [PATCH 14/26] add key for diff --- .github/workflows/golangci-lint.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 0d350df89..7936ecde6 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -20,5 +20,6 @@ jobs: # Optional: golangci-lint command line arguments. args: --new-from-rev=HEAD~ - + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From dc2b350b0482c97be38d139ae1a1c09829bc436e Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Wed, 20 May 2020 19:25:34 +0200 Subject: [PATCH 15/26] add verbose output --- .github/workflows/golangci-lint.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 7936ecde6..4065b07ae 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -19,7 +19,6 @@ jobs: version: v1.26 # Optional: golangci-lint command line arguments. - args: --new-from-rev=HEAD~ - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + args: -v --new-from-rev=HEAD~ + From 026bb223e0d2d749a6f9b0649d31fdc2cfa1481d Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Thu, 21 May 2020 09:20:37 +0200 Subject: [PATCH 16/26] check git present --- .github/workflows/golangci-lint.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 4065b07ae..7bc4fdfa0 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -11,7 +11,10 @@ jobs: name: lint runs-on: ubuntu-latest steps: + - name: check_git + run: git --version - uses: actions/checkout@v2 + - name: golangci-lint uses: golangci/golangci-lint-action@v1 with: From 7a2e8dfacd9d5bb8ce19eca5d9d5c12efadb21b8 Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Thu, 21 May 2020 10:08:17 +0200 Subject: [PATCH 17/26] try to mimic golangci-lint git behaviour --- .github/workflows/golangci-lint.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 7bc4fdfa0..220d2cd18 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -12,9 +12,8 @@ jobs: runs-on: ubuntu-latest steps: - name: check_git - run: git --version + run: git diff --relative HEAD~ - uses: actions/checkout@v2 - - name: golangci-lint uses: golangci/golangci-lint-action@v1 with: From 7e61c809f7d829be4b9babe8cef4fe278bf4f0ef Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Thu, 21 May 2020 10:09:25 +0200 Subject: [PATCH 18/26] try to mimic golangci-lint git behaviour --- .github/workflows/golangci-lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 220d2cd18..f873271f0 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -11,9 +11,9 @@ jobs: name: lint runs-on: ubuntu-latest steps: + - uses: actions/checkout@v2 - name: check_git run: git diff --relative HEAD~ - - uses: actions/checkout@v2 - name: golangci-lint uses: golangci/golangci-lint-action@v1 with: From 060ceb0dc7071262f758405698113e3728b697e6 Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Thu, 21 May 2020 10:28:06 +0200 Subject: [PATCH 19/26] git diff --- .github/workflows/golangci-lint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index f873271f0..1f8d8fc95 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -13,7 +13,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: check_git - run: git diff --relative HEAD~ + run: git diff --relative remotes/origin/master - name: golangci-lint uses: golangci/golangci-lint-action@v1 with: @@ -21,6 +21,6 @@ jobs: version: v1.26 # Optional: golangci-lint command line arguments. - args: -v --new-from-rev=HEAD~ + args: -v --new-from-rev=remotes/origin/master From 70356221466925e7f7b66c12564d99896dbb7bf0 Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Thu, 21 May 2020 10:31:42 +0200 Subject: [PATCH 20/26] fetch master --- .github/workflows/golangci-lint.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 1f8d8fc95..d5fcb9ef5 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -12,6 +12,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - name: git_fetch + run: git fetch origin master - name: check_git run: git diff --relative remotes/origin/master - name: golangci-lint From 193f2fd5d67be52318936a609124e5a111dc817e Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Thu, 21 May 2020 10:33:40 +0200 Subject: [PATCH 21/26] force error in diff --- cmd/crowdsec-cli/main.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmd/crowdsec-cli/main.go b/cmd/crowdsec-cli/main.go index 07c3474df..3bd25f6e1 100644 --- a/cmd/crowdsec-cli/main.go +++ b/cmd/crowdsec-cli/main.go @@ -15,6 +15,11 @@ import ( "gopkg.in/yaml.v2" ) +//This is some dead code +func DeadCodeTest() { + return +} + var dbg_lvl, nfo_lvl, wrn_lvl, err_lvl bool var config cliConfig From c37714f4a513e627a0db911620ed3198da03da12 Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Thu, 21 May 2020 10:38:06 +0200 Subject: [PATCH 22/26] remove dead code --- cmd/crowdsec-cli/main.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/cmd/crowdsec-cli/main.go b/cmd/crowdsec-cli/main.go index 3bd25f6e1..07c3474df 100644 --- a/cmd/crowdsec-cli/main.go +++ b/cmd/crowdsec-cli/main.go @@ -15,11 +15,6 @@ import ( "gopkg.in/yaml.v2" ) -//This is some dead code -func DeadCodeTest() { - return -} - var dbg_lvl, nfo_lvl, wrn_lvl, err_lvl bool var config cliConfig From 14c6ce1353f78df3c81b7346fee89e7cdb2a56fd Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Fri, 22 May 2020 09:50:15 +0200 Subject: [PATCH 23/26] try fixed version of golangci-lint --- .github/workflows/golangci-lint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index d5fcb9ef5..bb15016c3 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -21,8 +21,8 @@ jobs: with: # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. version: v1.26 - # Optional: golangci-lint command line arguments. - args: -v --new-from-rev=remotes/origin/master + #args: -v --new-from-rev=remotes/origin/master + only-new-issues: true From 5971b9ab40a0b37dff8a9e9dd18a1cf44894608b Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Fri, 22 May 2020 09:54:08 +0200 Subject: [PATCH 24/26] ensure linter is still ok --- cmd/crowdsec-cli/dashboard.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/crowdsec-cli/dashboard.go b/cmd/crowdsec-cli/dashboard.go index 21bee6c46..a6329b5f5 100644 --- a/cmd/crowdsec-cli/dashboard.go +++ b/cmd/crowdsec-cli/dashboard.go @@ -43,6 +43,10 @@ var ( defaultEmail = "metabase@crowdsec.net" ) +func thisIsDeadCode() { + //yep dead code to check linter +} + func NewDashboardCmd() *cobra.Command { /* ---- UPDATE COMMAND */ var cmdDashboard = &cobra.Command{ From 356ce3e7f95ea2c34949991d523a7fa082e83604 Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Fri, 22 May 2020 09:59:35 +0200 Subject: [PATCH 25/26] yep all good --- .github/workflows/golangci-lint.yml | 5 ----- cmd/crowdsec-cli/dashboard.go | 4 ---- 2 files changed, 9 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index bb15016c3..80bdd411a 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -12,17 +12,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: git_fetch - run: git fetch origin master - - name: check_git - run: git diff --relative remotes/origin/master - name: golangci-lint uses: golangci/golangci-lint-action@v1 with: # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. version: v1.26 # Optional: golangci-lint command line arguments. - #args: -v --new-from-rev=remotes/origin/master only-new-issues: true diff --git a/cmd/crowdsec-cli/dashboard.go b/cmd/crowdsec-cli/dashboard.go index a6329b5f5..21bee6c46 100644 --- a/cmd/crowdsec-cli/dashboard.go +++ b/cmd/crowdsec-cli/dashboard.go @@ -43,10 +43,6 @@ var ( defaultEmail = "metabase@crowdsec.net" ) -func thisIsDeadCode() { - //yep dead code to check linter -} - func NewDashboardCmd() *cobra.Command { /* ---- UPDATE COMMAND */ var cmdDashboard = &cobra.Command{ From ada5d3fcfea16f6f65cd0a873499fbff9dc5f182 Mon Sep 17 00:00:00 2001 From: Thibault bui Koechlin Date: Fri, 22 May 2020 10:12:35 +0200 Subject: [PATCH 26/26] explain linter bypasses --- cmd/crowdsec/serve.go | 2 +- pkg/cwapi/auth.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/crowdsec/serve.go b/cmd/crowdsec/serve.go index cbdd8486a..64dee17d1 100644 --- a/cmd/crowdsec/serve.go +++ b/cmd/crowdsec/serve.go @@ -69,7 +69,7 @@ func serveDaemon() error { if d != nil { return nil } - defer daemonCTX.Release() //nolint:errcheck + defer daemonCTX.Release() //nolint:errcheck // won't bother checking this error in defer statement err = daemon.ServeSignals() if err != nil { return fmt.Errorf("serveDaemon error : %s", err.Error()) diff --git a/pkg/cwapi/auth.go b/pkg/cwapi/auth.go index a08fe1358..208664220 100644 --- a/pkg/cwapi/auth.go +++ b/pkg/cwapi/auth.go @@ -113,7 +113,7 @@ func (ctx *ApiCtx) Init(cfg string, profile string) error { return err } //start the background go-routine - go ctx.pushLoop() //nolint:errcheck + go ctx.pushLoop() //nolint:errcheck // runs into the background, we can't check error with chan or such return nil }