2021-06-28 15:34:19 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-01-13 15:46:16 +00:00
|
|
|
"encoding/csv"
|
|
|
|
"encoding/json"
|
2021-06-28 15:34:19 +00:00
|
|
|
"fmt"
|
|
|
|
"net/url"
|
2022-01-13 15:46:16 +00:00
|
|
|
"os"
|
2021-06-28 15:34:19 +00:00
|
|
|
|
2022-10-13 10:28:24 +00:00
|
|
|
"github.com/fatih/color"
|
2022-10-07 09:05:35 +00:00
|
|
|
"github.com/go-openapi/strfmt"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/spf13/cobra"
|
2023-03-03 16:03:21 +00:00
|
|
|
"gopkg.in/yaml.v3"
|
2022-10-07 09:05:35 +00:00
|
|
|
|
2023-07-28 14:35:08 +00:00
|
|
|
"github.com/crowdsecurity/go-cs-lib/ptr"
|
|
|
|
"github.com/crowdsecurity/go-cs-lib/version"
|
2023-05-23 08:52:47 +00:00
|
|
|
|
2023-12-19 16:20:09 +00:00
|
|
|
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/require"
|
2021-06-28 15:34:19 +00:00
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
|
2022-01-13 15:46:16 +00:00
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
2021-06-28 15:34:19 +00:00
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
|
2022-01-13 15:46:16 +00:00
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/types"
|
2021-06-28 15:34:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func NewConsoleCmd() *cobra.Command {
|
|
|
|
var cmdConsole = &cobra.Command{
|
2021-09-03 10:56:17 +00:00
|
|
|
Use: "console [action]",
|
|
|
|
Short: "Manage interaction with Crowdsec console (https://app.crowdsec.net)",
|
|
|
|
Args: cobra.MinimumNArgs(1),
|
|
|
|
DisableAutoGenTag: true,
|
2021-06-28 15:34:19 +00:00
|
|
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
2023-07-27 15:02:20 +00:00
|
|
|
if err := require.LAPI(csConfig); err != nil {
|
|
|
|
return err
|
2021-06-28 15:34:19 +00:00
|
|
|
}
|
2023-07-27 15:02:20 +00:00
|
|
|
if err := require.CAPI(csConfig); err != nil {
|
|
|
|
return err
|
2022-01-13 15:46:16 +00:00
|
|
|
}
|
2023-08-29 09:44:23 +00:00
|
|
|
if err := require.CAPIRegistered(csConfig); err != nil {
|
2023-07-27 15:02:20 +00:00
|
|
|
return err
|
2021-06-28 15:34:19 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-10-26 13:33:17 +00:00
|
|
|
name := ""
|
2022-04-20 11:34:17 +00:00
|
|
|
overwrite := false
|
2021-10-26 13:33:17 +00:00
|
|
|
tags := []string{}
|
|
|
|
|
2021-06-28 15:34:19 +00:00
|
|
|
cmdEnroll := &cobra.Command{
|
|
|
|
Use: "enroll [enroll-key]",
|
|
|
|
Short: "Enroll this instance to https://app.crowdsec.net [requires local API]",
|
|
|
|
Long: `
|
|
|
|
Enroll this instance to https://app.crowdsec.net
|
|
|
|
|
|
|
|
You can get your enrollment key by creating an account on https://app.crowdsec.net.
|
|
|
|
After running this command your will need to validate the enrollment in the webapp.`,
|
2021-10-26 13:33:17 +00:00
|
|
|
Example: `cscli console enroll YOUR-ENROLL-KEY
|
|
|
|
cscli console enroll --name [instance_name] YOUR-ENROLL-KEY
|
|
|
|
cscli console enroll --name [instance_name] --tags [tag_1] --tags [tag_2] YOUR-ENROLL-KEY
|
|
|
|
`,
|
2021-08-31 13:03:47 +00:00
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
DisableAutoGenTag: true,
|
2023-08-29 09:44:23 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2021-06-28 15:34:19 +00:00
|
|
|
password := strfmt.Password(csConfig.API.Server.OnlineClient.Credentials.Password)
|
|
|
|
apiURL, err := url.Parse(csConfig.API.Server.OnlineClient.Credentials.URL)
|
|
|
|
if err != nil {
|
2023-08-29 09:44:23 +00:00
|
|
|
return fmt.Errorf("could not parse CAPI URL: %s", err)
|
2021-06-28 15:34:19 +00:00
|
|
|
}
|
|
|
|
|
2023-12-19 16:20:09 +00:00
|
|
|
hub, err := require.Hub(csConfig, nil, nil)
|
2023-11-24 14:57:32 +00:00
|
|
|
if err != nil {
|
2023-08-29 09:44:23 +00:00
|
|
|
return err
|
2021-06-28 15:34:19 +00:00
|
|
|
}
|
|
|
|
|
2023-11-24 14:57:32 +00:00
|
|
|
scenarios, err := hub.GetInstalledItemNames(cwhub.SCENARIOS)
|
2021-06-28 15:34:19 +00:00
|
|
|
if err != nil {
|
2023-08-29 09:44:23 +00:00
|
|
|
return fmt.Errorf("failed to get installed scenarios: %s", err)
|
2021-06-28 15:34:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(scenarios) == 0 {
|
|
|
|
scenarios = make([]string, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
c, _ := apiclient.NewClient(&apiclient.Config{
|
|
|
|
MachineID: csConfig.API.Server.OnlineClient.Credentials.Login,
|
|
|
|
Password: password,
|
|
|
|
Scenarios: scenarios,
|
2023-05-23 08:52:47 +00:00
|
|
|
UserAgent: fmt.Sprintf("crowdsec/%s", version.String()),
|
2021-06-28 15:34:19 +00:00
|
|
|
URL: apiURL,
|
2023-02-06 13:06:14 +00:00
|
|
|
VersionPrefix: "v3",
|
2021-06-28 15:34:19 +00:00
|
|
|
})
|
2022-04-20 11:34:17 +00:00
|
|
|
resp, err := c.Auth.EnrollWatcher(context.Background(), args[0], name, tags, overwrite)
|
2021-06-28 15:34:19 +00:00
|
|
|
if err != nil {
|
2023-08-29 09:44:23 +00:00
|
|
|
return fmt.Errorf("could not enroll instance: %s", err)
|
2021-06-28 15:34:19 +00:00
|
|
|
}
|
2022-04-20 11:34:17 +00:00
|
|
|
if resp.Response.StatusCode == 200 && !overwrite {
|
2022-06-22 07:38:23 +00:00
|
|
|
log.Warning("Instance already enrolled. You can use '--overwrite' to force enroll")
|
2023-08-29 09:44:23 +00:00
|
|
|
return nil
|
2022-04-20 11:34:17 +00:00
|
|
|
}
|
2022-01-13 15:46:16 +00:00
|
|
|
|
2023-08-29 09:44:23 +00:00
|
|
|
if err := SetConsoleOpts([]string{csconfig.SEND_MANUAL_SCENARIOS, csconfig.SEND_TAINTED_SCENARIOS}, true); err != nil {
|
|
|
|
return err
|
2022-01-24 16:22:16 +00:00
|
|
|
}
|
2023-08-29 09:44:23 +00:00
|
|
|
|
|
|
|
log.Info("Enabled tainted&manual alerts sharing, see 'cscli console status'.")
|
|
|
|
log.Info("Watcher successfully enrolled. Visit https://app.crowdsec.net to accept it.")
|
|
|
|
log.Info("Please restart crowdsec after accepting the enrollment.")
|
|
|
|
return nil
|
2021-06-28 15:34:19 +00:00
|
|
|
},
|
|
|
|
}
|
2021-10-26 13:33:17 +00:00
|
|
|
cmdEnroll.Flags().StringVarP(&name, "name", "n", "", "Name to display in the console")
|
2022-04-20 11:34:17 +00:00
|
|
|
cmdEnroll.Flags().BoolVarP(&overwrite, "overwrite", "", false, "Force enroll the instance")
|
2021-10-26 13:33:17 +00:00
|
|
|
cmdEnroll.Flags().StringSliceVarP(&tags, "tags", "t", tags, "Tags to display in the console")
|
2021-06-28 15:34:19 +00:00
|
|
|
cmdConsole.AddCommand(cmdEnroll)
|
2022-01-13 15:46:16 +00:00
|
|
|
|
|
|
|
var enableAll, disableAll bool
|
|
|
|
|
|
|
|
cmdEnable := &cobra.Command{
|
2023-01-04 15:50:02 +00:00
|
|
|
Use: "enable [option]",
|
|
|
|
Short: "Enable a console option",
|
|
|
|
Example: "sudo cscli console enable tainted",
|
2022-01-13 15:46:16 +00:00
|
|
|
Long: `
|
|
|
|
Enable given information push to the central API. Allows to empower the console`,
|
|
|
|
ValidArgs: csconfig.CONSOLE_CONFIGS,
|
|
|
|
DisableAutoGenTag: true,
|
2023-08-29 09:44:23 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2022-01-13 15:46:16 +00:00
|
|
|
if enableAll {
|
2023-08-29 09:44:23 +00:00
|
|
|
if err := SetConsoleOpts(csconfig.CONSOLE_CONFIGS, true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-02-24 09:24:04 +00:00
|
|
|
log.Infof("All features have been enabled successfully")
|
2022-01-13 15:46:16 +00:00
|
|
|
} else {
|
2022-02-24 09:24:04 +00:00
|
|
|
if len(args) == 0 {
|
2023-08-29 09:44:23 +00:00
|
|
|
return fmt.Errorf("you must specify at least one feature to enable")
|
|
|
|
}
|
|
|
|
if err := SetConsoleOpts(args, true); err != nil {
|
|
|
|
return err
|
2022-02-24 09:24:04 +00:00
|
|
|
}
|
|
|
|
log.Infof("%v have been enabled", args)
|
2022-01-13 15:46:16 +00:00
|
|
|
}
|
|
|
|
log.Infof(ReloadMessage())
|
2023-08-29 09:44:23 +00:00
|
|
|
return nil
|
2022-01-13 15:46:16 +00:00
|
|
|
},
|
|
|
|
}
|
2023-01-04 15:50:02 +00:00
|
|
|
cmdEnable.Flags().BoolVarP(&enableAll, "all", "a", false, "Enable all console options")
|
2022-01-13 15:46:16 +00:00
|
|
|
cmdConsole.AddCommand(cmdEnable)
|
|
|
|
|
|
|
|
cmdDisable := &cobra.Command{
|
2023-01-04 15:50:02 +00:00
|
|
|
Use: "disable [option]",
|
|
|
|
Short: "Disable a console option",
|
|
|
|
Example: "sudo cscli console disable tainted",
|
2022-01-13 15:46:16 +00:00
|
|
|
Long: `
|
|
|
|
Disable given information push to the central API.`,
|
|
|
|
ValidArgs: csconfig.CONSOLE_CONFIGS,
|
|
|
|
DisableAutoGenTag: true,
|
2023-08-29 09:44:23 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2022-01-13 15:46:16 +00:00
|
|
|
if disableAll {
|
2023-08-29 09:44:23 +00:00
|
|
|
if err := SetConsoleOpts(csconfig.CONSOLE_CONFIGS, false); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-01-13 15:46:16 +00:00
|
|
|
log.Infof("All features have been disabled")
|
|
|
|
} else {
|
2023-08-29 09:44:23 +00:00
|
|
|
if err := SetConsoleOpts(args, false); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-01-13 15:46:16 +00:00
|
|
|
log.Infof("%v have been disabled", args)
|
|
|
|
}
|
2023-08-29 09:44:23 +00:00
|
|
|
|
2022-01-13 15:46:16 +00:00
|
|
|
log.Infof(ReloadMessage())
|
2023-08-29 09:44:23 +00:00
|
|
|
return nil
|
2022-01-13 15:46:16 +00:00
|
|
|
},
|
|
|
|
}
|
2023-01-04 15:50:02 +00:00
|
|
|
cmdDisable.Flags().BoolVarP(&disableAll, "all", "a", false, "Disable all console options")
|
2022-01-13 15:46:16 +00:00
|
|
|
cmdConsole.AddCommand(cmdDisable)
|
|
|
|
|
|
|
|
cmdConsoleStatus := &cobra.Command{
|
2023-08-29 09:44:23 +00:00
|
|
|
Use: "status",
|
|
|
|
Short: "Shows status of the console options",
|
2023-01-04 15:50:02 +00:00
|
|
|
Example: `sudo cscli console status`,
|
2022-01-13 15:46:16 +00:00
|
|
|
DisableAutoGenTag: true,
|
2023-08-29 09:44:23 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2022-01-13 15:46:16 +00:00
|
|
|
switch csConfig.Cscli.Output {
|
|
|
|
case "human":
|
2022-10-13 10:28:24 +00:00
|
|
|
cmdConsoleStatusTable(color.Output, *csConfig)
|
2022-01-13 15:46:16 +00:00
|
|
|
case "json":
|
2023-08-29 09:44:23 +00:00
|
|
|
c := csConfig.API.Server.ConsoleConfig
|
|
|
|
out := map[string](*bool){
|
2023-12-08 13:55:45 +00:00
|
|
|
csconfig.SEND_MANUAL_SCENARIOS: c.ShareManualDecisions,
|
|
|
|
csconfig.SEND_CUSTOM_SCENARIOS: c.ShareCustomScenarios,
|
2023-08-29 09:44:23 +00:00
|
|
|
csconfig.SEND_TAINTED_SCENARIOS: c.ShareTaintedScenarios,
|
2023-12-08 13:55:45 +00:00
|
|
|
csconfig.SEND_CONTEXT: c.ShareContext,
|
|
|
|
csconfig.CONSOLE_MANAGEMENT: c.ConsoleManagement,
|
2023-08-29 09:44:23 +00:00
|
|
|
}
|
|
|
|
data, err := json.MarshalIndent(out, "", " ")
|
2022-01-13 15:46:16 +00:00
|
|
|
if err != nil {
|
2023-08-29 09:44:23 +00:00
|
|
|
return fmt.Errorf("failed to marshal configuration: %s", err)
|
2022-01-13 15:46:16 +00:00
|
|
|
}
|
2023-08-29 09:44:23 +00:00
|
|
|
fmt.Println(string(data))
|
2022-01-13 15:46:16 +00:00
|
|
|
case "raw":
|
|
|
|
csvwriter := csv.NewWriter(os.Stdout)
|
|
|
|
err := csvwriter.Write([]string{"option", "enabled"})
|
|
|
|
if err != nil {
|
2023-08-29 09:44:23 +00:00
|
|
|
return err
|
2022-01-13 15:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rows := [][]string{
|
2023-01-31 13:47:44 +00:00
|
|
|
{csconfig.SEND_MANUAL_SCENARIOS, fmt.Sprintf("%t", *csConfig.API.Server.ConsoleConfig.ShareManualDecisions)},
|
|
|
|
{csconfig.SEND_CUSTOM_SCENARIOS, fmt.Sprintf("%t", *csConfig.API.Server.ConsoleConfig.ShareCustomScenarios)},
|
|
|
|
{csconfig.SEND_TAINTED_SCENARIOS, fmt.Sprintf("%t", *csConfig.API.Server.ConsoleConfig.ShareTaintedScenarios)},
|
|
|
|
{csconfig.SEND_CONTEXT, fmt.Sprintf("%t", *csConfig.API.Server.ConsoleConfig.ShareContext)},
|
2023-03-06 14:38:58 +00:00
|
|
|
{csconfig.CONSOLE_MANAGEMENT, fmt.Sprintf("%t", *csConfig.API.Server.ConsoleConfig.ConsoleManagement)},
|
2022-01-13 15:46:16 +00:00
|
|
|
}
|
|
|
|
for _, row := range rows {
|
|
|
|
err = csvwriter.Write(row)
|
|
|
|
if err != nil {
|
2023-08-29 09:44:23 +00:00
|
|
|
return err
|
2022-01-13 15:46:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
csvwriter.Flush()
|
|
|
|
}
|
2023-08-29 09:44:23 +00:00
|
|
|
return nil
|
2022-01-13 15:46:16 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
cmdConsole.AddCommand(cmdConsoleStatus)
|
2023-01-04 15:50:02 +00:00
|
|
|
|
2021-06-28 15:34:19 +00:00
|
|
|
return cmdConsole
|
|
|
|
}
|
2022-01-13 15:46:16 +00:00
|
|
|
|
2023-10-09 09:10:51 +00:00
|
|
|
func dumpConsoleConfig(c *csconfig.LocalApiServerCfg) error {
|
|
|
|
out, err := yaml.Marshal(c.ConsoleConfig)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("while marshaling ConsoleConfig (for %s): %w", c.ConsoleConfigPath, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.ConsoleConfigPath == "" {
|
|
|
|
c.ConsoleConfigPath = csconfig.DefaultConsoleConfigFilePath
|
|
|
|
log.Debugf("Empty console_path, defaulting to %s", c.ConsoleConfigPath)
|
|
|
|
}
|
|
|
|
|
2023-12-08 09:51:15 +00:00
|
|
|
if err := os.WriteFile(c.ConsoleConfigPath, out, 0o600); err != nil {
|
2023-10-09 09:10:51 +00:00
|
|
|
return fmt.Errorf("while dumping console config to %s: %w", c.ConsoleConfigPath, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-08-29 09:44:23 +00:00
|
|
|
func SetConsoleOpts(args []string, wanted bool) error {
|
2022-01-13 15:46:16 +00:00
|
|
|
for _, arg := range args {
|
|
|
|
switch arg {
|
2023-01-31 13:47:44 +00:00
|
|
|
case csconfig.CONSOLE_MANAGEMENT:
|
|
|
|
/*for each flag check if it's already set before setting it*/
|
2023-03-06 14:38:58 +00:00
|
|
|
if csConfig.API.Server.ConsoleConfig.ConsoleManagement != nil {
|
|
|
|
if *csConfig.API.Server.ConsoleConfig.ConsoleManagement == wanted {
|
2023-02-08 09:35:21 +00:00
|
|
|
log.Debugf("%s already set to %t", csconfig.CONSOLE_MANAGEMENT, wanted)
|
2023-01-31 13:47:44 +00:00
|
|
|
} else {
|
|
|
|
log.Infof("%s set to %t", csconfig.CONSOLE_MANAGEMENT, wanted)
|
2023-03-06 14:38:58 +00:00
|
|
|
*csConfig.API.Server.ConsoleConfig.ConsoleManagement = wanted
|
2023-01-31 13:47:44 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.Infof("%s set to %t", csconfig.CONSOLE_MANAGEMENT, wanted)
|
2023-05-25 13:43:39 +00:00
|
|
|
csConfig.API.Server.ConsoleConfig.ConsoleManagement = ptr.Of(wanted)
|
2023-01-31 13:47:44 +00:00
|
|
|
}
|
2024-01-03 09:55:41 +00:00
|
|
|
|
2023-03-03 16:03:21 +00:00
|
|
|
if csConfig.API.Server.OnlineClient.Credentials != nil {
|
|
|
|
changed := false
|
|
|
|
if wanted && csConfig.API.Server.OnlineClient.Credentials.PapiURL == "" {
|
|
|
|
changed = true
|
|
|
|
csConfig.API.Server.OnlineClient.Credentials.PapiURL = types.PAPIBaseURL
|
|
|
|
} else if !wanted && csConfig.API.Server.OnlineClient.Credentials.PapiURL != "" {
|
|
|
|
changed = true
|
|
|
|
csConfig.API.Server.OnlineClient.Credentials.PapiURL = ""
|
|
|
|
}
|
2024-01-03 09:55:41 +00:00
|
|
|
|
2023-03-03 16:03:21 +00:00
|
|
|
if changed {
|
|
|
|
fileContent, err := yaml.Marshal(csConfig.API.Server.OnlineClient.Credentials)
|
|
|
|
if err != nil {
|
2023-08-29 09:44:23 +00:00
|
|
|
return fmt.Errorf("cannot marshal credentials: %s", err)
|
2023-03-03 16:03:21 +00:00
|
|
|
}
|
2024-01-03 09:55:41 +00:00
|
|
|
|
2023-03-03 16:03:21 +00:00
|
|
|
log.Infof("Updating credentials file: %s", csConfig.API.Server.OnlineClient.CredentialsFilePath)
|
2024-01-03 09:55:41 +00:00
|
|
|
|
2023-12-08 09:51:15 +00:00
|
|
|
err = os.WriteFile(csConfig.API.Server.OnlineClient.CredentialsFilePath, fileContent, 0o600)
|
2023-03-03 16:03:21 +00:00
|
|
|
if err != nil {
|
2023-08-29 09:44:23 +00:00
|
|
|
return fmt.Errorf("cannot write credentials file: %s", err)
|
2023-03-03 16:03:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-13 15:46:16 +00:00
|
|
|
case csconfig.SEND_CUSTOM_SCENARIOS:
|
|
|
|
/*for each flag check if it's already set before setting it*/
|
|
|
|
if csConfig.API.Server.ConsoleConfig.ShareCustomScenarios != nil {
|
|
|
|
if *csConfig.API.Server.ConsoleConfig.ShareCustomScenarios == wanted {
|
2023-02-08 09:35:21 +00:00
|
|
|
log.Debugf("%s already set to %t", csconfig.SEND_CUSTOM_SCENARIOS, wanted)
|
2022-01-13 15:46:16 +00:00
|
|
|
} else {
|
|
|
|
log.Infof("%s set to %t", csconfig.SEND_CUSTOM_SCENARIOS, wanted)
|
|
|
|
*csConfig.API.Server.ConsoleConfig.ShareCustomScenarios = wanted
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.Infof("%s set to %t", csconfig.SEND_CUSTOM_SCENARIOS, wanted)
|
2023-05-25 13:43:39 +00:00
|
|
|
csConfig.API.Server.ConsoleConfig.ShareCustomScenarios = ptr.Of(wanted)
|
2022-01-13 15:46:16 +00:00
|
|
|
}
|
|
|
|
case csconfig.SEND_TAINTED_SCENARIOS:
|
|
|
|
/*for each flag check if it's already set before setting it*/
|
|
|
|
if csConfig.API.Server.ConsoleConfig.ShareTaintedScenarios != nil {
|
|
|
|
if *csConfig.API.Server.ConsoleConfig.ShareTaintedScenarios == wanted {
|
2023-02-08 09:35:21 +00:00
|
|
|
log.Debugf("%s already set to %t", csconfig.SEND_TAINTED_SCENARIOS, wanted)
|
2022-01-13 15:46:16 +00:00
|
|
|
} else {
|
|
|
|
log.Infof("%s set to %t", csconfig.SEND_TAINTED_SCENARIOS, wanted)
|
|
|
|
*csConfig.API.Server.ConsoleConfig.ShareTaintedScenarios = wanted
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.Infof("%s set to %t", csconfig.SEND_TAINTED_SCENARIOS, wanted)
|
2023-05-25 13:43:39 +00:00
|
|
|
csConfig.API.Server.ConsoleConfig.ShareTaintedScenarios = ptr.Of(wanted)
|
2022-01-13 15:46:16 +00:00
|
|
|
}
|
|
|
|
case csconfig.SEND_MANUAL_SCENARIOS:
|
|
|
|
/*for each flag check if it's already set before setting it*/
|
|
|
|
if csConfig.API.Server.ConsoleConfig.ShareManualDecisions != nil {
|
|
|
|
if *csConfig.API.Server.ConsoleConfig.ShareManualDecisions == wanted {
|
2023-02-08 09:35:21 +00:00
|
|
|
log.Debugf("%s already set to %t", csconfig.SEND_MANUAL_SCENARIOS, wanted)
|
2022-01-13 15:46:16 +00:00
|
|
|
} else {
|
|
|
|
log.Infof("%s set to %t", csconfig.SEND_MANUAL_SCENARIOS, wanted)
|
|
|
|
*csConfig.API.Server.ConsoleConfig.ShareManualDecisions = wanted
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.Infof("%s set to %t", csconfig.SEND_MANUAL_SCENARIOS, wanted)
|
2023-05-25 13:43:39 +00:00
|
|
|
csConfig.API.Server.ConsoleConfig.ShareManualDecisions = ptr.Of(wanted)
|
2022-01-13 15:46:16 +00:00
|
|
|
}
|
2023-01-04 15:50:02 +00:00
|
|
|
case csconfig.SEND_CONTEXT:
|
|
|
|
/*for each flag check if it's already set before setting it*/
|
|
|
|
if csConfig.API.Server.ConsoleConfig.ShareContext != nil {
|
|
|
|
if *csConfig.API.Server.ConsoleConfig.ShareContext == wanted {
|
2023-02-08 09:35:21 +00:00
|
|
|
log.Debugf("%s already set to %t", csconfig.SEND_CONTEXT, wanted)
|
2023-01-04 15:50:02 +00:00
|
|
|
} else {
|
|
|
|
log.Infof("%s set to %t", csconfig.SEND_CONTEXT, wanted)
|
|
|
|
*csConfig.API.Server.ConsoleConfig.ShareContext = wanted
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.Infof("%s set to %t", csconfig.SEND_CONTEXT, wanted)
|
2023-05-25 13:43:39 +00:00
|
|
|
csConfig.API.Server.ConsoleConfig.ShareContext = ptr.Of(wanted)
|
2023-01-04 15:50:02 +00:00
|
|
|
}
|
2022-01-13 15:46:16 +00:00
|
|
|
default:
|
2023-08-29 09:44:23 +00:00
|
|
|
return fmt.Errorf("unknown flag %s", arg)
|
2022-01-13 15:46:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-09 09:10:51 +00:00
|
|
|
if err := dumpConsoleConfig(csConfig.API.Server); err != nil {
|
2023-08-29 09:44:23 +00:00
|
|
|
return fmt.Errorf("failed writing console config: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2022-01-13 15:46:16 +00:00
|
|
|
}
|