(pattern string, logger *log.Entry, hub *cwhub.Hub)
| 50 | var AppsecRulesDetails = make(map[int]RulesDetails) |
| 51 | |
| 52 | func LoadCollection(pattern string, logger *log.Entry, hub *cwhub.Hub) ([]AppsecCollection, error) { |
| 53 | ret := make([]AppsecCollection, 0) |
| 54 | |
| 55 | for _, appsecRule := range appsecRules { |
| 56 | tmpMatch, err := exprhelpers.Match(pattern, appsecRule.Name) |
| 57 | if err != nil { |
| 58 | logger.Errorf("unable to match %s with %s : %s", appsecRule.Name, pattern, err) |
| 59 | continue |
| 60 | } |
| 61 | |
| 62 | matched, ok := tmpMatch.(bool) |
| 63 | |
| 64 | if !ok { |
| 65 | logger.Errorf("unable to match %s with %s : %s", appsecRule.Name, pattern, err) |
| 66 | continue |
| 67 | } |
| 68 | |
| 69 | if !matched { |
| 70 | continue |
| 71 | } |
| 72 | |
| 73 | appsecCol := AppsecCollection{} |
| 74 | |
| 75 | if appsecRule.SecLangFilesRules != nil { |
| 76 | for _, rulesFile := range appsecRule.SecLangFilesRules { |
| 77 | logger.Debugf("Adding rules from %s", rulesFile) |
| 78 | globPattern := filepath.Join(hub.GetDataDir(), rulesFile) |
| 79 | |
| 80 | matches, err := filepath.Glob(globPattern) |
| 81 | |
| 82 | if err != nil { |
| 83 | logger.Errorf("unable to glob %s : %s", rulesFile, err) |
| 84 | continue |
| 85 | } |
| 86 | |
| 87 | if len(matches) == 0 { |
| 88 | logger.Warnf("no file matched pattern %s", globPattern) |
| 89 | continue |
| 90 | } |
| 91 | |
| 92 | for _, fullPath := range matches { |
| 93 | c, err := os.ReadFile(fullPath) |
| 94 | if err != nil { |
| 95 | logger.Errorf("unable to read file %s : %s", rulesFile, err) |
| 96 | continue |
| 97 | } |
| 98 | |
| 99 | for line := range strings.SplitSeq(string(c), "\n") { |
| 100 | if strings.HasPrefix(line, "#") { |
| 101 | continue |
| 102 | } |
| 103 | |
| 104 | if strings.TrimSpace(line) == "" { |
| 105 | continue |
| 106 | } |
| 107 | |
| 108 | appsecCol.NativeRules = append(appsecCol.NativeRules, line) |
| 109 | } |
no test coverage detected
searching dependent graphs…