mirror of
https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin.git
synced 2026-07-21 11:38:59 +02:00
Add Wait Stream feature
This commit is contained in:
@@ -28,6 +28,15 @@ run_local:
|
|||||||
run:
|
run:
|
||||||
docker-compose -f docker-compose.yml up -d --remove-orphans
|
docker-compose -f docker-compose.yml up -d --remove-orphans
|
||||||
|
|
||||||
|
restart_docker_dev:
|
||||||
|
docker-compose -f docker-compose.dev.yml restart
|
||||||
|
|
||||||
|
restart_docker_local:
|
||||||
|
docker-compose -f docker-compose.local.yml restart
|
||||||
|
|
||||||
|
restart_docker:
|
||||||
|
docker-compose -f docker-compose.yml restart
|
||||||
|
|
||||||
show_metrics:
|
show_metrics:
|
||||||
docker exec crowdsec cscli metrics
|
docker exec crowdsec cscli metrics
|
||||||
|
|
||||||
|
|||||||
+14
@@ -8,6 +8,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -117,6 +118,7 @@ func New(ctx context.Context, next http.Handler, config *Config, name string) (h
|
|||||||
cache: ttl_map.New(),
|
cache: ttl_map.New(),
|
||||||
}
|
}
|
||||||
if config.CrowdsecMode == streamMode || config.CrowdsecMode == aloneMode {
|
if config.CrowdsecMode == streamMode || config.CrowdsecMode == aloneMode {
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
if config.CrowdsecMode == aloneMode {
|
if config.CrowdsecMode == aloneMode {
|
||||||
getToken(bouncer)
|
getToken(bouncer)
|
||||||
}
|
}
|
||||||
@@ -271,9 +273,20 @@ func handleNoStreamCache(a *Bouncer, rw http.ResponseWriter, req *http.Request,
|
|||||||
setDecision(a, remoteHost, true, int64(duration.Seconds()))
|
setDecision(a, remoteHost, true, int64(duration.Seconds()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func wait_stream() {
|
||||||
|
logger("Start Wait Stream")
|
||||||
|
sec := rand.Int63n(30)
|
||||||
|
logger(fmt.Sprintf("Sec=%v", sec))
|
||||||
|
time.Sleep(time.Duration(sec) * time.Second)
|
||||||
|
logger("End Wait Stream")
|
||||||
|
}
|
||||||
|
|
||||||
func handleStreamCache(a *Bouncer) {
|
func handleStreamCache(a *Bouncer) {
|
||||||
logger(fmt.Sprintf("Start handleStreamCache with health=%v", a.crowdsecStreamHealthy))
|
logger(fmt.Sprintf("Start handleStreamCache with health=%v", a.crowdsecStreamHealthy))
|
||||||
// TODO clean properly on exit.
|
// TODO clean properly on exit.
|
||||||
|
|
||||||
|
wait_stream()
|
||||||
|
// wait random number of sec
|
||||||
var rawQuery string
|
var rawQuery string
|
||||||
var path string
|
var path string
|
||||||
if a.crowdsecMode == aloneMode {
|
if a.crowdsecMode == aloneMode {
|
||||||
@@ -307,6 +320,7 @@ func handleStreamCache(a *Bouncer) {
|
|||||||
a.cache.Del(decision.Value)
|
a.cache.Del(decision.Value)
|
||||||
}
|
}
|
||||||
a.crowdsecStreamHealthy = true
|
a.crowdsecStreamHealthy = true
|
||||||
|
logger(fmt.Sprintf("End handleStreamCache with health=%v", a.crowdsecStreamHealthy))
|
||||||
}
|
}
|
||||||
|
|
||||||
func getToken(a *Bouncer) {
|
func getToken(a *Bouncer) {
|
||||||
|
|||||||
Reference in New Issue
Block a user