MCPcopy
hub / github.com/crowdsecurity/crowdsec / setConsoleOpts

Method setConsoleOpts

cmd/crowdsec-cli/cliconsole/console.go:428–509  ·  view source on GitHub ↗
(args []string, wanted bool)

Source from the content-addressed store, hash-verified

426}
427
428func (cli *cliConsole) setConsoleOpts(args []string, wanted bool) error {
429 cfg := cli.cfg()
430 consoleCfg := cfg.API.Server.ConsoleConfig
431
432 for _, arg := range args {
433 switch arg {
434 case csconfig.CONSOLE_MANAGEMENT:
435 // for each flag check if it's already set before setting it
436 if consoleCfg.ConsoleManagement != nil && *consoleCfg.ConsoleManagement == wanted {
437 log.Debugf("%s already set to %t", csconfig.CONSOLE_MANAGEMENT, wanted)
438 } else {
439 log.Infof("%s set to %t", csconfig.CONSOLE_MANAGEMENT, wanted)
440 consoleCfg.ConsoleManagement = new(wanted)
441 }
442
443 if cfg.API.Server.OnlineClient.Credentials != nil {
444 changed := false
445 if wanted && cfg.API.Server.OnlineClient.Credentials.PapiURL == "" {
446 changed = true
447 cfg.API.Server.OnlineClient.Credentials.PapiURL = csconfig.PAPIBaseURL
448 } else if !wanted && cfg.API.Server.OnlineClient.Credentials.PapiURL != "" {
449 changed = true
450 cfg.API.Server.OnlineClient.Credentials.PapiURL = ""
451 }
452
453 if changed {
454 fileContent, err := yaml.Marshal(cfg.API.Server.OnlineClient.Credentials)
455 if err != nil {
456 return fmt.Errorf("cannot serialize credentials: %w", err)
457 }
458
459 log.Infof("Updating credentials file: %s", cfg.API.Server.OnlineClient.CredentialsFilePath)
460
461 err = os.WriteFile(cfg.API.Server.OnlineClient.CredentialsFilePath, fileContent, 0o600)
462 if err != nil {
463 return fmt.Errorf("cannot write credentials file: %w", err)
464 }
465 }
466 }
467 case csconfig.SEND_CUSTOM_SCENARIOS:
468 // for each flag check if it's already set before setting it
469 if consoleCfg.ShareCustomScenarios != nil && *consoleCfg.ShareCustomScenarios == wanted {
470 log.Debugf("%s already set to %t", csconfig.SEND_CUSTOM_SCENARIOS, wanted)
471 } else {
472 log.Infof("%s set to %t", csconfig.SEND_CUSTOM_SCENARIOS, wanted)
473 consoleCfg.ShareCustomScenarios = new(wanted)
474 }
475 case csconfig.SEND_TAINTED_SCENARIOS:
476 // for each flag check if it's already set before setting it
477 if consoleCfg.ShareTaintedScenarios != nil && *consoleCfg.ShareTaintedScenarios == wanted {
478 log.Debugf("%s already set to %t", csconfig.SEND_TAINTED_SCENARIOS, wanted)
479 } else {
480 log.Infof("%s set to %t", csconfig.SEND_TAINTED_SCENARIOS, wanted)
481 consoleCfg.ShareTaintedScenarios = new(wanted)
482 }
483 case csconfig.SEND_MANUAL_SCENARIOS:
484 // for each flag check if it's already set before setting it
485 if consoleCfg.ShareManualDecisions != nil && *consoleCfg.ShareManualDecisions == wanted {

Callers 3

enrollMethod · 0.95
newEnableCmdMethod · 0.95
newDisableCmdMethod · 0.95

Calls 2

dumpConfigMethod · 0.95
cfgMethod · 0.80

Tested by

no test coverage detected