(key string, values []string)
| 20 | ) |
| 21 | |
| 22 | func (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 | |
| 49 | func (cli *cliLapi) newContextAddCmd() *cobra.Command { |
| 50 | var ( |
no test coverage detected