Add a logger instance to bouncer instance (#134)

*  Add a logger instance to bouncer instance

* 🍱 fix test

* 🍱 fix lint

* 🍱 fix lint

* 🍱 fix lint

* 🍱 fix lint

* 🍱 fix lint

* 🍱 fix test

* 🍱 fix test

* 🍱 fix lint + test

* 🍱 fix test

* 🍱 fix test

* 🍱 fix test

* 🍱 fix lint

* 🍱 fix lint
This commit is contained in:
maxlerebourg
2024-02-11 11:52:47 +01:00
committed by GitHub
parent 6c183d9231
commit 575d3a02e5
7 changed files with 106 additions and 85 deletions
+4 -4
View File
@@ -8,7 +8,7 @@ import (
"net/http"
"strings"
"github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin/pkg/logger"
logger "github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin/pkg/logger"
)
// CHECKER
@@ -20,14 +20,14 @@ type Checker struct {
}
// NewChecker builds a new Checker given a list of CIDR-Strings to trusted IPs.
func NewChecker(trustedIPs []string) (*Checker, error) {
func NewChecker(log *logger.Log, trustedIPs []string) (*Checker, error) {
checker := &Checker{}
for _, ipMaskRaw := range trustedIPs {
ipMask := strings.TrimSpace(ipMaskRaw)
if ipAddr := net.ParseIP(ipMask); ipAddr != nil {
checker.authorizedIPs = append(checker.authorizedIPs, &ipAddr)
logger.Debug(fmt.Sprintf("IP %v is trusted", ipAddr))
log.Debug(fmt.Sprintf("IP %v is trusted", ipAddr))
continue
}
@@ -36,7 +36,7 @@ func NewChecker(trustedIPs []string) (*Checker, error) {
return nil, fmt.Errorf("parsing CIDR trusted IPs %s: %w", ipAddr, err)
}
checker.authorizedIPsNet = append(checker.authorizedIPsNet, ipAddr)
logger.Debug(fmt.Sprintf("IP network %v is trusted", ipAddr))
log.Debug(fmt.Sprintf("IP network %v is trusted", ipAddr))
}
return checker, nil