🍱 fix lint

This commit is contained in:
Max Lerebourg
2025-08-06 08:57:08 +02:00
parent 16a5ea05be
commit cca600d32d
3 changed files with 20 additions and 21 deletions

View File

@@ -233,16 +233,6 @@ func New(_ context.Context, next http.Handler, config *configuration.Config, nam
config.CaptchaSiteKey, _ = configuration.GetVariable(config, "CaptchaSiteKey")
config.CaptchaSecretKey, _ = configuration.GetVariable(config, "CaptchaSecretKey")
var infoProvider *captcha.InfoProvider
if config.CaptchaProvider == configuration.CustomProvider {
infoProvider = &captcha.InfoProvider{
js: config.CaptchaCustomJsURL,
key: config.CaptchaCustomKey,
response: config.CaptchaCustomResponse,
validate: config.CaptchaCustomValidateURL,
}
}
err = bouncer.captchaClient.New(
log,
bouncer.cacheClient,
@@ -250,7 +240,13 @@ func New(_ context.Context, next http.Handler, config *configuration.Config, nam
Transport: &http.Transport{MaxIdleConns: 10, IdleConnTimeout: 30 * time.Second},
Timeout: time.Duration(config.HTTPTimeoutSeconds) * time.Second,
},
infoProvider,
captcha.GetInfoProvider(
config.CaptchaProvider,
config.CaptchaCustomJsURL,
config.CaptchaCustomKey,
config.CaptchaCustomResponse,
config.CaptchaCustomValidateURL,
),
config.CaptchaProvider,
config.CaptchaSiteKey,
config.CaptchaSecretKey,

View File

@@ -294,12 +294,7 @@
<h1 class="text-2xl lg:text-3xl xl:text-4xl">CrowdSec Captcha</h1>
</div>
<form action="" method="POST" class="flex flex-col items-center space-y-1" id="captcha-form">
<div
id="captcha"
class="{{ .FrontendKey }}"
data-sitekey="{{ .SiteKey }}"
data-callback="captchaCallback"
>
<div id="captcha" class="{{ .FrontendKey }}" data-sitekey="{{ .SiteKey }}" data-callback="captchaCallback">
</div>
</form>
<div class="flex justify-center flex-wrap">

View File

@@ -58,16 +58,24 @@ var infoProviders = map[string]*InfoProvider{
},
}
// GetInfoProvider Get InfoProvider.
func GetInfoProvider(provider, js, key, response, validate string) *InfoProvider {
var infoProvider InfoProvider
if provider == configuration.CustomProvider {
infoProvider = &captcha.InfoProvider{js, key, response, validate}
} else {
infoProvider = infoProviders[provider]
}
return infoProvider
}
// New Initialize captcha client.
func (c *Client) New(log *logger.Log, cacheClient *cache.Client, httpClient *http.Client, infoProvider *InfoProvider, provider, siteKey, secretKey, remediationCustomHeader, captchaTemplatePath string, gracePeriodSeconds int64) error {
func (c *Client) New(log *logger.Log, cacheClient *cache.Client, httpClient *http.Client, infoProvider *InfoProvider, siteKey, secretKey, remediationCustomHeader, captchaTemplatePath string, gracePeriodSeconds int64) error {
c.Valid = provider != ""
if !c.Valid {
return nil
}
c.infoProvider = infoProvider
if c.infoProvider == nil {
c.infoProvider = infoProviders[provider]
}
c.siteKey = siteKey
c.secretKey = secretKey
c.remediationCustomHeader = remediationCustomHeader