MCPcopy
hub / github.com/crowdsecurity/crowdsec / CAPIPullIsOld

Method CAPIPullIsOld

pkg/apiserver/apic.go:427–445  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

425}
426
427func (a *apic) CAPIPullIsOld(ctx context.Context) (bool, error) {
428 /*only pull community blocklist if it's older than 1h30 */
429 alerts := a.dbClient.Ent.Alert.Query()
430
431 alerts = alerts.Where(alert.HasDecisionsWith(decision.OriginEQ(database.CapiMachineID)))
432 alerts = alerts.Where(alert.CreatedAtGTE(time.Now().UTC().Add(-time.Duration(1*time.Hour + 30*time.Minute)))) //nolint:unconvert
433
434 count, err := alerts.Count(ctx)
435 if err != nil {
436 return false, fmt.Errorf("while looking for CAPI alert: %w", err)
437 }
438
439 if count > 0 {
440 log.Info("last CAPI pull is newer than 1h30, skip.")
441 return false, nil
442 }
443
444 return true, nil
445}
446
447func (a *apic) HandleDeletedDecisionsV3(ctx context.Context, deletedDecisions []*modelscapi.GetDecisionsStreamResponseDeletedItem, deleteCounters map[string]map[string]int) (int, error) {
448 var nbDeleted int

Callers 2

PullTopMethod · 0.95
TestAPICCAPIPullIsOldFunction · 0.80

Calls 8

HasDecisionsWithFunction · 0.92
OriginEQFunction · 0.92
CreatedAtGTEFunction · 0.92
QueryMethod · 0.45
WhereMethod · 0.45
AddMethod · 0.45
CountMethod · 0.45
InfoMethod · 0.45

Tested by 1

TestAPICCAPIPullIsOldFunction · 0.64