mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-19 13:15:29 +00:00
Misc
This commit is contained in:
parent
d3b2c8fee0
commit
e09f16b68c
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/projectdiscovery/nuclei/v2/pkg/types"
|
"github.com/projectdiscovery/nuclei/v2/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Exporter is an exporter for nuclei sarif output format.
|
||||||
type Exporter struct {
|
type Exporter struct {
|
||||||
sarif *sarif.Report
|
sarif *sarif.Report
|
||||||
run *sarif.Run
|
run *sarif.Run
|
||||||
@ -45,10 +46,8 @@ func New(options *Options) (*Exporter, error) {
|
|||||||
return &Exporter{options: options, home: templatePath, sarif: report, run: run, mutex: &sync.Mutex{}}, nil
|
return &Exporter{options: options, home: templatePath, sarif: report, run: run, mutex: &sync.Mutex{}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export exports a passed result event to disk
|
// Export exports a passed result event to sarif structure
|
||||||
func (i *Exporter) Export(event *output.ResultEvent) error {
|
func (i *Exporter) Export(event *output.ResultEvent) error {
|
||||||
i.mutex.Lock()
|
|
||||||
defer i.mutex.Unlock()
|
|
||||||
templatePath := strings.TrimPrefix(event.TemplatePath, i.home)
|
templatePath := strings.TrimPrefix(event.TemplatePath, i.home)
|
||||||
|
|
||||||
description := getSarifResultMessage(event, templatePath)
|
description := getSarifResultMessage(event, templatePath)
|
||||||
@ -81,6 +80,9 @@ func (i *Exporter) Export(event *output.ResultEvent) error {
|
|||||||
}
|
}
|
||||||
ruleHelp := builder.String()
|
ruleHelp := builder.String()
|
||||||
|
|
||||||
|
i.mutex.Lock()
|
||||||
|
defer i.mutex.Unlock()
|
||||||
|
|
||||||
_ = i.run.AddRule(event.TemplateID).
|
_ = i.run.AddRule(event.TemplateID).
|
||||||
WithDescription(ruleName).
|
WithDescription(ruleName).
|
||||||
WithHelp(ruleHelp).
|
WithHelp(ruleHelp).
|
||||||
@ -183,6 +185,9 @@ func getSarifResultMessage(event *output.ResultEvent, templatePath string) strin
|
|||||||
|
|
||||||
// Close closes the exporter after operation
|
// Close closes the exporter after operation
|
||||||
func (i *Exporter) Close() error {
|
func (i *Exporter) Close() error {
|
||||||
|
i.mutex.Lock()
|
||||||
|
defer i.mutex.Unlock()
|
||||||
|
|
||||||
i.sarif.AddRun(i.run)
|
i.sarif.AddRun(i.run)
|
||||||
|
|
||||||
file, err := os.Create(i.options.File)
|
file, err := os.Create(i.options.File)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user