Skip to content

Commit

Permalink
make max-request optional
Browse files Browse the repository at this point in the history
  • Loading branch information
RamanaReddy0M committed Jun 19, 2023
1 parent d49f64f commit fbf7871
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions v2/cmd/tmc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ var idRegex = regexp.MustCompile("id: ([C|c][V|v][E|e]-[0-9]+-[0-9]+)")
type options struct {
input string
errorLogFile string
debug bool
enhance bool
format bool
validate bool
lint bool
validate bool
format bool
enhance bool
maxRequest bool
debug bool
}

func main() {
Expand All @@ -95,10 +96,11 @@ func main() {
)

flagSet.CreateGroup("Config", "config",
flagSet.BoolVarP(&opts.enhance, "enhance", "e", false, "enhance given nuclei template"),
flagSet.BoolVarP(&opts.format, "format", "f", false, "format given nuclei template"),
flagSet.BoolVarP(&opts.lint, "lint", "l", false, "lint given nuclei template"),
flagSet.BoolVarP(&opts.validate, "validate", "v", false, "validate given nuclei template"),
flagSet.BoolVarP(&opts.format, "format", "f", false, "format given nuclei template"),
flagSet.BoolVarP(&opts.enhance, "enhance", "e", false, "enhance given nuclei template"),
flagSet.BoolVarP(&opts.maxRequest, "max-request", "mr", false, "add / update max request counter"),
flagSet.StringVarP(&opts.errorLogFile, "error-log", "el", "", "file to write failed template update"),
flagSet.BoolVarP(&opts.debug, "debug", "d", false, "show debug message"),
)
Expand Down Expand Up @@ -154,16 +156,17 @@ func process(opts options) error {
}
dataString := string(data)

// try to fill max-requests
var updated bool // if max-requests is updated
dataString, updated, err = parseAndAddMaxRequests(templateCatalog, path, dataString)
if err != nil {
gologger.Info().Label("max-request").Msgf(logErrMsg(path, err, opts.debug, errFile))
} else {
if updated {
gologger.Info().Label("max-request").Msgf("✅ updated template: %s\n", path)
if opts.maxRequest {
var updated bool // if max-requests is updated
dataString, updated, err = parseAndAddMaxRequests(templateCatalog, path, dataString)
if err != nil {
gologger.Info().Label("max-request").Msgf(logErrMsg(path, err, opts.debug, errFile))
} else {
if updated {
gologger.Info().Label("max-request").Msgf("✅ updated template: %s\n", path)
}
// do not print if max-requests is not updated
}
// do not print if max-requests is not updated
}

if opts.lint {
Expand Down

0 comments on commit fbf7871

Please sign in to comment.