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

Method addContext

cmd/crowdsec-cli/clilapi/context.go:22–47  ·  view source on GitHub ↗
(key string, values []string)

Source from the content-addressed store, hash-verified

20)
21
22func (cli *cliLapi) addContext(key string, values []string) error {
23 cfg := cli.cfg()
24
25 if err := alertcontext.ValidateContextExpr(key, values); err != nil {
26 return fmt.Errorf("invalid context configuration: %w", err)
27 }
28
29 if _, ok := cfg.Crowdsec.ContextToSend[key]; !ok {
30 cfg.Crowdsec.ContextToSend[key] = make([]string, 0)
31
32 log.Infof("key '%s' added", key)
33 }
34
35 data := cfg.Crowdsec.ContextToSend[key]
36
37 for _, val := range values {
38 if !slices.Contains(data, val) {
39 log.Infof("value '%s' added to key '%s'", val, key)
40 data = append(data, val)
41 }
42
43 cfg.Crowdsec.ContextToSend[key] = data
44 }
45
46 return cfg.Crowdsec.DumpContextConfigFile()
47}
48
49func (cli *cliLapi) newContextAddCmd() *cobra.Command {
50 var (

Callers 1

newContextAddCmdMethod · 0.95

Calls 3

ValidateContextExprFunction · 0.92
cfgMethod · 0.80
DumpContextConfigFileMethod · 0.80

Tested by

no test coverage detected