mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-11 12:25:53 +02:00
pkg/cwhub: simpler accessor methods (#3165)
* pkg/cwhub: simpler accessor methods - prefer higher level GetItemsByType, GetInstalledByType over GetItemMap - always send both appsec-rules and scenarios to api - explicit parameter for (case insensitive) sorted list of items - shorter code - assume itemType parameter makes sense, don't error * lint (gofumpt)
This commit is contained in:
parent
429418ffc6
commit
89aec7cf6b
19 changed files with 161 additions and 283 deletions
|
@ -66,21 +66,20 @@ func NewParsers(hub *cwhub.Hub) *Parsers {
|
|||
}
|
||||
|
||||
for _, itemType := range []string{cwhub.PARSERS, cwhub.POSTOVERFLOWS} {
|
||||
for _, hubParserItem := range hub.GetItemMap(itemType) {
|
||||
if hubParserItem.State.Installed {
|
||||
stagefile := Stagefile{
|
||||
Filename: hubParserItem.State.LocalPath,
|
||||
Stage: hubParserItem.Stage,
|
||||
}
|
||||
if itemType == cwhub.PARSERS {
|
||||
parsers.StageFiles = append(parsers.StageFiles, stagefile)
|
||||
}
|
||||
if itemType == cwhub.POSTOVERFLOWS {
|
||||
parsers.PovfwStageFiles = append(parsers.PovfwStageFiles, stagefile)
|
||||
}
|
||||
for _, hubParserItem := range hub.GetInstalledByType(itemType, false) {
|
||||
stagefile := Stagefile{
|
||||
Filename: hubParserItem.State.LocalPath,
|
||||
Stage: hubParserItem.Stage,
|
||||
}
|
||||
if itemType == cwhub.PARSERS {
|
||||
parsers.StageFiles = append(parsers.StageFiles, stagefile)
|
||||
}
|
||||
if itemType == cwhub.POSTOVERFLOWS {
|
||||
parsers.PovfwStageFiles = append(parsers.PovfwStageFiles, stagefile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if parsers.StageFiles != nil {
|
||||
sort.Slice(parsers.StageFiles, func(i, j int) bool {
|
||||
return parsers.StageFiles[i].Filename < parsers.StageFiles[j].Filename
|
||||
|
@ -101,13 +100,17 @@ func LoadParsers(cConfig *csconfig.Config, parsers *Parsers) (*Parsers, error) {
|
|||
patternsDir := cConfig.ConfigPaths.PatternDir
|
||||
log.Infof("Loading grok library %s", patternsDir)
|
||||
/* load base regexps for two grok parsers */
|
||||
parsers.Ctx, err = Init(map[string]interface{}{"patterns": patternsDir,
|
||||
"data": cConfig.ConfigPaths.DataDir})
|
||||
parsers.Ctx, err = Init(map[string]interface{}{
|
||||
"patterns": patternsDir,
|
||||
"data": cConfig.ConfigPaths.DataDir,
|
||||
})
|
||||
if err != nil {
|
||||
return parsers, fmt.Errorf("failed to load parser patterns : %v", err)
|
||||
}
|
||||
parsers.Povfwctx, err = Init(map[string]interface{}{"patterns": patternsDir,
|
||||
"data": cConfig.ConfigPaths.DataDir})
|
||||
parsers.Povfwctx, err = Init(map[string]interface{}{
|
||||
"patterns": patternsDir,
|
||||
"data": cConfig.ConfigPaths.DataDir,
|
||||
})
|
||||
if err != nil {
|
||||
return parsers, fmt.Errorf("failed to load postovflw parser patterns : %v", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue