|
@@ -5,6 +5,7 @@ import (
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
"os"
|
|
"os"
|
|
|
|
|
|
|
|
+ "github.com/pkg/errors"
|
|
log "github.com/sirupsen/logrus"
|
|
log "github.com/sirupsen/logrus"
|
|
"gopkg.in/yaml.v2"
|
|
"gopkg.in/yaml.v2"
|
|
)
|
|
)
|
|
@@ -16,6 +17,8 @@ const (
|
|
SEND_LIVE_DECISIONS = "live_decisions"
|
|
SEND_LIVE_DECISIONS = "live_decisions"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+var DefaultConsoleConfgFilePath = "/etc/crowdsec/console_config.yaml"
|
|
|
|
+
|
|
var CONSOLE_CONFIGS = []string{SEND_CUSTOM_SCENARIOS, SEND_LIVE_DECISIONS, SEND_MANUAL_SCENARIOS, SEND_TAINTED_SCENARIOS}
|
|
var CONSOLE_CONFIGS = []string{SEND_CUSTOM_SCENARIOS, SEND_LIVE_DECISIONS, SEND_MANUAL_SCENARIOS, SEND_TAINTED_SCENARIOS}
|
|
|
|
|
|
type ConsoleConfig struct {
|
|
type ConsoleConfig struct {
|
|
@@ -29,6 +32,10 @@ func (c *LocalApiServerCfg) LoadConsoleConfig() error {
|
|
c.ConsoleConfig = &ConsoleConfig{}
|
|
c.ConsoleConfig = &ConsoleConfig{}
|
|
if _, err := os.Stat(c.ConsoleConfigPath); err != nil && os.IsNotExist(err) {
|
|
if _, err := os.Stat(c.ConsoleConfigPath); err != nil && os.IsNotExist(err) {
|
|
log.Debugf("no console configuration to load")
|
|
log.Debugf("no console configuration to load")
|
|
|
|
+ c.ConsoleConfig.ShareCustomScenarios = new(bool)
|
|
|
|
+ c.ConsoleConfig.ShareTaintedScenarios = new(bool)
|
|
|
|
+ c.ConsoleConfig.ShareManualDecisions = new(bool)
|
|
|
|
+ c.ConsoleConfig.ShareDecisions = new(bool)
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
@@ -61,3 +68,22 @@ func (c *LocalApiServerCfg) LoadConsoleConfig() error {
|
|
|
|
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func (c *LocalApiServerCfg) DumpConsoleConfig() error {
|
|
|
|
+ var out []byte
|
|
|
|
+ var err error
|
|
|
|
+
|
|
|
|
+ if out, err = yaml.Marshal(c.ConsoleConfig); err != nil {
|
|
|
|
+ return errors.Wrapf(err, "while marshaling ConsoleConfig (for %s)", c.ConsoleConfigPath)
|
|
|
|
+ }
|
|
|
|
+ if c.ConsoleConfigPath == "" {
|
|
|
|
+ log.Debugf("Empty console_path, defaulting to %s", DefaultConsoleConfgFilePath)
|
|
|
|
+ c.ConsoleConfigPath = DefaultConsoleConfgFilePath
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if err := os.WriteFile(c.ConsoleConfigPath, out, 0600); err != nil {
|
|
|
|
+ return errors.Wrapf(err, "while dumping console config to %s", c.ConsoleConfigPath)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return nil
|
|
|
|
+}
|