From a12e121a7311c8241981e5dde8586750dc0d79db Mon Sep 17 00:00:00 2001 From: marco Date: Fri, 11 Oct 2024 16:30:49 +0200 Subject: [PATCH] remove unused code: HandleDeletedDecision() --- pkg/apiserver/apic.go | 31 ------------------------------- pkg/apiserver/apic_test.go | 38 -------------------------------------- 2 files changed, 69 deletions(-) diff --git a/pkg/apiserver/apic.go b/pkg/apiserver/apic.go index a2fb0e85749..fff0ebcacbf 100644 --- a/pkg/apiserver/apic.go +++ b/pkg/apiserver/apic.go @@ -423,37 +423,6 @@ func (a *apic) CAPIPullIsOld(ctx context.Context) (bool, error) { return true, nil } -func (a *apic) HandleDeletedDecisions(deletedDecisions []*models.Decision, deleteCounters map[string]map[string]int) (int, error) { - ctx := context.TODO() - nbDeleted := 0 - - for _, decision := range deletedDecisions { - filter := map[string][]string{ - "value": {*decision.Value}, - "origin": {*decision.Origin}, - } - if strings.ToLower(*decision.Scope) != "ip" { - filter["type"] = []string{*decision.Type} - filter["scopes"] = []string{*decision.Scope} - } - - dbCliRet, _, err := a.dbClient.ExpireDecisionsWithFilter(ctx, filter) - if err != nil { - return 0, fmt.Errorf("expiring decisions error: %w", err) - } - - dbCliDel, err := strconv.Atoi(dbCliRet) - if err != nil { - return 0, fmt.Errorf("converting db ret %d: %w", dbCliDel, err) - } - - updateCounterForDecision(deleteCounters, decision.Origin, decision.Scenario, dbCliDel) - nbDeleted += dbCliDel - } - - return nbDeleted, nil -} - func (a *apic) HandleDeletedDecisionsV3(ctx context.Context, deletedDecisions []*modelscapi.GetDecisionsStreamResponseDeletedItem, deleteCounters map[string]map[string]int) (int, error) { var nbDeleted int diff --git a/pkg/apiserver/apic_test.go b/pkg/apiserver/apic_test.go index b52dc9e44cc..99fee6e32bf 100644 --- a/pkg/apiserver/apic_test.go +++ b/pkg/apiserver/apic_test.go @@ -255,44 +255,6 @@ func TestNewAPIC(t *testing.T) { } } -func TestAPICHandleDeletedDecisions(t *testing.T) { - ctx := context.Background() - api := getAPIC(t, ctx) - _, deleteCounters := makeAddAndDeleteCounters() - - decision1 := api.dbClient.Ent.Decision.Create(). - SetUntil(time.Now().Add(time.Hour)). - SetScenario("crowdsec/test"). - SetType("ban"). - SetScope("IP"). - SetValue("1.2.3.4"). - SetOrigin(types.CAPIOrigin). - SaveX(context.Background()) - - api.dbClient.Ent.Decision.Create(). - SetUntil(time.Now().Add(time.Hour)). - SetScenario("crowdsec/test"). - SetType("ban"). - SetScope("IP"). - SetValue("1.2.3.4"). - SetOrigin(types.CAPIOrigin). - SaveX(context.Background()) - - assertTotalDecisionCount(t, ctx, api.dbClient, 2) - - nbDeleted, err := api.HandleDeletedDecisions([]*models.Decision{{ - Value: ptr.Of("1.2.3.4"), - Origin: ptr.Of(types.CAPIOrigin), - Type: &decision1.Type, - Scenario: ptr.Of("crowdsec/test"), - Scope: ptr.Of("IP"), - }}, deleteCounters) - - require.NoError(t, err) - assert.Equal(t, 2, nbDeleted) - assert.Equal(t, 2, deleteCounters[types.CAPIOrigin]["all"]) -} - func TestAPICGetMetrics(t *testing.T) { ctx := context.Background()