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

Method remove

cmd/crowdsec-cli/cliallowlists/allowlists.go:611–653  ·  view source on GitHub ↗
(ctx context.Context, db *database.Client, name string, values []string)

Source from the content-addressed store, hash-verified

609}
610
611func (*cliAllowLists) remove(ctx context.Context, db *database.Client, name string, values []string) error {
612 allowlist, err := db.GetAllowList(ctx, name, true)
613 if err != nil {
614 return err
615 }
616
617 if allowlist.FromConsole {
618 return fmt.Errorf("allowlist %s is managed by console, cannot delete with cscli. Please visit https://app.crowdsec.net/allowlists/%s to delete", name, allowlist.AllowlistID)
619 }
620
621 toRemove := make([]string, 0)
622
623 for _, v := range values {
624 found := false
625
626 for _, item := range allowlist.Edges.AllowlistItems {
627 if item.Value == v {
628 found = true
629 break
630 }
631 }
632
633 if found {
634 toRemove = append(toRemove, v)
635 }
636 }
637
638 if len(toRemove) == 0 {
639 fmt.Fprintln(os.Stdout, "no value to remove from allowlist")
640 return nil
641 }
642
643 deleted, err := db.RemoveFromAllowlist(ctx, allowlist, toRemove...)
644 if err != nil {
645 return fmt.Errorf("unable to remove values from allowlist: %w", err)
646 }
647
648 if deleted > 0 {
649 fmt.Fprintf(os.Stdout, "removed %d values from allowlist %s", deleted, name)
650 }
651
652 return nil
653}
654
655func (cli *cliAllowLists) check(ctx context.Context, ips []string) error {
656 cfg := cli.cfg()

Callers 1

newRemoveCmdMethod · 0.95

Calls 2

GetAllowListMethod · 0.80
RemoveFromAllowlistMethod · 0.80

Tested by

no test coverage detected