This commit is contained in:
alteredCoder 2021-10-07 11:39:15 +02:00
parent 908b04028e
commit 04f7dbd1f5
2 changed files with 29 additions and 1 deletions

View file

@ -107,7 +107,9 @@ func (c *Config) LoadAPIServer() error {
if err := c.API.Server.LoadProfiles(); err != nil {
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 {
return errors.Wrap(err, "while loading console options")
}

View file

@ -5,6 +5,7 @@ import (
"io/ioutil"
"os"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)
@ -16,6 +17,8 @@ const (
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}
type ConsoleConfig struct {
@ -29,6 +32,10 @@ func (c *LocalApiServerCfg) LoadConsoleConfig() error {
c.ConsoleConfig = &ConsoleConfig{}
if _, err := os.Stat(c.ConsoleConfigPath); err != nil && os.IsNotExist(err) {
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
}
@ -61,3 +68,22 @@ func (c *LocalApiServerCfg) LoadConsoleConfig() error {
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
}