alteredCoder 3 vuotta sitten
vanhempi
commit
04f7dbd1f5
2 muutettua tiedostoa jossa 29 lisäystä ja 1 poistoa
  1. 3 1
      pkg/csconfig/api.go
  2. 26 0
      pkg/csconfig/console.go

+ 3 - 1
pkg/csconfig/api.go

@@ -107,7 +107,9 @@ func (c *Config) LoadAPIServer() error {
 		if err := c.API.Server.LoadProfiles(); err != nil {
 		if err := c.API.Server.LoadProfiles(); err != nil {
 			return errors.Wrap(err, "while loading profiles for LAPI")
 			return errors.Wrap(err, "while loading profiles for LAPI")
 		}
 		}
-
+		if c.API.Server.ConsoleConfigPath == "" {
+			c.API.Server.ConsoleConfigPath = DefaultConsoleConfgFilePath
+		}
 		if err := c.API.Server.LoadConsoleConfig(); err != nil {
 		if err := c.API.Server.LoadConsoleConfig(); err != nil {
 			return errors.Wrap(err, "while loading console options")
 			return errors.Wrap(err, "while loading console options")
 		}
 		}

+ 26 - 0
pkg/csconfig/console.go

@@ -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
+}