@@ -27,7 +27,6 @@ import (
2727 "github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/require"
2828 "github.com/crowdsecurity/crowdsec/pkg/apiclient"
2929 "github.com/crowdsecurity/crowdsec/pkg/csconfig"
30- "github.com/crowdsecurity/crowdsec/pkg/types"
3130)
3231
3332type configGetter func () * csconfig.Config
@@ -52,6 +51,7 @@ func (cli *cliConsole) NewCommand() *cobra.Command {
5251 if err := require .LAPI (cfg ); err != nil {
5352 return err
5453 }
54+
5555 if err := require .CAPI (cfg ); err != nil {
5656 return err
5757 }
@@ -240,14 +240,17 @@ Enable given information push to the central API. Allows to empower the console`
240240 if err := cli .setConsoleOpts (csconfig .CONSOLE_CONFIGS , true ); err != nil {
241241 return err
242242 }
243+
243244 log .Infof ("All features have been enabled successfully" )
244245 } else {
245246 if len (args ) == 0 {
246247 return errors .New ("you must specify at least one feature to enable" )
247248 }
249+
248250 if err := cli .setConsoleOpts (args , true ); err != nil {
249251 return err
250252 }
253+
251254 log .Infof ("%v have been enabled" , args )
252255 }
253256
@@ -279,14 +282,17 @@ Disable given information push to the central API.`,
279282 if err := cli .setConsoleOpts (csconfig .CONSOLE_CONFIGS , false ); err != nil {
280283 return err
281284 }
285+
282286 log .Infof ("All features have been disabled" )
283287 } else {
284288 if len (args ) == 0 {
285289 return errors .New ("you must specify at least one feature to disable" )
286290 }
291+
287292 if err := cli .setConsoleOpts (args , false ); err != nil {
288293 return err
289294 }
295+
290296 log .Infof ("%v have been disabled" , args )
291297 }
292298
@@ -312,6 +318,7 @@ func (cli *cliConsole) newStatusCmd() *cobra.Command {
312318 RunE : func (_ * cobra.Command , _ []string ) error {
313319 cfg := cli .cfg ()
314320 consoleCfg := cfg .API .Server .ConsoleConfig
321+
315322 switch cfg .Cscli .Output {
316323 case "human" :
317324 cmdConsoleStatusTable (color .Output , cfg .Cscli .Color , * consoleCfg )
@@ -323,13 +330,16 @@ func (cli *cliConsole) newStatusCmd() *cobra.Command {
323330 csconfig .SEND_CONTEXT : consoleCfg .ShareContext ,
324331 csconfig .CONSOLE_MANAGEMENT : consoleCfg .ConsoleManagement ,
325332 }
333+
326334 data , err := json .MarshalIndent (out , "" , " " )
327335 if err != nil {
328336 return fmt .Errorf ("failed to serialize configuration: %w" , err )
329337 }
338+
330339 fmt .Fprintln (os .Stdout , string (data ))
331340 case "raw" :
332341 csvwriter := csv .NewWriter (os .Stdout )
342+
333343 err := csvwriter .Write ([]string {"option" , "enabled" })
334344 if err != nil {
335345 return err
@@ -348,6 +358,7 @@ func (cli *cliConsole) newStatusCmd() *cobra.Command {
348358 return err
349359 }
350360 }
361+
351362 csvwriter .Flush ()
352363 }
353364
@@ -385,7 +396,7 @@ func (cli *cliConsole) setConsoleOpts(args []string, wanted bool) error {
385396 for _ , arg := range args {
386397 switch arg {
387398 case csconfig .CONSOLE_MANAGEMENT :
388- /* for each flag check if it's already set before setting it*/
399+ // for each flag check if it's already set before setting it
389400 if consoleCfg .ConsoleManagement != nil && * consoleCfg .ConsoleManagement == wanted {
390401 log .Debugf ("%s already set to %t" , csconfig .CONSOLE_MANAGEMENT , wanted )
391402 } else {
@@ -397,7 +408,7 @@ func (cli *cliConsole) setConsoleOpts(args []string, wanted bool) error {
397408 changed := false
398409 if wanted && cfg .API .Server .OnlineClient .Credentials .PapiURL == "" {
399410 changed = true
400- cfg .API .Server .OnlineClient .Credentials .PapiURL = types .PAPIBaseURL
411+ cfg .API .Server .OnlineClient .Credentials .PapiURL = csconfig .PAPIBaseURL
401412 } else if ! wanted && cfg .API .Server .OnlineClient .Credentials .PapiURL != "" {
402413 changed = true
403414 cfg .API .Server .OnlineClient .Credentials .PapiURL = ""
@@ -418,31 +429,31 @@ func (cli *cliConsole) setConsoleOpts(args []string, wanted bool) error {
418429 }
419430 }
420431 case csconfig .SEND_CUSTOM_SCENARIOS :
421- /* for each flag check if it's already set before setting it*/
432+ // for each flag check if it's already set before setting it
422433 if consoleCfg .ShareCustomScenarios != nil && * consoleCfg .ShareCustomScenarios == wanted {
423434 log .Debugf ("%s already set to %t" , csconfig .SEND_CUSTOM_SCENARIOS , wanted )
424435 } else {
425436 log .Infof ("%s set to %t" , csconfig .SEND_CUSTOM_SCENARIOS , wanted )
426437 consoleCfg .ShareCustomScenarios = ptr .Of (wanted )
427438 }
428439 case csconfig .SEND_TAINTED_SCENARIOS :
429- /* for each flag check if it's already set before setting it*/
440+ // for each flag check if it's already set before setting it
430441 if consoleCfg .ShareTaintedScenarios != nil && * consoleCfg .ShareTaintedScenarios == wanted {
431442 log .Debugf ("%s already set to %t" , csconfig .SEND_TAINTED_SCENARIOS , wanted )
432443 } else {
433444 log .Infof ("%s set to %t" , csconfig .SEND_TAINTED_SCENARIOS , wanted )
434445 consoleCfg .ShareTaintedScenarios = ptr .Of (wanted )
435446 }
436447 case csconfig .SEND_MANUAL_SCENARIOS :
437- /* for each flag check if it's already set before setting it*/
448+ // for each flag check if it's already set before setting it
438449 if consoleCfg .ShareManualDecisions != nil && * consoleCfg .ShareManualDecisions == wanted {
439450 log .Debugf ("%s already set to %t" , csconfig .SEND_MANUAL_SCENARIOS , wanted )
440451 } else {
441452 log .Infof ("%s set to %t" , csconfig .SEND_MANUAL_SCENARIOS , wanted )
442453 consoleCfg .ShareManualDecisions = ptr .Of (wanted )
443454 }
444455 case csconfig .SEND_CONTEXT :
445- /* for each flag check if it's already set before setting it*/
456+ // for each flag check if it's already set before setting it
446457 if consoleCfg .ShareContext != nil && * consoleCfg .ShareContext == wanted {
447458 log .Debugf ("%s already set to %t" , csconfig .SEND_CONTEXT , wanted )
448459 } else {
0 commit comments