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

Method CountDecisionsByValue

pkg/database/decisions.go:403–431  ·  view source on GitHub ↗
(ctx context.Context, value string, since *time.Time, onlyActive bool)

Source from the content-addressed store, hash-verified

401}
402
403func (c *Client) CountDecisionsByValue(ctx context.Context, value string, since *time.Time, onlyActive bool) (int, error) {
404 rng, err := csnet.NewRange(value)
405 if err != nil {
406 return 0, fmt.Errorf("unable to convert '%s' to int: %w", value, err)
407 }
408
409 contains := true
410 decisions := c.Ent.Decision.Query()
411
412 decisions, err = decisionIPFilter(decisions, contains, rng)
413 if err != nil {
414 return 0, fmt.Errorf("fail to apply StartIpEndIpFilter: %w", err)
415 }
416
417 if since != nil {
418 decisions = decisions.Where(decision.CreatedAtGT(*since))
419 }
420
421 if onlyActive {
422 decisions = decisions.Where(decision.UntilGT(time.Now().UTC()))
423 }
424
425 count, err := decisions.Count(ctx)
426 if err != nil {
427 return 0, fmt.Errorf("fail to count decisions: %w", err)
428 }
429
430 return count, nil
431}
432
433func (c *Client) GetActiveDecisionsTimeLeftByValue(ctx context.Context, decisionValue string) (time.Duration, error) {
434 rng, err := csnet.NewRange(decisionValue)

Callers 3

GetDecisionsCountFunction · 0.80
GetDecisionsSinceCountFunction · 0.80
GetActiveDecisionsCountFunction · 0.80

Calls 7

NewRangeFunction · 0.92
CreatedAtGTFunction · 0.92
UntilGTFunction · 0.92
decisionIPFilterFunction · 0.85
QueryMethod · 0.45
WhereMethod · 0.45
CountMethod · 0.45

Tested by

no test coverage detected