update output

This commit is contained in:
alteredCoder 2021-10-07 15:40:14 +02:00
parent 0c32f2574b
commit 553e833d75
2 changed files with 23 additions and 5 deletions

View file

@ -2,6 +2,7 @@ package main
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"net/url" "net/url"
@ -13,6 +14,7 @@ import (
"github.com/go-openapi/strfmt" "github.com/go-openapi/strfmt"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"gopkg.in/yaml.v2"
) )
func NewConsoleCmd() *cobra.Command { func NewConsoleCmd() *cobra.Command {
@ -153,10 +155,26 @@ Disable given information push to the central API.`,
Example: "status alerts-tainted", Example: "status alerts-tainted",
DisableAutoGenTag: true, DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("share decisions\t%t\n", *csConfig.API.Server.ConsoleConfig.ShareDecisions) switch csConfig.Cscli.Output {
fmt.Printf("share tainted scenarios alerts\t%t\n", *csConfig.API.Server.ConsoleConfig.ShareTaintedScenarios) case "human":
fmt.Printf("share custom scenarios alerts\t%t\n", *csConfig.API.Server.ConsoleConfig.ShareCustomScenarios) fmt.Printf("Sharing options enabled:\n")
fmt.Printf("share manual decisions\t%t\n", *csConfig.API.Server.ConsoleConfig.ShareManualDecisions) fmt.Printf(" - Share Decisions : %t\n", *csConfig.API.Server.ConsoleConfig.ShareDecisions)
fmt.Printf(" - Share tainted scenarios alerts : %t\n", *csConfig.API.Server.ConsoleConfig.ShareTaintedScenarios)
fmt.Printf(" - Share custom scenarios alerts : %t\n", *csConfig.API.Server.ConsoleConfig.ShareCustomScenarios)
fmt.Printf(" - Share manual decisions alerts : %t\n", *csConfig.API.Server.ConsoleConfig.ShareManualDecisions)
case "json":
data, err := json.MarshalIndent(csConfig.API.Server.ConsoleConfig, "", " ")
if err != nil {
log.Fatalf("failed to marshal configuration: %s", err)
}
fmt.Printf("%s\n", string(data))
case "raw":
data, err := yaml.Marshal(csConfig.API.Server.ConsoleConfig)
if err != nil {
log.Fatalf("failed to marshal configuration: %s", err)
}
fmt.Printf("%s\n", string(data))
}
}, },
} }

View file

@ -64,7 +64,7 @@ func (c *LocalApiServerCfg) LoadConsoleConfig() error {
log.Debugf("no share_decisions scenarios found, setting to false") log.Debugf("no share_decisions scenarios found, setting to false")
c.ConsoleConfig.ShareDecisions = new(bool) c.ConsoleConfig.ShareDecisions = new(bool)
} }
log.Infof("Console configuration '%s' loaded successfully", c.ConsoleConfigPath) log.Debugf("Console configuration '%s' loaded successfully", c.ConsoleConfigPath)
return nil return nil
} }