Allow to override statics in hubtest. (#1495)
This commit is contained in:
parent
64369b5c2b
commit
8f111680bf
|
@ -41,6 +41,7 @@ cscli explain --dsn "file://myfile.log" --type nginx
|
||||||
fmt.Printf("Please provide --type flag\n")
|
fmt.Printf("Please provide --type flag\n")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
var f *os.File
|
||||||
|
|
||||||
// we create a temporary log file if a log line has been provided
|
// we create a temporary log file if a log line has been provided
|
||||||
if logLine != "" {
|
if logLine != "" {
|
||||||
|
@ -83,6 +84,7 @@ cscli explain --dsn "file://myfile.log" --type nginx
|
||||||
|
|
||||||
// rm the temporary log file if only a log line was provided
|
// rm the temporary log file if only a log line was provided
|
||||||
if logLine != "" {
|
if logLine != "" {
|
||||||
|
f.Close()
|
||||||
if err := os.Remove(logFile); err != nil {
|
if err := os.Remove(logFile); err != nil {
|
||||||
log.Fatalf("unable to remove tmp log file '%s': %+v", logFile, err)
|
log.Fatalf("unable to remove tmp log file '%s': %+v", logFile, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,18 +10,21 @@ import (
|
||||||
|
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
|
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
|
||||||
|
"github.com/crowdsecurity/crowdsec/pkg/parser"
|
||||||
|
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HubTestItemConfig struct {
|
type HubTestItemConfig struct {
|
||||||
Parsers []string `yaml:"parsers"`
|
Parsers []string `yaml:"parsers"`
|
||||||
Scenarios []string `yaml:"scenarios"`
|
Scenarios []string `yaml:"scenarios"`
|
||||||
PostOVerflows []string `yaml:"postoverflows"`
|
PostOVerflows []string `yaml:"postoverflows"`
|
||||||
LogFile string `yaml:"log_file"`
|
LogFile string `yaml:"log_file"`
|
||||||
LogType string `yaml:"log_type"`
|
LogType string `yaml:"log_type"`
|
||||||
Labels map[string]string `yaml:"labels"`
|
Labels map[string]string `yaml:"labels"`
|
||||||
IgnoreParsers bool `yaml:"ignore_parsers"` // if we test a scenario, we don't want to assert on Parser
|
IgnoreParsers bool `yaml:"ignore_parsers"` // if we test a scenario, we don't want to assert on Parser
|
||||||
|
OverrideStatics []types.ExtraField `yaml:"override_statics"` //Allow to override statics. Executed before s00
|
||||||
}
|
}
|
||||||
|
|
||||||
type HubIndex struct {
|
type HubIndex struct {
|
||||||
|
@ -377,6 +380,22 @@ func (t *HubTestItem) InstallHub() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(t.Config.OverrideStatics) > 0 {
|
||||||
|
n := parser.Node{
|
||||||
|
Name: "overrides",
|
||||||
|
Filter: "1==1",
|
||||||
|
Statics: t.Config.OverrideStatics,
|
||||||
|
}
|
||||||
|
b, err := yaml.Marshal(n)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to marshal overrides: %s", err)
|
||||||
|
}
|
||||||
|
tgtFilename := fmt.Sprintf("%s/parsers/s00-raw/00_overrides.yaml", t.RuntimePath)
|
||||||
|
if err := os.WriteFile(tgtFilename, b, os.ModePerm); err != nil {
|
||||||
|
return fmt.Errorf("unable to write overrides to '%s': %s", tgtFilename, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// load installed hub
|
// load installed hub
|
||||||
err := cwhub.GetHubIdx(t.RuntimeHubConfig)
|
err := cwhub.GetHubIdx(t.RuntimeHubConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue