Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Nov 26, 2023
1 parent a0a7a4f commit a593faa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
30 changes: 15 additions & 15 deletions pkg/apiserver/apic.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net"
"net/http"
"net/url"
"slices"
"strconv"
"strings"
"sync"
Expand All @@ -17,6 +16,7 @@ import (
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"gopkg.in/tomb.v2"
"slices"

"github.com/crowdsecurity/go-cs-lib/ptr"
"github.com/crowdsecurity/go-cs-lib/trace"
Expand Down Expand Up @@ -383,10 +383,10 @@ func (a *apic) CAPIPullIsOld() (bool, error) {
}

func (a *apic) HandleDeletedDecisions(deletedDecisions []*models.Decision, delete_counters map[string]map[string]int) (int, error) {
var nbDeleted int
nbDeleted := 0
for _, decision := range deletedDecisions {
filter := map[string][]string{
"value": {*decision.Value},
"value": {*decision.Value},
"origin": {*decision.Origin},
}
if strings.ToLower(*decision.Scope) != "ip" {
Expand Down Expand Up @@ -414,7 +414,7 @@ func (a *apic) HandleDeletedDecisionsV3(deletedDecisions []*modelscapi.GetDecisi
scope := decisions.Scope
for _, decision := range decisions.Decisions {
filter := map[string][]string{
"value": {decision},
"value": {decision},
"origin": {types.CAPIOrigin},
}
if strings.ToLower(*scope) != "ip" {
Expand Down Expand Up @@ -485,7 +485,7 @@ func createAlertForDecision(decision *models.Decision) *models.Alert {
case types.ListOrigin:
scenario = *decision.Scenario
scope = types.ListOrigin
default:
default:
// XXX: this or nil?
scenario = ""
scope = ""
Expand All @@ -497,17 +497,17 @@ func createAlertForDecision(decision *models.Decision) *models.Alert {
Scope: ptr.Of(scope),
Value: ptr.Of(""),
},
Scenario: ptr.Of(scenario),
Message: ptr.Of(""),
StartAt: ptr.Of(time.Now().UTC().Format(time.RFC3339)),
StopAt: ptr.Of(time.Now().UTC().Format(time.RFC3339)),
Capacity: ptr.Of(int32(0)),
Simulated: ptr.Of(false),
EventsCount: ptr.Of(int32(0)),
Leakspeed: ptr.Of(""),
ScenarioHash: ptr.Of(""),
Scenario: ptr.Of(scenario),
Message: ptr.Of(""),
StartAt: ptr.Of(time.Now().UTC().Format(time.RFC3339)),
StopAt: ptr.Of(time.Now().UTC().Format(time.RFC3339)),
Capacity: ptr.Of(int32(0)),
Simulated: ptr.Of(false),
EventsCount: ptr.Of(int32(0)),
Leakspeed: ptr.Of(""),
ScenarioHash: ptr.Of(""),
ScenarioVersion: ptr.Of(""),
MachineID: database.CapiMachineID,
MachineID: database.CapiMachineID,
}
}

Expand Down
9 changes: 4 additions & 5 deletions pkg/database/decisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type DecisionsByScenario struct {
}

func BuildDecisionRequestWithFilter(query *ent.DecisionQuery, filter map[string][]string) (*ent.DecisionQuery, error) {

var err error
var start_ip, start_sfx, end_ip, end_sfx int64
var ip_sz int
Expand Down Expand Up @@ -551,8 +550,8 @@ func (c *Client) BulkDeleteDecisions(decisionsToDelete []*ent.Decision, softDele
const bulkSize = 256 //scientifically proven to be the best value for bulk delete

var (
nbUpdates int
err error
nbUpdates int
err error
totalUpdates = 0
)

Expand All @@ -574,7 +573,7 @@ func (c *Client) BulkDeleteDecisions(decisionsToDelete []*ent.Decision, softDele
decision.IDIn(chunk...),
).Exec(c.CTX)
if err != nil {
return totalUpdates, fmt.Errorf("hard delete decisions with provided filter: %w", err)
return totalUpdates, fmt.Errorf("hard delete decisions with provided filter: %w", err)
}
}
totalUpdates += nbUpdates
Expand All @@ -588,7 +587,7 @@ func (c *Client) SoftDeleteDecisionByID(decisionID int) (int, []*ent.Decision, e
toUpdate, err := c.Ent.Decision.Query().Where(decision.IDEQ(decisionID)).All(c.CTX)

// XXX: do we want 500 or 404 here?
if err != nil || len(toUpdate) == 0{
if err != nil || len(toUpdate) == 0 {
c.Log.Warningf("SoftDeleteDecisionByID : %v (nb soft deleted: %d)", err, len(toUpdate))
return 0, nil, errors.Wrapf(DeleteFail, "decision with id '%d' doesn't exist", decisionID)
}
Expand Down

0 comments on commit a593faa

Please sign in to comment.