Skip to content

Commit

Permalink
lint (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc authored Mar 18, 2024
1 parent bd05c89 commit 0ef82b9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: v1.55
version: v1.56
args: --issues-exit-code=1 --timeout 10m
only-new-issues: false
# the cache is already managed above, enabling it here
Expand Down
13 changes: 8 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"bytes"
"context"
"errors"
"flag"
"fmt"
"os"
Expand Down Expand Up @@ -33,9 +34,9 @@ func HandleSignals(ctx context.Context) error {
case s := <-signalChan:
switch s {
case syscall.SIGTERM:
return fmt.Errorf("received SIGTERM")
return errors.New("received SIGTERM")
case os.Interrupt: // cross-platform SIGINT
return fmt.Errorf("received interrupt")
return errors.New("received interrupt")
}
case <-ctx.Done():
return ctx.Err()
Expand All @@ -60,7 +61,7 @@ func Execute() error {
}

if configPath == nil || *configPath == "" {
return fmt.Errorf("configuration file is required")
return errors.New("configuration file is required")
}

configBytes, err := cfg.MergedConfig(*configPath)
Expand Down Expand Up @@ -101,7 +102,7 @@ func Execute() error {
ScenariosNotContaining: strings.Join(config.CrowdsecConfig.ExcludeScenariosContaining, ","),
Origins: strings.Join(config.CrowdsecConfig.OnlyIncludeDecisionsFrom, ","),
},
UserAgent: fmt.Sprintf("crowdsec-blocklist-mirror/%s", version.String()),
UserAgent: "crowdsec-blocklist-mirror/" + version.String(),
CertPath: config.CrowdsecConfig.CertPath,
KeyPath: config.CrowdsecConfig.KeyPath,
CAPath: config.CrowdsecConfig.CAPath,
Expand All @@ -121,7 +122,7 @@ func Execute() error {

g.Go(func() error {
decisionStreamer.Run(ctx)
return fmt.Errorf("bouncer stream halted")
return errors.New("bouncer stream halted")
})

g.Go(func() error {
Expand All @@ -148,10 +149,12 @@ func Execute() error {
if decisions == nil {
continue
}

if len(decisions.New) > 0 {
log.Infof("received %d new decisions", len(decisions.New))
registry.GlobalDecisionRegistry.AddDecisions(decisions.New)
}

if len(decisions.Deleted) > 0 {
log.Infof("received %d expired decisions", len(decisions.Deleted))
registry.GlobalDecisionRegistry.DeleteDecisions(decisions.Deleted)
Expand Down
5 changes: 3 additions & 2 deletions pkg/cfg/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cfg

import (
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -66,11 +67,11 @@ type Config struct {

func (cfg *Config) ValidateAndSetDefaults() error {
if cfg.CrowdsecConfig.LapiKey == "" && cfg.CrowdsecConfig.CertPath == "" {
return fmt.Errorf("one of lapi_key or cert_path is required")
return errors.New("one of lapi_key or cert_path is required")
}

if cfg.CrowdsecConfig.LapiURL == "" {
return fmt.Errorf("lapi_url is required")
return errors.New("lapi_url is required")
}

if !strings.HasSuffix(cfg.CrowdsecConfig.LapiURL, "/") {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cfg/logging.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cfg

import (
"fmt"
"errors"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -75,7 +75,7 @@ func (c *LoggingConfig) setDefaults() {

func (c *LoggingConfig) validate() error {
if c.LogMedia != "stdout" && c.LogMedia != "file" {
return fmt.Errorf("log_media should be either 'stdout' or 'file'")
return errors.New("log_media should be either 'stdout' or 'file'")
}

return nil
Expand Down
2 changes: 2 additions & 0 deletions pkg/server/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,14 @@ func appendQuoted(buf []byte, s string) []byte {
if r == rune('"') || r == '\\' { // always backslashed
buf = append(buf, '\\')
buf = append(buf, byte(r))

continue
}

if strconv.IsPrint(r) {
n := utf8.EncodeRune(runeTmp[:], r)
buf = append(buf, runeTmp[:n]...)

continue
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func satisfiesBasicAuth(r *http.Request, user, password string) bool {
return false
}

expectedVal := fmt.Sprintf("Basic %s", basicAuth(user, password))
expectedVal := "Basic " + basicAuth(user, password)
foundVal := r.Header[http.CanonicalHeaderKey("Authorization")][0]
log.WithFields(log.Fields{
"expected": expectedVal,
Expand Down

0 comments on commit 0ef82b9

Please sign in to comment.