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:
+17
-12
@@ -126,7 +126,7 @@ func New(ctx context.Context, next http.Handler, config *Config, name string) (h
|
|||||||
MaxIdleConns: 10,
|
MaxIdleConns: 10,
|
||||||
IdleConnTimeout: 30 * time.Second,
|
IdleConnTimeout: 30 * time.Second,
|
||||||
},
|
},
|
||||||
Timeout: 5 * time.Second,
|
Timeout: 2 * time.Second,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if config.RedisCacheEnabled {
|
if config.RedisCacheEnabled {
|
||||||
@@ -182,17 +182,30 @@ func (bouncer *Bouncer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.Debug(fmt.Sprintf("ServeHTTP ip:%s cache:hit isBanned:%v", remoteIP, isBanned))
|
logger.Debug(fmt.Sprintf("ServeHTTP ip:%s cache:hit isBanned:%v", remoteIP, isBanned))
|
||||||
response(isBanned, bouncer, rw, req)
|
if isBanned {
|
||||||
|
rw.WriteHeader(http.StatusForbidden)
|
||||||
|
} else {
|
||||||
|
bouncer.next.ServeHTTP(rw, req)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Right here if we cannot join the stream we forbid the request to go on.
|
// Right here if we cannot join the stream we forbid the request to go on.
|
||||||
if bouncer.crowdsecMode == streamMode {
|
if bouncer.crowdsecMode == streamMode {
|
||||||
response(isCrowdsecStreamHealthy, bouncer, rw, req)
|
if isCrowdsecStreamHealthy {
|
||||||
|
rw.WriteHeader(http.StatusForbidden)
|
||||||
|
} else {
|
||||||
|
bouncer.next.ServeHTTP(rw, req)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
err = handleNoStreamCache(bouncer, remoteIP)
|
err = handleNoStreamCache(bouncer, remoteIP)
|
||||||
response(err != nil, bouncer, rw, req)
|
if err != nil {
|
||||||
|
logger.Debug(err.Error())
|
||||||
|
rw.WriteHeader(http.StatusForbidden)
|
||||||
|
} else {
|
||||||
|
bouncer.next.ServeHTTP(rw, req)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,14 +230,6 @@ type Stream struct {
|
|||||||
New []Decision `json:"new"`
|
New []Decision `json:"new"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func response(isValid bool, bouncer *Bouncer, rw http.ResponseWriter, req *http.Request) {
|
|
||||||
if isValid {
|
|
||||||
rw.WriteHeader(http.StatusForbidden)
|
|
||||||
} else {
|
|
||||||
bouncer.next.ServeHTTP(rw, req)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func contains(source []string, target string) bool {
|
func contains(source []string, target string) bool {
|
||||||
for _, item := range source {
|
for _, item := range source {
|
||||||
if item == target {
|
if item == target {
|
||||||
|
|||||||
Reference in New Issue
Block a user