Print first line of running action if any

dev
Ice3man543 2021-06-05 23:09:08 +05:30
parent d9bb1393d3
commit 1dc1b9ee73
1 changed files with 4 additions and 14 deletions

View File

@ -3,7 +3,6 @@ package sarif
import ( import (
"crypto/sha1" "crypto/sha1"
"encoding/hex" "encoding/hex"
"io/ioutil"
"os" "os"
"path" "path"
"strings" "strings"
@ -38,14 +37,6 @@ func New(options *Options) (*Exporter, error) {
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not create sarif exporter") return nil, errors.Wrap(err, "could not create sarif exporter")
} }
tempFile, err := ioutil.TempFile("", "sarif-test-*")
if err != nil {
return nil, errors.Wrap(err, "could not create sarif temp file")
}
defer tempFile.Close()
tempFile.WriteString("github.com/projectdiscovery/nuclei Scan Result")
tempFileName := tempFile.Name()
home, err := os.UserHomeDir() home, err := os.UserHomeDir()
if err != nil { if err != nil {
@ -54,7 +45,7 @@ func New(options *Options) (*Exporter, error) {
templatePath := path.Join(home, "nuclei-templates") templatePath := path.Join(home, "nuclei-templates")
run := sarif.NewRun("nuclei", "https://github.com/projectdiscovery/nuclei") run := sarif.NewRun("nuclei", "https://github.com/projectdiscovery/nuclei")
return &Exporter{options: options, tempFile: tempFileName, 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 sarif structure // Export exports a passed result event to sarif structure
@ -91,13 +82,12 @@ func (i *Exporter) Export(event *output.ResultEvent) error {
WithHelp(fullDescription). WithHelp(fullDescription).
WithHelpURI(templateURL). WithHelpURI(templateURL).
WithFullDescription(sarif.NewMultiformatMessageString(ruleDescription)) WithFullDescription(sarif.NewMultiformatMessageString(ruleDescription))
_ = i.run.AddResult(templateID). _ = i.run.AddResult(templateID).
WithMessage(sarif.NewMessage().WithText(event.Host)). WithMessage(sarif.NewMessage().WithText(event.Host)).
WithLevel(sarifSeverity). WithLevel(sarifSeverity).
WithLocation(sarif.NewLocation().WithMessage(sarif.NewMessage().WithText(event.Host)).WithPhysicalLocation( WithLocation(sarif.NewLocation().WithMessage(sarif.NewMessage().WithText(event.Host)).WithPhysicalLocation(
sarif.NewPhysicalLocation(). sarif.NewPhysicalLocation().
WithArtifactLocation(sarif.NewArtifactLocation().WithUri(i.tempFile)). WithArtifactLocation(sarif.NewArtifactLocation().WithUri(os.Getenv("github.action_path"))).
WithRegion(sarif.NewRegion().WithStartColumn(1).WithStartLine(1).WithEndLine(1).WithEndColumn(1)), WithRegion(sarif.NewRegion().WithStartColumn(1).WithStartLine(1).WithEndLine(1).WithEndColumn(1)),
)) ))
return nil return nil
@ -112,13 +102,13 @@ func getSarifSeverity(event *output.ResultEvent) string {
switch ruleSeverity { switch ruleSeverity {
case "info": case "info":
return "none" return "note"
case "low", "medium": case "low", "medium":
return "warning" return "warning"
case "high", "critical": case "high", "critical":
return "error" return "error"
default: default:
return "none" return "note"
} }
} }