MCPcopy Index your code
hub / github.com/crowdsecurity/crowdsec / CreateAllowList

Method CreateAllowList

pkg/database/allowlists.go:24–40  ·  view source on GitHub ↗
(ctx context.Context, name string, description string, allowlistID string, fromConsole bool)

Source from the content-addressed store, hash-verified

22const allowlistExpireDecisionsBatchSize = 300
23
24func (c *Client) CreateAllowList(ctx context.Context, name string, description string, allowlistID string, fromConsole bool) (*ent.AllowList, error) {
25 allowlist, err := c.Ent.AllowList.Create().
26 SetName(name).
27 SetFromConsole(fromConsole).
28 SetDescription(description).
29 SetAllowlistID(allowlistID).
30 Save(ctx)
31 if err != nil {
32 if sqlgraph.IsUniqueConstraintError(err) {
33 return nil, fmt.Errorf("allowlist '%s' already exists", name)
34 }
35
36 return nil, fmt.Errorf("unable to create allowlist: %w", err)
37 }
38
39 return allowlist, nil
40}
41
42func (c *Client) DeleteAllowList(ctx context.Context, name string, fromConsole bool) error {
43 nbDeleted, err := c.Ent.AllowListItem.Delete().Where(allowlistitem.HasAllowlistWith(allowlist.NameEQ(name), allowlist.FromConsoleEQ(fromConsole))).Exec(ctx)

Callers 12

TestCheckAllowlistFunction · 0.80
updateOneAllowlistMethod · 0.80
TestAllowlistListFunction · 0.80
TestGetAllowlistFunction · 0.80
TestCheckInAllowlistFunction · 0.80
TestBulkCheckAllowlistFunction · 0.80
createMethod · 0.80

Calls 6

SaveMethod · 0.45
SetAllowlistIDMethod · 0.45
SetDescriptionMethod · 0.45
SetFromConsoleMethod · 0.45
SetNameMethod · 0.45
CreateMethod · 0.45

Tested by 10

TestCheckAllowlistFunction · 0.64
TestAllowlistListFunction · 0.64
TestGetAllowlistFunction · 0.64
TestCheckInAllowlistFunction · 0.64
TestBulkCheckAllowlistFunction · 0.64