mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-11 12:25:53 +02:00
remove unused code: HandleDeletedDecisions() (#3301)
This commit is contained in:
parent
53f9bc562d
commit
96d4da76b9
2 changed files with 0 additions and 69 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue