fix #1385: .yaml.local (#1497)

Added support for .yaml.local files to override values in .yaml
This commit is contained in:
mmetc 2022-05-18 10:08:37 +02:00 committed by GitHub
parent 635e633520
commit 98f2ac5e7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 1088 additions and 42 deletions

View file

@ -2,10 +2,9 @@ package csconfig
import (
"fmt"
"io/ioutil"
"path/filepath"
"github.com/pkg/errors"
"github.com/crowdsecurity/crowdsec/pkg/yamlpatch"
"gopkg.in/yaml.v2"
)
@ -39,9 +38,11 @@ func (c *Config) LoadSimulation() error {
if c.ConfigPaths.SimulationFilePath == "" {
c.ConfigPaths.SimulationFilePath = filepath.Clean(c.ConfigPaths.ConfigDir + "/simulation.yaml")
}
rcfg, err := ioutil.ReadFile(c.ConfigPaths.SimulationFilePath)
patcher := yamlpatch.NewPatcher(c.ConfigPaths.SimulationFilePath, ".local")
rcfg, err := patcher.MergedPatchContent()
if err != nil {
return errors.Wrapf(err, "while reading '%s'", c.ConfigPaths.SimulationFilePath)
return err
}
if err := yaml.UnmarshalStrict(rcfg, &simCfg); err != nil {
return fmt.Errorf("while unmarshaling simulation file '%s' : %s", c.ConfigPaths.SimulationFilePath, err)