minor reverts and tweaks (#2639)

This commit is contained in:
mmetc 2023-12-05 17:06:25 +01:00 committed by GitHub
parent 0c030a3bb5
commit f7c5726a0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 25 deletions

View file

@ -55,7 +55,6 @@ func initConfig() {
log.Fatal(err)
}
} else {
// XXX: check all the defaults
csConfig = csconfig.NewDefaultConfig()
}

View file

@ -100,9 +100,6 @@ func GetConfig() Config {
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 {
logLevel := log.InfoLevel
commonCfg := CommonCfg{

View file

@ -18,22 +18,18 @@ type ConfigurationPaths struct {
func (c *Config) loadConfigurationPaths() error {
var err error
if c.ConfigPaths == nil {
// XXX: test me
return fmt.Errorf("no configuration paths provided")
}
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")
}
if c.ConfigPaths.HubDir == "" {
// XXX: test me
c.ConfigPaths.HubDir = filepath.Clean(c.ConfigPaths.ConfigDir + "/hub")
}
if c.ConfigPaths.HubIndexFile == "" {
// XXX: test me
c.ConfigPaths.HubIndexFile = filepath.Clean(c.ConfigPaths.HubDir + "/.index.json")
}

View file

@ -7,6 +7,7 @@ import (
"io"
"os"
"path/filepath"
"slices"
"sort"
"strings"
@ -112,21 +113,13 @@ func (h *Hub) getItemFileInfo(path string) (*itemFileInfo, error) {
log.Tracef("stage:%s ftype:%s", ret.stage, ret.ftype)
if ret.stage == SCENARIOS {
ret.ftype = SCENARIOS
if ret.ftype != PARSERS && ret.ftype != POSTOVERFLOWS {
if !slices.Contains(ItemTypes, ret.stage) {
return nil, fmt.Errorf("unknown configuration type for file '%s'", path)
}
ret.ftype = 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)

View file

@ -36,7 +36,7 @@ teardown() {
rune -0 cscli hub list
assert_output "No items to display"
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
assert_output 'name,status,version,description,type'
@ -137,7 +137,7 @@ teardown() {
assert_line "collections"
rune -0 cscli hub types -o human
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
assert_json '["appsec-configs","appsec-rules","parsers","postoverflows","scenarios","collections"]'
assert_json '["parsers","postoverflows","scenarios","appsec-configs","appsec-rules","collections"]'
}