This commit is contained in:
Max Lerebourg
2022-09-29 09:11:19 +02:00
parent da47ef320d
commit cba7c1231f
2 changed files with 8 additions and 6 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
[![Build Status](https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin/actions) [![Build Status](https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin/actions/workflows/main.yml/badge.svg)](https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin/actions)
[![Go Report Card](https://goreportcard.com/badge/github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin)](https://goreportcard.com/badge/github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin) [![Go Report Card](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
View File
@@ -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")
} }