mirror of
https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin.git
synced 2026-07-21 11:38:59 +02:00
✨ remove down at start if crowdsec unavailable (#93)
* ✨ remove down at start if crowdsec unavailable * 🚨 fix lint
This commit is contained in:
@@ -30,4 +30,6 @@ Steps to reproduce the behavior:
|
|||||||
3. Scroll down to '....'
|
3. Scroll down to '....'
|
||||||
4. See error
|
4. See error
|
||||||
|
|
||||||
|
<!---
|
||||||
If you like the plugin, please consider starring it, so you can get updates and we get some more visibility ✨
|
If you like the plugin, please consider starring it, so you can get updates and we get some more visibility ✨
|
||||||
|
-->
|
||||||
|
|||||||
@@ -16,4 +16,6 @@ A clear and concise description of what you want to happen.
|
|||||||
**Additional context**
|
**Additional context**
|
||||||
Add any other context or screenshots about the feature request here.
|
Add any other context or screenshots about the feature request here.
|
||||||
|
|
||||||
|
<!---
|
||||||
If you like the plugin, please consider starring it, so you can get updates and we get some more visibility ✨
|
If you like the plugin, please consider starring it, so you can get updates and we get some more visibility ✨
|
||||||
|
-->
|
||||||
|
|||||||
+11
-10
@@ -144,7 +144,6 @@ func New(ctx context.Context, next http.Handler, config *configuration.Config, n
|
|||||||
config.RedisCachePassword, _ = configuration.GetVariable(config, "RedisCachePassword")
|
config.RedisCachePassword, _ = configuration.GetVariable(config, "RedisCachePassword")
|
||||||
bouncer.cacheClient.New(config.RedisCacheEnabled, config.RedisCacheHost, config.RedisCachePassword)
|
bouncer.cacheClient.New(config.RedisCacheEnabled, config.RedisCacheHost, config.RedisCachePassword)
|
||||||
|
|
||||||
//nolint:nestif
|
|
||||||
if (config.CrowdsecMode == configuration.StreamMode || config.CrowdsecMode == configuration.AloneMode) && ticker == nil {
|
if (config.CrowdsecMode == configuration.StreamMode || config.CrowdsecMode == configuration.AloneMode) && ticker == nil {
|
||||||
if config.CrowdsecMode == configuration.AloneMode {
|
if config.CrowdsecMode == configuration.AloneMode {
|
||||||
if err := getToken(bouncer); err != nil {
|
if err := getToken(bouncer); err != nil {
|
||||||
@@ -152,17 +151,10 @@ func New(ctx context.Context, next http.Handler, config *configuration.Config, n
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := handleStreamCache(bouncer); err != nil {
|
handleStreamTicker(bouncer)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
isStartup = false
|
isStartup = false
|
||||||
ticker = startTicker(config, func() {
|
ticker = startTicker(config, func() {
|
||||||
if err := handleStreamCache(bouncer); err != nil {
|
handleStreamTicker(bouncer)
|
||||||
isCrowdsecStreamHealthy = false
|
|
||||||
logger.Error(err.Error())
|
|
||||||
} else {
|
|
||||||
isCrowdsecStreamHealthy = true
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
logger.Debug(fmt.Sprintf("New initialized mode:%s", config.CrowdsecMode))
|
logger.Debug(fmt.Sprintf("New initialized mode:%s", config.CrowdsecMode))
|
||||||
@@ -269,6 +261,15 @@ type Login struct {
|
|||||||
Expire string `json:"expire"`
|
Expire string `json:"expire"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleStreamTicker(bouncer *Bouncer) {
|
||||||
|
if err := handleStreamCache(bouncer); err != nil {
|
||||||
|
isCrowdsecStreamHealthy = false
|
||||||
|
logger.Error(err.Error())
|
||||||
|
} else {
|
||||||
|
isCrowdsecStreamHealthy = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func startTicker(config *configuration.Config, work func()) chan bool {
|
func startTicker(config *configuration.Config, work func()) chan bool {
|
||||||
ticker := time.NewTicker(time.Duration(config.UpdateIntervalSeconds) * time.Second)
|
ticker := time.NewTicker(time.Duration(config.UpdateIntervalSeconds) * time.Second)
|
||||||
stop := make(chan bool, 1)
|
stop := make(chan bool, 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user