lint (errorlint) (#2644)

This commit is contained in:
mmetc 2023-12-18 09:35:28 +01:00 committed by GitHub
parent c2c173ac7e
commit 08694adf1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 27 additions and 33 deletions

View file

@ -104,12 +104,12 @@ func CrowdsecCTI(params ...any) (any, error) {
ctiResp, err := ctiClient.GetIPInfo(ip)
ctiClient.Logger.Debugf("request for %s took %v", ip, time.Since(before))
if err != nil {
switch err {
case cticlient.ErrUnauthorized:
switch {
case errors.Is(err, cticlient.ErrUnauthorized):
CTIApiEnabled = false
ctiClient.Logger.Errorf("Invalid API key provided, disabling CTI API")
return &cticlient.SmokeItem{}, cticlient.ErrUnauthorized
case cticlient.ErrLimit:
case errors.Is(err, cticlient.ErrLimit):
CTIBackOffUntil = time.Now().Add(CTIBackOffDuration)
ctiClient.Logger.Errorf("CTI API is throttled, will try again in %s", CTIBackOffDuration)
return &cticlient.SmokeItem{}, cticlient.ErrLimit

View file

@ -3,6 +3,7 @@ package exprhelpers
import (
"bytes"
"encoding/json"
"errors"
"io"
"net/http"
"strings"
@ -108,7 +109,7 @@ func smokeHandler(req *http.Request) *http.Response {
func TestNillClient(t *testing.T) {
defer ShutdownCrowdsecCTI()
if err := InitCrowdsecCTI(ptr.Of(""), nil, nil, nil); err != cticlient.ErrDisabled {
if err := InitCrowdsecCTI(ptr.Of(""), nil, nil, nil); !errors.Is(err, cticlient.ErrDisabled) {
t.Fatalf("failed to init CTI : %s", err)
}
item, err := CrowdsecCTI("1.2.3.4")