()
| 252 | } |
| 253 | |
| 254 | func (cli *cliLapi) newContextCmd() *cobra.Command { |
| 255 | cmd := &cobra.Command{ |
| 256 | Use: "context [command]", |
| 257 | Short: "Manage context to send with alerts", |
| 258 | DisableAutoGenTag: true, |
| 259 | PersistentPreRunE: func(_ *cobra.Command, _ []string) error { |
| 260 | cfg := cli.cfg() |
| 261 | if err := cfg.LoadCrowdsec(); err != nil { |
| 262 | fileNotFoundMessage := fmt.Sprintf("failed to open context file: open %s: no such file or directory", cfg.Crowdsec.ConsoleContextPath) |
| 263 | if err.Error() != fileNotFoundMessage { |
| 264 | return fmt.Errorf("unable to load CrowdSec agent configuration: %w", err) |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | if cfg.DisableAgent { |
| 269 | return errors.New("agent is disabled and lapi context can only be used on the agent") |
| 270 | } |
| 271 | |
| 272 | return nil |
| 273 | }, |
| 274 | } |
| 275 | |
| 276 | cmd.AddCommand(cli.newContextAddCmd()) |
| 277 | cmd.AddCommand(cli.newContextStatusCmd()) |
| 278 | cmd.AddCommand(cli.newContextDetectCmd()) |
| 279 | cmd.AddCommand(cli.newContextDeleteCmd()) |
| 280 | |
| 281 | return cmd |
| 282 | } |
| 283 | |
| 284 | func detectStaticField(grokStatics []parser.Static) []string { |
| 285 | ret := make([]string, 0) |
no test coverage detected