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

Method newContextCmd

cmd/crowdsec-cli/clilapi/context.go:254–282  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

252}
253
254func (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
284func detectStaticField(grokStatics []parser.Static) []string {
285 ret := make([]string, 0)

Callers 1

NewCommandMethod · 0.95

Calls 8

newContextAddCmdMethod · 0.95
newContextStatusCmdMethod · 0.95
newContextDetectCmdMethod · 0.95
newContextDeleteCmdMethod · 0.95
cfgMethod · 0.80
LoadCrowdsecMethod · 0.80
AddCommandMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected