minor reverts and tweaks (#2639)
This commit is contained in:
parent
0c030a3bb5
commit
f7c5726a0a
5 changed files with 10 additions and 25 deletions
|
@ -55,7 +55,6 @@ func initConfig() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// XXX: check all the defaults
|
|
||||||
csConfig = csconfig.NewDefaultConfig()
|
csConfig = csconfig.NewDefaultConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,9 +100,6 @@ func GetConfig() Config {
|
||||||
return globalConfig
|
return globalConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: We must not have a different behavior with an empty vs a missing configuration file.
|
|
||||||
// XXX: For this reason, all defaults have to come from NewConfig(). The following function should
|
|
||||||
// XXX: be replaced
|
|
||||||
func NewDefaultConfig() *Config {
|
func NewDefaultConfig() *Config {
|
||||||
logLevel := log.InfoLevel
|
logLevel := log.InfoLevel
|
||||||
commonCfg := CommonCfg{
|
commonCfg := CommonCfg{
|
||||||
|
|
|
@ -18,22 +18,18 @@ type ConfigurationPaths struct {
|
||||||
func (c *Config) loadConfigurationPaths() error {
|
func (c *Config) loadConfigurationPaths() error {
|
||||||
var err error
|
var err error
|
||||||
if c.ConfigPaths == nil {
|
if c.ConfigPaths == nil {
|
||||||
// XXX: test me
|
|
||||||
return fmt.Errorf("no configuration paths provided")
|
return fmt.Errorf("no configuration paths provided")
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.ConfigPaths.DataDir == "" {
|
if c.ConfigPaths.DataDir == "" {
|
||||||
// XXX: test me
|
|
||||||
return fmt.Errorf("please provide a data directory with the 'data_dir' directive in the 'config_paths' section")
|
return fmt.Errorf("please provide a data directory with the 'data_dir' directive in the 'config_paths' section")
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.ConfigPaths.HubDir == "" {
|
if c.ConfigPaths.HubDir == "" {
|
||||||
// XXX: test me
|
|
||||||
c.ConfigPaths.HubDir = filepath.Clean(c.ConfigPaths.ConfigDir + "/hub")
|
c.ConfigPaths.HubDir = filepath.Clean(c.ConfigPaths.ConfigDir + "/hub")
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.ConfigPaths.HubIndexFile == "" {
|
if c.ConfigPaths.HubIndexFile == "" {
|
||||||
// XXX: test me
|
|
||||||
c.ConfigPaths.HubIndexFile = filepath.Clean(c.ConfigPaths.HubDir + "/.index.json")
|
c.ConfigPaths.HubIndexFile = filepath.Clean(c.ConfigPaths.HubDir + "/.index.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -112,21 +113,13 @@ func (h *Hub) getItemFileInfo(path string) (*itemFileInfo, error) {
|
||||||
|
|
||||||
log.Tracef("stage:%s ftype:%s", ret.stage, ret.ftype)
|
log.Tracef("stage:%s ftype:%s", ret.stage, ret.ftype)
|
||||||
|
|
||||||
if ret.stage == SCENARIOS {
|
if ret.ftype != PARSERS && ret.ftype != POSTOVERFLOWS {
|
||||||
ret.ftype = SCENARIOS
|
if !slices.Contains(ItemTypes, ret.stage) {
|
||||||
|
return nil, fmt.Errorf("unknown configuration type for file '%s'", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.ftype = ret.stage
|
||||||
ret.stage = ""
|
ret.stage = ""
|
||||||
} else if ret.stage == COLLECTIONS {
|
|
||||||
ret.ftype = COLLECTIONS
|
|
||||||
ret.stage = ""
|
|
||||||
} else if ret.stage == APPSEC_RULES {
|
|
||||||
ret.ftype = APPSEC_RULES
|
|
||||||
ret.stage = ""
|
|
||||||
} else if ret.stage == APPSEC_CONFIGS {
|
|
||||||
ret.ftype = APPSEC_CONFIGS
|
|
||||||
ret.stage = ""
|
|
||||||
} else if ret.ftype != PARSERS && ret.ftype != POSTOVERFLOWS {
|
|
||||||
// it's a PARSER / POSTOVERFLOW with a stage
|
|
||||||
return nil, fmt.Errorf("unknown configuration type for file '%s'", path)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Tracef("CORRECTED [%s] by [%s] in stage [%s] of type [%s]", ret.fname, ret.fauthor, ret.stage, ret.ftype)
|
log.Tracef("CORRECTED [%s] by [%s] in stage [%s] of type [%s]", ret.fname, ret.fauthor, ret.stage, ret.ftype)
|
||||||
|
|
|
@ -36,7 +36,7 @@ teardown() {
|
||||||
rune -0 cscli hub list
|
rune -0 cscli hub list
|
||||||
assert_output "No items to display"
|
assert_output "No items to display"
|
||||||
rune -0 cscli hub list -o json
|
rune -0 cscli hub list -o json
|
||||||
assert_json '{appsec-configs:[],appsec-rules:[],parsers:[],scenarios:[],collections:[],postoverflows:[]}'
|
assert_json '{"appsec-configs":[],"appsec-rules":[],parsers:[],scenarios:[],collections:[],postoverflows:[]}'
|
||||||
rune -0 cscli hub list -o raw
|
rune -0 cscli hub list -o raw
|
||||||
assert_output 'name,status,version,description,type'
|
assert_output 'name,status,version,description,type'
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ teardown() {
|
||||||
assert_line "collections"
|
assert_line "collections"
|
||||||
rune -0 cscli hub types -o human
|
rune -0 cscli hub types -o human
|
||||||
rune -0 yq -o json <(output)
|
rune -0 yq -o json <(output)
|
||||||
assert_json '["appsec-configs","appsec-rules","parsers","postoverflows","scenarios","collections"]'
|
assert_json '["parsers","postoverflows","scenarios","appsec-configs","appsec-rules","collections"]'
|
||||||
rune -0 cscli hub types -o json
|
rune -0 cscli hub types -o json
|
||||||
assert_json '["appsec-configs","appsec-rules","parsers","postoverflows","scenarios","collections"]'
|
assert_json '["parsers","postoverflows","scenarios","appsec-configs","appsec-rules","collections"]'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue