Changed code as per review comments

dev
Ice3man543 2021-08-31 21:39:20 +05:30
parent 2c8f5bc2e5
commit 19770d186f
3 changed files with 15 additions and 13 deletions

View File

@ -349,7 +349,7 @@ func (r *Runner) RunEnumeration() error {
if err := store.ValidateTemplates(r.options.Templates, r.options.Workflows); err != nil {
return err
}
if stats.GetValue("syntax-warnings") == 0 && stats.GetValue("syntax-errors") == 0 {
if stats.GetValue(parsers.SyntaxErrorStats) == 0 && stats.GetValue(parsers.SyntaxWarningStats) == 0 {
gologger.Info().Msgf("All templates validated successfully\n")
} else {
return errors.New("encountered errors while performing template validation")
@ -358,8 +358,8 @@ func (r *Runner) RunEnumeration() error {
}
// Display stats for any loaded templates syntax warnings or errors
stats.Display("syntax-warnings")
stats.Display("syntax-errors")
stats.Display(parsers.SyntaxWarningStats)
stats.Display(parsers.SyntaxErrorStats)
builder := &strings.Builder{}
if r.templatesConfig != nil && r.templatesConfig.NucleiLatestVersion != "" {

View File

@ -92,12 +92,17 @@ var (
fieldErrorRegexp = regexp.MustCompile(`not found in`)
)
const (
SyntaxWarningStats = "syntax-warnings"
SyntaxErrorStats = "syntax-errors"
)
func init() {
parsedTemplatesCache = cache.New()
stats.NewEntry("syntax-warnings", "Got %d syntax warnings for the loaded templates")
stats.NewEntry("syntax-errors", "Got %d syntax errors for the loaded templates")
stats.NewEntry(SyntaxWarningStats, "Got %d syntax warnings for the loaded templates")
stats.NewEntry(SyntaxErrorStats, "Got %d syntax errors for the loaded templates")
}
// ParseTemplate parses a template and returns a *templates.Template structure
@ -122,10 +127,10 @@ func ParseTemplate(templatePath string) (*templates.Template, error) {
if err != nil {
errString := err.Error()
if !fieldErrorRegexp.MatchString(errString) {
stats.Increment("syntax-errors")
stats.Increment(SyntaxErrorStats)
return nil, err
}
stats.Increment("syntax-warnings")
stats.Increment(SyntaxWarningStats)
if ShouldValidate {
gologger.Error().Msgf("Syntax warnings for template %s: %s", templatePath, err)
} else {

View File

@ -61,11 +61,10 @@ func (s *Storage) NewEntry(name, description string) {
func (s *Storage) Increment(name string) {
s.mutex.RLock()
data, ok := s.data[name]
s.mutex.RUnlock()
if !ok {
s.mutex.RUnlock()
return
}
s.mutex.RUnlock()
atomic.AddInt64(&data.value, 1)
}
@ -74,11 +73,10 @@ func (s *Storage) Increment(name string) {
func (s *Storage) Display(name string) {
s.mutex.RLock()
data, ok := s.data[name]
s.mutex.RUnlock()
if !ok {
s.mutex.RUnlock()
return
}
s.mutex.RUnlock()
dataValue := atomic.LoadInt64(&data.value)
if dataValue == 0 {
@ -91,11 +89,10 @@ func (s *Storage) Display(name string) {
func (s *Storage) GetValue(name string) int64 {
s.mutex.RLock()
data, ok := s.data[name]
s.mutex.RUnlock()
if !ok {
s.mutex.RUnlock()
return 0
}
s.mutex.RUnlock()
dataValue := atomic.LoadInt64(&data.value)
return dataValue