mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-14 13:24:34 +02:00
* tests: don't run crowdsec if not necessary * make listen_uri report the random port number when 0 is requested * move apiserver.getTLSAuthType() -> csconfig.TLSCfg.GetAuthType() * move apiserver.isEnrolled() -> apiclient.ApiClient.IsEnrolled() * extract function apiserver.recoverFromPanic() * simplify and move APIServer.GetTLSConfig() -> TLSCfg.GetTLSConfig() * moved TLSCfg type to csconfig/tls.go * APIServer.InitController(): early return / happy path * extract function apiserver.newGinLogger() * lapi tests * update unit test * lint (testify) * lint (whitespace, variable names) * update docker tests
38 lines
795 B
Go
38 lines
795 B
Go
package v1
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/database/ent"
|
|
)
|
|
|
|
var (
|
|
bouncerContextKey = "bouncer_info"
|
|
)
|
|
|
|
func getBouncerFromContext(ctx *gin.Context) (*ent.Bouncer, error) {
|
|
bouncerInterface, exist := ctx.Get(bouncerContextKey)
|
|
if !exist {
|
|
return nil, fmt.Errorf("bouncer not found")
|
|
}
|
|
|
|
bouncerInfo, ok := bouncerInterface.(*ent.Bouncer)
|
|
if !ok {
|
|
return nil, fmt.Errorf("bouncer not found")
|
|
}
|
|
|
|
return bouncerInfo, nil
|
|
}
|
|
|
|
func (c *Controller) AbortRemoteIf(option bool) gin.HandlerFunc {
|
|
return func(gctx *gin.Context) {
|
|
incomingIP := gctx.ClientIP()
|
|
if option && incomingIP != "127.0.0.1" && incomingIP != "::1" {
|
|
gctx.JSON(http.StatusForbidden, gin.H{"message": "access forbidden"})
|
|
gctx.Abort()
|
|
}
|
|
}
|
|
}
|