mirror of
https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin.git
synced 2026-07-21 11:38:59 +02:00
fix lint
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
[](https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin/actions)
|
[](https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin/actions)
|
||||||
[](https://goreportcard.com/badge/github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin)
|
[](https://goreportcard.com/badge/github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin)
|
||||||
|
|
||||||
# Crowdsec Bouncer Traefik plugin
|
# Crowdsec Bouncer Traefik plugin
|
||||||
|
|||||||
+7
-5
@@ -26,6 +26,7 @@ const (
|
|||||||
|
|
||||||
var cache = ttl_map.New()
|
var cache = ttl_map.New()
|
||||||
|
|
||||||
|
// Config the plugin configuration.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Enabled bool `json:"enabled,omitempty"`
|
Enabled bool `json:"enabled,omitempty"`
|
||||||
CrowdsecMode string `json:"crowdsecMode,omitempty"`
|
CrowdsecMode string `json:"crowdsecMode,omitempty"`
|
||||||
@@ -36,6 +37,7 @@ type Config struct {
|
|||||||
DefaultDecisionSeconds int64 `json:"defaultDecisionSeconds,omitempty"`
|
DefaultDecisionSeconds int64 `json:"defaultDecisionSeconds,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateConfig creates the default plugin configuration.
|
||||||
func CreateConfig() *Config {
|
func CreateConfig() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
Enabled: false,
|
Enabled: false,
|
||||||
@@ -48,6 +50,7 @@ func CreateConfig() *Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bouncer a Bouncer plugin.
|
||||||
type Bouncer struct {
|
type Bouncer struct {
|
||||||
next http.Handler
|
next http.Handler
|
||||||
name string
|
name string
|
||||||
@@ -238,6 +241,8 @@ func (a *Bouncer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
// CUSTOM CODE
|
// CUSTOM CODE
|
||||||
// TODO place in another file
|
// TODO place in another file
|
||||||
|
|
||||||
|
// Decision: Body returned from Crowdsec LAPI
|
||||||
type Decision struct {
|
type Decision struct {
|
||||||
Id int `json:"id"`
|
Id int `json:"id"`
|
||||||
Origin string `json:"origin"`
|
Origin string `json:"origin"`
|
||||||
@@ -249,6 +254,7 @@ type Decision struct {
|
|||||||
Simulated bool `json:"simulated"`
|
Simulated bool `json:"simulated"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stream: Body returned from Crowdsec Stream LAPI
|
||||||
type Stream struct {
|
type Stream struct {
|
||||||
Deleted []Decision `json:"deleted"`
|
Deleted []Decision `json:"deleted"`
|
||||||
New []Decision `json:"new"`
|
New []Decision `json:"new"`
|
||||||
@@ -268,11 +274,7 @@ func contains(source []string, target string) bool {
|
|||||||
func getDecision(clientIP string) (bool, error) {
|
func getDecision(clientIP string) (bool, error) {
|
||||||
isBanned, ok := cache.Get(clientIP)
|
isBanned, ok := cache.Get(clientIP)
|
||||||
if ok && len(isBanned.(string)) > 0 {
|
if ok && len(isBanned.(string)) > 0 {
|
||||||
if isBanned == cacheNoBannedValue {
|
return isBanned == cacheNoBannedValue, nil
|
||||||
return false, nil
|
|
||||||
} else {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false, fmt.Errorf("no data")
|
return false, fmt.Errorf("no data")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user