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

Method GetActiveDecisionsTimeLeftByValue

pkg/database/decisions.go:433–461  ·  view source on GitHub ↗
(ctx context.Context, decisionValue string)

Source from the content-addressed store, hash-verified

431}
432
433func (c *Client) GetActiveDecisionsTimeLeftByValue(ctx context.Context, decisionValue string) (time.Duration, error) {
434 rng, err := csnet.NewRange(decisionValue)
435 if err != nil {
436 return 0, fmt.Errorf("unable to convert '%s' to int: %w", decisionValue, err)
437 }
438
439 contains := true
440 decisions := c.Ent.Decision.Query().Where(
441 decision.UntilGT(time.Now().UTC()),
442 )
443
444 decisions, err = decisionIPFilter(decisions, contains, rng)
445 if err != nil {
446 return 0, fmt.Errorf("fail to apply StartIpEndIpFilter: %w", err)
447 }
448
449 decisions = decisions.Order(ent.Desc(decision.FieldUntil))
450
451 decision, err := decisions.First(ctx)
452 if err != nil && !ent.IsNotFound(err) {
453 return 0, fmt.Errorf("fail to get decision: %w", err)
454 }
455
456 if decision == nil {
457 return 0, nil
458 }
459
460 return decision.Until.Sub(time.Now().UTC()), nil
461}

Callers 1

Calls 9

NewRangeFunction · 0.92
UntilGTFunction · 0.92
DescFunction · 0.92
IsNotFoundFunction · 0.92
decisionIPFilterFunction · 0.85
WhereMethod · 0.45
QueryMethod · 0.45
OrderMethod · 0.45
FirstMethod · 0.45

Tested by

no test coverage detected