Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Mar 19, 2024
1 parent ffb2f47 commit b509b94
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 18 deletions.
24 changes: 18 additions & 6 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 All @@ -18,7 +19,6 @@ import (

"github.com/crowdsecurity/crowdsec/pkg/models"
csbouncer "github.com/crowdsecurity/go-cs-bouncer"

"github.com/crowdsecurity/go-cs-lib/version"

"github.com/crowdsecurity/cs-aws-waf-bouncer/pkg/cfg"
Expand All @@ -30,8 +30,8 @@ var wafInstances = make([]*waf.WAF, 0)
func resourceCleanup() {
for _, w := range wafInstances {
w.Logger.Infof("Cleaning up resources")
err := w.Cleanup()
if err != nil {

if err := w.Cleanup(); err != nil {
log.Errorf("Error cleaning up WAF: %s", err)
}
}
Expand All @@ -45,13 +45,14 @@ 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()
}

return nil
}

Expand Down Expand Up @@ -136,6 +137,7 @@ func Execute() error {
}

configBytes := []byte{}

var err error

if configPath != nil && *configPath != "" {
Expand Down Expand Up @@ -169,12 +171,15 @@ func Execute() error {
if *testConfig {
for _, wafConfig := range config.WebACLConfig {
log.Debugf("Create WAF instance with config: %+v", wafConfig)

_, err := waf.NewWaf(wafConfig)
if err != nil {
return fmt.Errorf("configuration error: %w", err)
}
}

log.Info("valid config")

return nil
}

Expand All @@ -198,17 +203,21 @@ func Execute() error {

for _, wafConfig := range config.WebACLConfig {
log.Debugf("Create WAF instance with config: %+v", wafConfig)

w, err := waf.NewWaf(wafConfig)
if err != nil {
return fmt.Errorf("could not create waf instance: %w", err)
}

err = w.Init()
if err != nil {
if os.Getenv("CS_AWS_WAF_BOUNCER_TESTING") == "" {
return fmt.Errorf("could not initialize waf instance: %w", err)
}

log.Errorf("could not initialize waf instance: %v+", err)
}

wafInstances = append(wafInstances, w)
}

Expand All @@ -220,7 +229,7 @@ func Execute() error {

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

if config.Daemon {
Expand All @@ -232,13 +241,16 @@ func Execute() error {

g.Go(func() error {
log.Info("Starting processing decisions")

for {
select {
case <-ctx.Done():
log.Info("terminating bouncer process")

for _, w := range wafInstances {
w.T.Kill(nil)
}

return nil
case decisions := <-bouncer.Stream:
log.Info("Polling decisions")
Expand Down
Loading

0 comments on commit b509b94

Please sign in to comment.