From 5d89bb80568500db2edc135899cfaedb5a39ecbe Mon Sep 17 00:00:00 2001 From: forgedhallpass <13679401+forgedhallpass@users.noreply.github.com> Date: Mon, 19 Jul 2021 21:04:08 +0300 Subject: [PATCH] RES-84 # Improve Nuclei CLI interface * fixed issues reported by the linter --- v2/cmd/nuclei/main.go | 5 +-- v2/internal/colorizer/colorizer.go | 8 +++-- v2/internal/runner/runner.go | 17 +++++----- v2/internal/runner/templates.go | 9 ++--- v2/internal/severity/misc.go | 5 +-- v2/internal/severity/severity.go | 30 ++++++++-------- v2/internal/severity/severity_test.go | 34 ++++++++++--------- v2/pkg/catalog/config/config.go | 2 +- v2/pkg/catalog/loader/filter/tag_filter.go | 25 +++++++------- .../catalog/loader/filter/tag_filter_test.go | 3 +- v2/pkg/catalog/loader/loader.go | 5 ++- v2/pkg/model/model.go | 3 +- v2/pkg/operators/operators.go | 1 + v2/pkg/output/format_screen.go | 1 + v2/pkg/output/output.go | 8 +++-- v2/pkg/parsers/parser.go | 34 +++++++++---------- v2/pkg/protocols/dns/dns_test.go | 7 ++-- v2/pkg/protocols/dns/operators.go | 3 +- v2/pkg/protocols/dns/operators_test.go | 7 ++-- v2/pkg/protocols/dns/request_test.go | 7 ++-- v2/pkg/protocols/file/file_test.go | 7 ++-- v2/pkg/protocols/file/find_test.go | 7 ++-- v2/pkg/protocols/file/operators.go | 2 +- v2/pkg/protocols/file/operators_test.go | 7 ++-- v2/pkg/protocols/file/request_test.go | 4 +-- v2/pkg/protocols/headless/operators.go | 2 +- v2/pkg/protocols/http/build_request_test.go | 4 +-- v2/pkg/protocols/http/http_test.go | 7 ++-- v2/pkg/protocols/http/operators.go | 2 +- v2/pkg/protocols/http/operators_test.go | 7 ++-- v2/pkg/protocols/network/network_test.go | 7 ++-- v2/pkg/protocols/network/operators.go | 2 +- v2/pkg/protocols/network/operators_test.go | 7 ++-- v2/pkg/protocols/network/request_test.go | 7 ++-- v2/pkg/protocols/offlinehttp/find_test.go | 9 ++--- v2/pkg/protocols/offlinehttp/operators.go | 2 +- .../protocols/offlinehttp/operators_test.go | 7 ++-- v2/pkg/reporting/exporters/sarif/sarif.go | 5 +-- v2/pkg/reporting/format/format.go | 2 +- v2/pkg/reporting/reporting.go | 13 +++---- v2/pkg/reporting/trackers/jira/jira.go | 5 +-- v2/pkg/templates/compile.go | 5 +-- v2/pkg/types/interfaces.go | 3 +- v2/pkg/utils/utils.go | 1 + v2/pkg/utils/utils_test.go | 4 ++- 45 files changed, 189 insertions(+), 153 deletions(-) diff --git a/v2/cmd/nuclei/main.go b/v2/cmd/nuclei/main.go index 8b878cdc..25f2d753 100644 --- a/v2/cmd/nuclei/main.go +++ b/v2/cmd/nuclei/main.go @@ -2,13 +2,14 @@ package main import ( "fmt" + "os" + "path" + "github.com/projectdiscovery/goflags" "github.com/projectdiscovery/gologger" "github.com/projectdiscovery/nuclei/v2/internal/runner" "github.com/projectdiscovery/nuclei/v2/internal/severity" "github.com/projectdiscovery/nuclei/v2/pkg/types" - "os" - "path" ) var ( diff --git a/v2/internal/colorizer/colorizer.go b/v2/internal/colorizer/colorizer.go index 75978027..c179a034 100644 --- a/v2/internal/colorizer/colorizer.go +++ b/v2/internal/colorizer/colorizer.go @@ -1,6 +1,8 @@ package colorizer import ( + "fmt" + "github.com/logrusorgru/aurora" "github.com/projectdiscovery/gologger" "github.com/projectdiscovery/nuclei/v2/internal/severity" @@ -10,7 +12,7 @@ const ( fgOrange uint8 = 208 ) -func GetColor(colorizer aurora.Aurora, templateSeverity severity.Severity) string { +func GetColor(colorizer aurora.Aurora, templateSeverity fmt.Stringer) string { var method func(arg interface{}) aurora.Value switch templateSeverity { case severity.Info: @@ -31,8 +33,8 @@ func GetColor(colorizer aurora.Aurora, templateSeverity severity.Severity) strin return method(templateSeverity.String()).String() } -func New(aurora aurora.Aurora) func(severity.Severity) string { +func New(colorizer aurora.Aurora) func(severity.Severity) string { return func(severity severity.Severity) string { - return GetColor(aurora, severity) + return GetColor(colorizer, severity) } } diff --git a/v2/internal/runner/runner.go b/v2/internal/runner/runner.go index f0458c28..b8520875 100644 --- a/v2/internal/runner/runner.go +++ b/v2/internal/runner/runner.go @@ -3,9 +3,6 @@ package runner import ( "bufio" "fmt" - "github.com/projectdiscovery/nuclei/v2/internal/severity" - "github.com/projectdiscovery/nuclei/v2/pkg/parsers" - "github.com/projectdiscovery/nuclei/v2/pkg/utils" "os" "path" "strings" @@ -13,13 +10,21 @@ import ( "github.com/logrusorgru/aurora" "github.com/pkg/errors" + "github.com/remeh/sizedwaitgroup" + "github.com/rs/xid" + "go.uber.org/atomic" + "go.uber.org/ratelimit" + "gopkg.in/yaml.v2" + "github.com/projectdiscovery/gologger" "github.com/projectdiscovery/hmap/store/hybrid" "github.com/projectdiscovery/nuclei/v2/internal/colorizer" + "github.com/projectdiscovery/nuclei/v2/internal/severity" "github.com/projectdiscovery/nuclei/v2/pkg/catalog" "github.com/projectdiscovery/nuclei/v2/pkg/catalog/config" "github.com/projectdiscovery/nuclei/v2/pkg/catalog/loader" "github.com/projectdiscovery/nuclei/v2/pkg/output" + "github.com/projectdiscovery/nuclei/v2/pkg/parsers" "github.com/projectdiscovery/nuclei/v2/pkg/progress" "github.com/projectdiscovery/nuclei/v2/pkg/projectfile" "github.com/projectdiscovery/nuclei/v2/pkg/protocols" @@ -32,11 +37,7 @@ import ( "github.com/projectdiscovery/nuclei/v2/pkg/reporting/exporters/sarif" "github.com/projectdiscovery/nuclei/v2/pkg/templates" "github.com/projectdiscovery/nuclei/v2/pkg/types" - "github.com/remeh/sizedwaitgroup" - "github.com/rs/xid" - "go.uber.org/atomic" - "go.uber.org/ratelimit" - "gopkg.in/yaml.v2" + "github.com/projectdiscovery/nuclei/v2/pkg/utils" ) // Runner is a client for running the enumeration process. diff --git a/v2/internal/runner/templates.go b/v2/internal/runner/templates.go index 1a44c05c..409b76bb 100644 --- a/v2/internal/runner/templates.go +++ b/v2/internal/runner/templates.go @@ -3,16 +3,17 @@ package runner import ( "bytes" "fmt" - "github.com/projectdiscovery/nuclei/v2/internal/severity" "io/ioutil" "os" "strings" "github.com/karrick/godirwalk" + "gopkg.in/yaml.v2" + "github.com/projectdiscovery/gologger" + "github.com/projectdiscovery/nuclei/v2/internal/severity" "github.com/projectdiscovery/nuclei/v2/pkg/templates" "github.com/projectdiscovery/nuclei/v2/pkg/types" - "gopkg.in/yaml.v2" ) // parseTemplateFile returns the parsed template file @@ -36,13 +37,13 @@ func (r *Runner) parseTemplateFile(file string) (*templates.Template, error) { return template, nil } -func (r *Runner) templateLogMsg(id string, name string, author string, severity severity.Severity) string { +func (r *Runner) templateLogMsg(id, name, author string, templateSeverity severity.Severity) string { // Display the message for the template return fmt.Sprintf("[%s] %s (%s) [%s]", r.colorizer.BrightBlue(id).String(), r.colorizer.Bold(name).String(), r.colorizer.BrightYellow(appendAtSignToAuthors(author)).String(), - r.addColor(severity)) + r.addColor(templateSeverity)) } // appendAtSignToAuthors appends @ before each author and returns final string diff --git a/v2/internal/severity/misc.go b/v2/internal/severity/misc.go index 23b649f0..995cc072 100644 --- a/v2/internal/severity/misc.go +++ b/v2/internal/severity/misc.go @@ -1,7 +1,6 @@ package severity import ( - "errors" "fmt" "strings" @@ -14,6 +13,7 @@ func (severities Severities) String() string { return strings.Join(severities.ToStringArray(), ", ") } +//nolint:indent-error-flow,revive //reducing the scope of the variables func (severities *Severities) Set(value string) error { if inputSeverities, err := goflags.ToStringSlice(value); err != nil { return err @@ -30,8 +30,9 @@ func (severities *Severities) Set(value string) error { func setSeverity(severities *Severities, value string) error { computedSeverity, err := toSeverity(value) if err != nil { - return errors.New(fmt.Sprintf("'%s' is not a valid severity!", value)) + return fmt.Errorf("'%s' is not a valid severity", value) } + // TODO change the Severities type to map[Severity]interface{}, where the values are struct{}{}, to "simulates" a "set" data structure *severities = append(*severities, computedSeverity) return nil diff --git a/v2/internal/severity/severity.go b/v2/internal/severity/severity.go index 7f2180a6..3ce28e82 100644 --- a/v2/internal/severity/severity.go +++ b/v2/internal/severity/severity.go @@ -2,8 +2,9 @@ package severity import ( "encoding/json" - "github.com/pkg/errors" "strings" + + "github.com/pkg/errors" ) type Severity int @@ -47,14 +48,12 @@ func normalizeValue(value string) string { return strings.TrimSpace(strings.ToLower(value)) } -func (severity Severity) normalize() string { - return normalizeValue(severity.String()) -} - func (severity Severity) String() string { return severityMappings[severity] } +//nolint:exported,revive //prefer to be explicit about the name, and make it refactor-safe +//goland:noinspection GoNameStartsWithPackageName type SeverityHolder struct { Severity Severity } @@ -62,17 +61,17 @@ type SeverityHolder struct { func (severityHolder SeverityHolder) MarshalYAML() (interface{}, error) { if value, found := severityMappings[severityHolder.Severity]; found { return &struct{ Severity string }{value}, nil // TODO see if the new struct can be dynamically created using reflection to make it refactor safe - } else { - panic("Invalid field to marshall") } + + panic("Invalid field to marshall") } func (severityHolder SeverityHolder) MarshalJSON() ([]byte, error) { if value, found := severityMappings[severityHolder.Severity]; found { return json.Marshal(&struct{ Severity string }{value}) // TODO see if the new struct can be dynamically created using reflection to make it refactor safe - } else { - panic("Invalid field to marshall") } + + panic("Invalid field to marshall") } func (severityHolder *SeverityHolder) UnmarshalYAML(unmarshal func(interface{}) error) error { @@ -96,20 +95,21 @@ func (severityHolder *SeverityHolder) UnmarshalJSON(data []byte) error { return err } - return mapToSeverity(objMap, severityHolder) + return severityHolder.mapToSeverity(objMap) } -func mapToSeverity(objMap map[string]string, severity *SeverityHolder) error { +func (severityHolder *SeverityHolder) mapToSeverity(objMap map[string]string) error { if len(objMap) != 1 { return errors.New("There can only be one severity defined") } stringSeverity := getFirstValue(objMap) - if readableSeverity, err := toSeverity(stringSeverity); err == nil { - severity = &SeverityHolder{readableSeverity} - return nil - } else { + readableSeverity, err := toSeverity(stringSeverity) + if err != nil { return err } + + *severityHolder = SeverityHolder{readableSeverity} + return nil } func getFirstValue(stringMap map[string]string) string { diff --git a/v2/internal/severity/severity_test.go b/v2/internal/severity/severity_test.go index 80f6c9c9..fc27327a 100644 --- a/v2/internal/severity/severity_test.go +++ b/v2/internal/severity/severity_test.go @@ -3,26 +3,28 @@ package severity import ( "encoding/json" "fmt" - "github.com/stretchr/testify/assert" - "gopkg.in/yaml.v2" "testing" + + "gopkg.in/yaml.v2" + + "github.com/stretchr/testify/assert" ) func TestJsonUnmarshal(t *testing.T) { - testUnmarshal(t, json.Unmarshal, createJson) + testUnmarshal(t, json.Unmarshal, createJSON) } // TODO -//func TestYamlUnmarshal(t *testing.T) { -// testUnmarshal(t, yaml.Unmarshal, createYaml) -//} +// func TestYamlUnmarshal(t *testing.T) { +// testUnmarshal(t, yaml.Unmarshal, createYAML) +// } func TestJsonUnmarshalFail(t *testing.T) { - testUnmarshalFail(t, json.Unmarshal, createJson) + testUnmarshalFail(t, json.Unmarshal, createJSON) } func TestYamlUnmarshalFail(t *testing.T) { - testUnmarshalFail(t, yaml.Unmarshal, createYaml) + testUnmarshalFail(t, yaml.Unmarshal, createYAML) } func TestJsonMarshalFails(t *testing.T) { @@ -34,11 +36,11 @@ func TestYamlMarshalFails(t *testing.T) { } func TestJsonMarshalSucceed(t *testing.T) { - testMarshal(t, json.Marshal, createJson) + testMarshal(t, json.Marshal, createJSON) } func TestYamlMarshal(t *testing.T) { - testMarshal(t, yaml.Marshal, createYaml) + testMarshal(t, yaml.Marshal, createYAML) } func testUnmarshal(t *testing.T, unmarshaller func(data []byte, v interface{}) error, payloadCreator func(value string) string) { @@ -50,7 +52,7 @@ func testUnmarshal(t *testing.T, unmarshaller func(data []byte, v interface{}) e payloadCreator(" INFO "), } - for _, payload := range payloads { + for _, payload := range payloads { // nolint:scopelint // false-positive t.Run(payload, func(t *testing.T) { result := unmarshal(payload, unmarshaller) assert.Equal(t, result.Severity, Info) @@ -66,12 +68,12 @@ func testMarshal(t *testing.T, marshaller func(v interface{}) ([]byte, error), p } } -func testUnmarshalFail(t *testing.T, unmarshaller func(data []byte, v interface{}) error, payloadCreator func(value string) string) bool { - return assert.Panics(t, func() { unmarshal(payloadCreator("invalid"), unmarshaller) }) +func testUnmarshalFail(t *testing.T, unmarshaller func(data []byte, v interface{}) error, payloadCreator func(value string) string) { + assert.Panics(t, func() { unmarshal(payloadCreator("invalid"), unmarshaller) }) } func testMarshallerFails(t *testing.T, marshaller func(v interface{}) ([]byte, error)) { - assert.Panics(t, func() { marshaller(&SeverityHolder{Severity: 13}) }) + assert.Panics(t, func() { _, _ = marshaller(&SeverityHolder{Severity: 13}) }) } func unmarshal(value string, unmarshaller func(data []byte, v interface{}) error) SeverityHolder { @@ -83,10 +85,10 @@ func unmarshal(value string, unmarshaller func(data []byte, v interface{}) error return severityStruct } -func createJson(severityString string) string { +func createJSON(severityString string) string { return fmt.Sprintf(`{"Severity":"%s"}`, severityString) } -func createYaml(value string) string { +func createYAML(value string) string { return "severity: " + value + "\n" } diff --git a/v2/pkg/catalog/config/config.go b/v2/pkg/catalog/config/config.go index 372b90d6..d437834e 100644 --- a/v2/pkg/catalog/config/config.go +++ b/v2/pkg/catalog/config/config.go @@ -28,7 +28,7 @@ type Config struct { const nucleiConfigFilename = ".templates-config.json" // Version is the current version of nuclei -const Version = `2.4.0` +const Version = `2.4.x` func getConfigDetails() (string, error) { homeDir, err := os.UserHomeDir() diff --git a/v2/pkg/catalog/loader/filter/tag_filter.go b/v2/pkg/catalog/loader/filter/tag_filter.go index b03daa60..761b0237 100644 --- a/v2/pkg/catalog/loader/filter/tag_filter.go +++ b/v2/pkg/catalog/loader/filter/tag_filter.go @@ -2,9 +2,10 @@ package filter import ( "errors" + "strings" + "github.com/projectdiscovery/nuclei/v2/internal/severity" "github.com/projectdiscovery/nuclei/v2/pkg/utils" - "strings" ) // TagFilter is used to filter nuclei templates for tag based execution @@ -27,7 +28,7 @@ var ErrExcluded = errors.New("the template was excluded") // matchAllows section. // // It returns true if the tag is specified, or false. -func (tagFilter *TagFilter) Match(templateTags, templateAuthors []string, severity severity.Severity) (bool, error) { +func (tagFilter *TagFilter) Match(templateTags, templateAuthors []string, templateSeverity severity.Severity) (bool, error) { for _, templateTag := range templateTags { _, blocked := tagFilter.block[templateTag] _, allowed := tagFilter.matchAllows[templateTag] @@ -46,7 +47,7 @@ func (tagFilter *TagFilter) Match(templateTags, templateAuthors []string, severi } if utils.IsNotEmpty(tagFilter.severities) { - if _, ok := tagFilter.severities[severity]; !ok { + if _, ok := tagFilter.severities[templateSeverity]; !ok { return false, nil } } @@ -57,16 +58,18 @@ func (tagFilter *TagFilter) Match(templateTags, templateAuthors []string, severi func isAuthorMatch(templateAuthors []string, tagFilter *TagFilter) bool { if utils.IsEmpty(tagFilter.authors) { return true - } else { - for _, templateAuthor := range templateAuthors { - if _, ok := tagFilter.authors[templateAuthor]; ok { - return true - } + } + + for _, templateAuthor := range templateAuthors { + if _, ok := tagFilter.authors[templateAuthor]; ok { + return true } } + return false } +//nolint:indent-error-flow,revive // keeping conditions together func isTagMatch(templateTags []string, tagFilter *TagFilter) bool { if utils.IsEmpty(tagFilter.allowedTags) { return true @@ -80,10 +83,8 @@ func isTagMatch(templateTags []string, tagFilter *TagFilter) bool { return false } -// MatchWithWorkflowTags takes an addition list of allowed tags -// and returns true if the match was successful. +// MatchWithWorkflowTags takes an addition list of allowed tags and returns true if the match was successful. func (tagFilter *TagFilter) MatchWithWorkflowTags(templateTags, templateAuthors []string, templateSeverity severity.Severity, workflowTags []string) (bool, error) { - workflowAllowedTagMap := make(map[string]struct{}) for _, workflowTag := range workflowTags { if _, ok := workflowAllowedTagMap[workflowTag]; !ok { @@ -114,8 +115,8 @@ func (tagFilter *TagFilter) MatchWithWorkflowTags(templateTags, templateAuthors return false, nil } } - } + if utils.IsNotEmpty(tagFilter.severities) { if _, ok := tagFilter.severities[templateSeverity]; !ok { return false, nil diff --git a/v2/pkg/catalog/loader/filter/tag_filter_test.go b/v2/pkg/catalog/loader/filter/tag_filter_test.go index 0687efd0..33b7bda1 100644 --- a/v2/pkg/catalog/loader/filter/tag_filter_test.go +++ b/v2/pkg/catalog/loader/filter/tag_filter_test.go @@ -1,10 +1,11 @@ package filter import ( - "github.com/projectdiscovery/nuclei/v2/internal/severity" "testing" "github.com/stretchr/testify/require" + + "github.com/projectdiscovery/nuclei/v2/internal/severity" ) func TestTagBasedFilter(t *testing.T) { diff --git a/v2/pkg/catalog/loader/loader.go b/v2/pkg/catalog/loader/loader.go index eb938005..f996da1f 100644 --- a/v2/pkg/catalog/loader/loader.go +++ b/v2/pkg/catalog/loader/loader.go @@ -1,17 +1,16 @@ package loader import ( - "github.com/projectdiscovery/nuclei/v2/internal/severity" - "github.com/projectdiscovery/nuclei/v2/pkg/utils" "strings" "github.com/projectdiscovery/gologger" - + "github.com/projectdiscovery/nuclei/v2/internal/severity" "github.com/projectdiscovery/nuclei/v2/pkg/catalog" "github.com/projectdiscovery/nuclei/v2/pkg/catalog/loader/filter" "github.com/projectdiscovery/nuclei/v2/pkg/parsers" "github.com/projectdiscovery/nuclei/v2/pkg/protocols" "github.com/projectdiscovery/nuclei/v2/pkg/templates" + "github.com/projectdiscovery/nuclei/v2/pkg/utils" ) // Config contains the configuration options for the loader diff --git a/v2/pkg/model/model.go b/v2/pkg/model/model.go index b82c9cb6..ffe62316 100644 --- a/v2/pkg/model/model.go +++ b/v2/pkg/model/model.go @@ -1,9 +1,10 @@ package model import ( + "strings" + "github.com/projectdiscovery/nuclei/v2/internal/severity" "github.com/projectdiscovery/nuclei/v2/pkg/utils" - "strings" ) type Info struct { diff --git a/v2/pkg/operators/operators.go b/v2/pkg/operators/operators.go index 2497fa49..9093ae8f 100644 --- a/v2/pkg/operators/operators.go +++ b/v2/pkg/operators/operators.go @@ -2,6 +2,7 @@ package operators import ( "github.com/pkg/errors" + "github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors" "github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers" ) diff --git a/v2/pkg/output/format_screen.go b/v2/pkg/output/format_screen.go index 7381a3dd..89c7ec98 100644 --- a/v2/pkg/output/format_screen.go +++ b/v2/pkg/output/format_screen.go @@ -2,6 +2,7 @@ package output import ( "bytes" + "github.com/projectdiscovery/nuclei/v2/pkg/types" ) diff --git a/v2/pkg/output/output.go b/v2/pkg/output/output.go index 25b79dd8..0c86385e 100644 --- a/v2/pkg/output/output.go +++ b/v2/pkg/output/output.go @@ -1,18 +1,20 @@ package output import ( - "github.com/projectdiscovery/nuclei/v2/internal/severity" - "github.com/projectdiscovery/nuclei/v2/pkg/model" "os" "regexp" "sync" "time" + "github.com/pkg/errors" + jsoniter "github.com/json-iterator/go" "github.com/logrusorgru/aurora" - "github.com/pkg/errors" + "github.com/projectdiscovery/interactsh/pkg/server" "github.com/projectdiscovery/nuclei/v2/internal/colorizer" + "github.com/projectdiscovery/nuclei/v2/internal/severity" + "github.com/projectdiscovery/nuclei/v2/pkg/model" "github.com/projectdiscovery/nuclei/v2/pkg/operators" ) diff --git a/v2/pkg/parsers/parser.go b/v2/pkg/parsers/parser.go index b318f9d9..72ac91e9 100644 --- a/v2/pkg/parsers/parser.go +++ b/v2/pkg/parsers/parser.go @@ -2,21 +2,21 @@ package parsers import ( "bytes" - "errors" "fmt" + "io/ioutil" + "os" + + "gopkg.in/yaml.v2" + "github.com/projectdiscovery/nuclei/v2/pkg/catalog/loader/filter" "github.com/projectdiscovery/nuclei/v2/pkg/model" "github.com/projectdiscovery/nuclei/v2/pkg/templates" "github.com/projectdiscovery/nuclei/v2/pkg/utils" - "gopkg.in/yaml.v2" - "io/ioutil" - "os" ) const mandatoryFieldMissingTemplate = "mandatory '%s' field is missing" -// Load loads a template by parsing metadata and running -// all tag and path based filters on the template. +// Load loads a template by parsing metadata and running all tag and path based filters on the template. func Load(templatePath string, isWorkflow bool, workflowTags []string, tagFilter *filter.TagFilter) (bool, error) { template, templateParseError := parseTemplate(templatePath) if templateParseError != nil { @@ -24,24 +24,24 @@ func Load(templatePath string, isWorkflow bool, workflowTags []string, tagFilter } templateInfo := template.Info - if validationError := validateMandatoryInfoFields(templateInfo); validationError != nil { + if validationError := validateMandatoryInfoFields(&templateInfo); validationError != nil { return false, validationError } if utils.IsNotEmpty(template.Workflows) { if isWorkflow { return true, nil // if a workflow is declared and this template is a workflow, then load - } else { + } else { //nolint:indent-error-flow,revive // preferred: readability and extensibility return false, nil // if a workflow is declared and this template is not a workflow then do not load } } else if isWorkflow { return false, nil // if no workflows are declared and this template is a workflow then do not load } else { // if workflows are not declared and the template is not a workflow then parse it - return isInfoMetadataMatch(tagFilter, templateInfo, workflowTags) + return isInfoMetadataMatch(tagFilter, &templateInfo, workflowTags) } } -func isInfoMetadataMatch(tagFilter *filter.TagFilter, templateInfo model.Info, workflowTags []string) (bool, error) { +func isInfoMetadataMatch(tagFilter *filter.TagFilter, templateInfo *model.Info, workflowTags []string) (bool, error) { templateTags := templateInfo.Tags.ToSlice() templateAuthors := templateInfo.Authors.ToSlice() templateSeverity := templateInfo.SeverityHolder.Severity @@ -61,18 +61,18 @@ func isInfoMetadataMatch(tagFilter *filter.TagFilter, templateInfo model.Info, w return match, nil } -func validateMandatoryInfoFields(info model.Info) error { - if utils.IsEmpty(info) { - return errors.New(fmt.Sprintf(mandatoryFieldMissingTemplate, "info")) +func validateMandatoryInfoFields(info *model.Info) error { + if utils.IsEmpty(&info) { + return fmt.Errorf(mandatoryFieldMissingTemplate, "info") } - if utils.IsEmpty(info.Name) { - return errors.New(fmt.Sprintf(mandatoryFieldMissingTemplate, "name")) + if utils.IsEmpty(&info.Name) { + return fmt.Errorf(mandatoryFieldMissingTemplate, "name") } authors := info.Authors.ToSlice() - if utils.IsEmpty(authors) { - return errors.New(fmt.Sprintf(mandatoryFieldMissingTemplate, "author")) + if utils.IsEmpty(&authors) { + return fmt.Errorf(mandatoryFieldMissingTemplate, "author") } return nil } diff --git a/v2/pkg/protocols/dns/dns_test.go b/v2/pkg/protocols/dns/dns_test.go index 92a7cacd..6e6911a5 100644 --- a/v2/pkg/protocols/dns/dns_test.go +++ b/v2/pkg/protocols/dns/dns_test.go @@ -1,12 +1,13 @@ package dns import ( - "github.com/projectdiscovery/nuclei/v2/internal/severity" - "github.com/projectdiscovery/nuclei/v2/pkg/model" "testing" - "github.com/projectdiscovery/nuclei/v2/internal/testutils" "github.com/stretchr/testify/require" + + "github.com/projectdiscovery/nuclei/v2/internal/severity" + "github.com/projectdiscovery/nuclei/v2/internal/testutils" + "github.com/projectdiscovery/nuclei/v2/pkg/model" ) func TestDNSCompileMake(t *testing.T) { diff --git a/v2/pkg/protocols/dns/operators.go b/v2/pkg/protocols/dns/operators.go index 89eb842a..1120aff8 100644 --- a/v2/pkg/protocols/dns/operators.go +++ b/v2/pkg/protocols/dns/operators.go @@ -2,10 +2,11 @@ package dns import ( "bytes" - "github.com/projectdiscovery/nuclei/v2/pkg/model" "time" "github.com/miekg/dns" + + "github.com/projectdiscovery/nuclei/v2/pkg/model" "github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors" "github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers" "github.com/projectdiscovery/nuclei/v2/pkg/output" diff --git a/v2/pkg/protocols/dns/operators_test.go b/v2/pkg/protocols/dns/operators_test.go index 8a0c63a2..c0937b91 100644 --- a/v2/pkg/protocols/dns/operators_test.go +++ b/v2/pkg/protocols/dns/operators_test.go @@ -1,19 +1,20 @@ package dns import ( - "github.com/projectdiscovery/nuclei/v2/internal/severity" - "github.com/projectdiscovery/nuclei/v2/pkg/model" "net" "strconv" "testing" "github.com/miekg/dns" + "github.com/stretchr/testify/require" + + "github.com/projectdiscovery/nuclei/v2/internal/severity" "github.com/projectdiscovery/nuclei/v2/internal/testutils" + "github.com/projectdiscovery/nuclei/v2/pkg/model" "github.com/projectdiscovery/nuclei/v2/pkg/operators" "github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors" "github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers" "github.com/projectdiscovery/nuclei/v2/pkg/output" - "github.com/stretchr/testify/require" ) func TestResponseToDSLMap(t *testing.T) { diff --git a/v2/pkg/protocols/dns/request_test.go b/v2/pkg/protocols/dns/request_test.go index 9081f7ea..ee3bd305 100644 --- a/v2/pkg/protocols/dns/request_test.go +++ b/v2/pkg/protocols/dns/request_test.go @@ -1,16 +1,17 @@ package dns import ( - "github.com/projectdiscovery/nuclei/v2/internal/severity" - "github.com/projectdiscovery/nuclei/v2/pkg/model" "testing" + "github.com/stretchr/testify/require" + + "github.com/projectdiscovery/nuclei/v2/internal/severity" "github.com/projectdiscovery/nuclei/v2/internal/testutils" + "github.com/projectdiscovery/nuclei/v2/pkg/model" "github.com/projectdiscovery/nuclei/v2/pkg/operators" "github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors" "github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers" "github.com/projectdiscovery/nuclei/v2/pkg/output" - "github.com/stretchr/testify/require" ) func TestDNSExecuteWithResults(t *testing.T) { diff --git a/v2/pkg/protocols/file/file_test.go b/v2/pkg/protocols/file/file_test.go index 0a018fc8..04a1077d 100644 --- a/v2/pkg/protocols/file/file_test.go +++ b/v2/pkg/protocols/file/file_test.go @@ -1,12 +1,13 @@ package file import ( - "github.com/projectdiscovery/nuclei/v2/internal/severity" - "github.com/projectdiscovery/nuclei/v2/pkg/model" "testing" - "github.com/projectdiscovery/nuclei/v2/internal/testutils" "github.com/stretchr/testify/require" + + "github.com/projectdiscovery/nuclei/v2/internal/severity" + "github.com/projectdiscovery/nuclei/v2/internal/testutils" + "github.com/projectdiscovery/nuclei/v2/pkg/model" ) func TestFileCompile(t *testing.T) { diff --git a/v2/pkg/protocols/file/find_test.go b/v2/pkg/protocols/file/find_test.go index 8bc3f5df..0ade4098 100644 --- a/v2/pkg/protocols/file/find_test.go +++ b/v2/pkg/protocols/file/find_test.go @@ -1,15 +1,16 @@ package file import ( - "github.com/projectdiscovery/nuclei/v2/internal/severity" - "github.com/projectdiscovery/nuclei/v2/pkg/model" "io/ioutil" "os" "path" "testing" - "github.com/projectdiscovery/nuclei/v2/internal/testutils" "github.com/stretchr/testify/require" + + "github.com/projectdiscovery/nuclei/v2/internal/severity" + "github.com/projectdiscovery/nuclei/v2/internal/testutils" + "github.com/projectdiscovery/nuclei/v2/pkg/model" ) func TestFindInputPaths(t *testing.T) { diff --git a/v2/pkg/protocols/file/operators.go b/v2/pkg/protocols/file/operators.go index 26f60950..4b8af505 100644 --- a/v2/pkg/protocols/file/operators.go +++ b/v2/pkg/protocols/file/operators.go @@ -2,10 +2,10 @@ package file import ( "bufio" - "github.com/projectdiscovery/nuclei/v2/pkg/model" "strings" "time" + "github.com/projectdiscovery/nuclei/v2/pkg/model" "github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors" "github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers" "github.com/projectdiscovery/nuclei/v2/pkg/output" diff --git a/v2/pkg/protocols/file/operators_test.go b/v2/pkg/protocols/file/operators_test.go index 017c50ef..ceb60116 100644 --- a/v2/pkg/protocols/file/operators_test.go +++ b/v2/pkg/protocols/file/operators_test.go @@ -1,16 +1,17 @@ package file import ( - "github.com/projectdiscovery/nuclei/v2/internal/severity" - "github.com/projectdiscovery/nuclei/v2/pkg/model" "testing" + "github.com/stretchr/testify/require" + + "github.com/projectdiscovery/nuclei/v2/internal/severity" "github.com/projectdiscovery/nuclei/v2/internal/testutils" + "github.com/projectdiscovery/nuclei/v2/pkg/model" "github.com/projectdiscovery/nuclei/v2/pkg/operators" "github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors" "github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers" "github.com/projectdiscovery/nuclei/v2/pkg/output" - "github.com/stretchr/testify/require" ) func TestResponseToDSLMap(t *testing.T) { diff --git a/v2/pkg/protocols/file/request_test.go b/v2/pkg/protocols/file/request_test.go index d6878861..14c037db 100644 --- a/v2/pkg/protocols/file/request_test.go +++ b/v2/pkg/protocols/file/request_test.go @@ -1,14 +1,14 @@ package file import ( - "github.com/projectdiscovery/nuclei/v2/internal/severity" - "github.com/projectdiscovery/nuclei/v2/pkg/model" "io/ioutil" "os" "path" "testing" + "github.com/projectdiscovery/nuclei/v2/internal/severity" "github.com/projectdiscovery/nuclei/v2/internal/testutils" + "github.com/projectdiscovery/nuclei/v2/pkg/model" "github.com/projectdiscovery/nuclei/v2/pkg/operators" "github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors" "github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers" diff --git a/v2/pkg/protocols/headless/operators.go b/v2/pkg/protocols/headless/operators.go index aa36c777..d0a87aca 100644 --- a/v2/pkg/protocols/headless/operators.go +++ b/v2/pkg/protocols/headless/operators.go @@ -1,9 +1,9 @@ package headless import ( - "github.com/projectdiscovery/nuclei/v2/pkg/model" "time" + "github.com/projectdiscovery/nuclei/v2/pkg/model" "github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors" "github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers" "github.com/projectdiscovery/nuclei/v2/pkg/output" diff --git a/v2/pkg/protocols/http/build_request_test.go b/v2/pkg/protocols/http/build_request_test.go index caf03e53..ea465bb7 100644 --- a/v2/pkg/protocols/http/build_request_test.go +++ b/v2/pkg/protocols/http/build_request_test.go @@ -1,12 +1,12 @@ package http import ( - "github.com/projectdiscovery/nuclei/v2/internal/severity" - "github.com/projectdiscovery/nuclei/v2/pkg/model" "net/url" "testing" + "github.com/projectdiscovery/nuclei/v2/internal/severity" "github.com/projectdiscovery/nuclei/v2/internal/testutils" + "github.com/projectdiscovery/nuclei/v2/pkg/model" "github.com/stretchr/testify/require" ) diff --git a/v2/pkg/protocols/http/http_test.go b/v2/pkg/protocols/http/http_test.go index 818b888f..a675330c 100644 --- a/v2/pkg/protocols/http/http_test.go +++ b/v2/pkg/protocols/http/http_test.go @@ -1,12 +1,13 @@ package http import ( - "github.com/projectdiscovery/nuclei/v2/internal/severity" - "github.com/projectdiscovery/nuclei/v2/pkg/model" "testing" - "github.com/projectdiscovery/nuclei/v2/internal/testutils" "github.com/stretchr/testify/require" + + "github.com/projectdiscovery/nuclei/v2/internal/severity" + "github.com/projectdiscovery/nuclei/v2/internal/testutils" + "github.com/projectdiscovery/nuclei/v2/pkg/model" ) func TestHTTPCompile(t *testing.T) { diff --git a/v2/pkg/protocols/http/operators.go b/v2/pkg/protocols/http/operators.go index 5136c671..a426c985 100644 --- a/v2/pkg/protocols/http/operators.go +++ b/v2/pkg/protocols/http/operators.go @@ -1,11 +1,11 @@ package http import ( - "github.com/projectdiscovery/nuclei/v2/pkg/model" "net/http" "strings" "time" + "github.com/projectdiscovery/nuclei/v2/pkg/model" "github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors" "github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers" "github.com/projectdiscovery/nuclei/v2/pkg/output" diff --git a/v2/pkg/protocols/http/operators_test.go b/v2/pkg/protocols/http/operators_test.go index 6cb40733..a0a44258 100644 --- a/v2/pkg/protocols/http/operators_test.go +++ b/v2/pkg/protocols/http/operators_test.go @@ -1,18 +1,19 @@ package http import ( - "github.com/projectdiscovery/nuclei/v2/internal/severity" - "github.com/projectdiscovery/nuclei/v2/pkg/model" "net/http" "testing" "time" + "github.com/stretchr/testify/require" + + "github.com/projectdiscovery/nuclei/v2/internal/severity" "github.com/projectdiscovery/nuclei/v2/internal/testutils" + "github.com/projectdiscovery/nuclei/v2/pkg/model" "github.com/projectdiscovery/nuclei/v2/pkg/operators" "github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors" "github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers" "github.com/projectdiscovery/nuclei/v2/pkg/output" - "github.com/stretchr/testify/require" ) func TestResponseToDSLMap(t *testing.T) { diff --git a/v2/pkg/protocols/network/network_test.go b/v2/pkg/protocols/network/network_test.go index 6669a1f9..ef21b28b 100644 --- a/v2/pkg/protocols/network/network_test.go +++ b/v2/pkg/protocols/network/network_test.go @@ -1,12 +1,13 @@ package network import ( - "github.com/projectdiscovery/nuclei/v2/internal/severity" - "github.com/projectdiscovery/nuclei/v2/pkg/model" "testing" - "github.com/projectdiscovery/nuclei/v2/internal/testutils" "github.com/stretchr/testify/require" + + "github.com/projectdiscovery/nuclei/v2/internal/severity" + "github.com/projectdiscovery/nuclei/v2/internal/testutils" + "github.com/projectdiscovery/nuclei/v2/pkg/model" ) func TestNetworkCompileMake(t *testing.T) { diff --git a/v2/pkg/protocols/network/operators.go b/v2/pkg/protocols/network/operators.go index d4fd0247..c658dddc 100644 --- a/v2/pkg/protocols/network/operators.go +++ b/v2/pkg/protocols/network/operators.go @@ -1,9 +1,9 @@ package network import ( - "github.com/projectdiscovery/nuclei/v2/pkg/model" "time" + "github.com/projectdiscovery/nuclei/v2/pkg/model" "github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors" "github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers" "github.com/projectdiscovery/nuclei/v2/pkg/output" diff --git a/v2/pkg/protocols/network/operators_test.go b/v2/pkg/protocols/network/operators_test.go index bf6b13f6..36f384ba 100644 --- a/v2/pkg/protocols/network/operators_test.go +++ b/v2/pkg/protocols/network/operators_test.go @@ -1,16 +1,17 @@ package network import ( - "github.com/projectdiscovery/nuclei/v2/internal/severity" - "github.com/projectdiscovery/nuclei/v2/pkg/model" "testing" + "github.com/stretchr/testify/require" + + "github.com/projectdiscovery/nuclei/v2/internal/severity" "github.com/projectdiscovery/nuclei/v2/internal/testutils" + "github.com/projectdiscovery/nuclei/v2/pkg/model" "github.com/projectdiscovery/nuclei/v2/pkg/operators" "github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors" "github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers" "github.com/projectdiscovery/nuclei/v2/pkg/output" - "github.com/stretchr/testify/require" ) func TestResponseToDSLMap(t *testing.T) { diff --git a/v2/pkg/protocols/network/request_test.go b/v2/pkg/protocols/network/request_test.go index 11d9f3de..5db22af5 100644 --- a/v2/pkg/protocols/network/request_test.go +++ b/v2/pkg/protocols/network/request_test.go @@ -3,19 +3,20 @@ package network import ( "encoding/hex" "fmt" - "github.com/projectdiscovery/nuclei/v2/internal/severity" - "github.com/projectdiscovery/nuclei/v2/pkg/model" "net/http" "net/http/httptest" "net/url" "testing" + "github.com/stretchr/testify/require" + + "github.com/projectdiscovery/nuclei/v2/internal/severity" "github.com/projectdiscovery/nuclei/v2/internal/testutils" + "github.com/projectdiscovery/nuclei/v2/pkg/model" "github.com/projectdiscovery/nuclei/v2/pkg/operators" "github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors" "github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers" "github.com/projectdiscovery/nuclei/v2/pkg/output" - "github.com/stretchr/testify/require" ) func TestNetworkExecuteWithResults(t *testing.T) { diff --git a/v2/pkg/protocols/offlinehttp/find_test.go b/v2/pkg/protocols/offlinehttp/find_test.go index 4013b92c..c4aeb1b8 100644 --- a/v2/pkg/protocols/offlinehttp/find_test.go +++ b/v2/pkg/protocols/offlinehttp/find_test.go @@ -1,16 +1,17 @@ package offlinehttp import ( - "github.com/projectdiscovery/nuclei/v2/internal/severity" - "github.com/projectdiscovery/nuclei/v2/pkg/model" "io/ioutil" "os" "path" "testing" - "github.com/projectdiscovery/nuclei/v2/internal/testutils" - "github.com/projectdiscovery/nuclei/v2/pkg/operators" "github.com/stretchr/testify/require" + + "github.com/projectdiscovery/nuclei/v2/internal/severity" + "github.com/projectdiscovery/nuclei/v2/internal/testutils" + "github.com/projectdiscovery/nuclei/v2/pkg/model" + "github.com/projectdiscovery/nuclei/v2/pkg/operators" ) func TestFindResponses(t *testing.T) { diff --git a/v2/pkg/protocols/offlinehttp/operators.go b/v2/pkg/protocols/offlinehttp/operators.go index 2c9c183d..3acdbf4f 100644 --- a/v2/pkg/protocols/offlinehttp/operators.go +++ b/v2/pkg/protocols/offlinehttp/operators.go @@ -1,11 +1,11 @@ package offlinehttp import ( - "github.com/projectdiscovery/nuclei/v2/pkg/model" "net/http" "strings" "time" + "github.com/projectdiscovery/nuclei/v2/pkg/model" "github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors" "github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers" "github.com/projectdiscovery/nuclei/v2/pkg/output" diff --git a/v2/pkg/protocols/offlinehttp/operators_test.go b/v2/pkg/protocols/offlinehttp/operators_test.go index aa36dbb6..980de53c 100644 --- a/v2/pkg/protocols/offlinehttp/operators_test.go +++ b/v2/pkg/protocols/offlinehttp/operators_test.go @@ -1,18 +1,19 @@ package offlinehttp import ( - "github.com/projectdiscovery/nuclei/v2/internal/severity" - "github.com/projectdiscovery/nuclei/v2/pkg/model" "net/http" "testing" "time" + "github.com/stretchr/testify/require" + + "github.com/projectdiscovery/nuclei/v2/internal/severity" "github.com/projectdiscovery/nuclei/v2/internal/testutils" + "github.com/projectdiscovery/nuclei/v2/pkg/model" "github.com/projectdiscovery/nuclei/v2/pkg/operators" "github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors" "github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers" "github.com/projectdiscovery/nuclei/v2/pkg/output" - "github.com/stretchr/testify/require" ) func TestResponseToDSLMap(t *testing.T) { diff --git a/v2/pkg/reporting/exporters/sarif/sarif.go b/v2/pkg/reporting/exporters/sarif/sarif.go index 9937a8af..9579fde5 100644 --- a/v2/pkg/reporting/exporters/sarif/sarif.go +++ b/v2/pkg/reporting/exporters/sarif/sarif.go @@ -3,8 +3,6 @@ package sarif import ( "crypto/sha1" "encoding/hex" - "github.com/projectdiscovery/nuclei/v2/internal/severity" - "github.com/projectdiscovery/nuclei/v2/pkg/utils" "os" "path" "strings" @@ -12,8 +10,11 @@ import ( "github.com/owenrumney/go-sarif/sarif" "github.com/pkg/errors" + + "github.com/projectdiscovery/nuclei/v2/internal/severity" "github.com/projectdiscovery/nuclei/v2/pkg/output" "github.com/projectdiscovery/nuclei/v2/pkg/reporting/format" + "github.com/projectdiscovery/nuclei/v2/pkg/utils" ) // Exporter is an exporter for nuclei sarif output format. diff --git a/v2/pkg/reporting/format/format.go b/v2/pkg/reporting/format/format.go index 278f2a55..942ac16b 100644 --- a/v2/pkg/reporting/format/format.go +++ b/v2/pkg/reporting/format/format.go @@ -3,12 +3,12 @@ package format import ( "bytes" "fmt" - "github.com/projectdiscovery/nuclei/v2/pkg/utils" "reflect" "strings" "github.com/projectdiscovery/nuclei/v2/pkg/output" "github.com/projectdiscovery/nuclei/v2/pkg/types" + "github.com/projectdiscovery/nuclei/v2/pkg/utils" ) // Summary returns a formatted built one line summary of the event diff --git a/v2/pkg/reporting/reporting.go b/v2/pkg/reporting/reporting.go index c3bc32f2..369a1e44 100644 --- a/v2/pkg/reporting/reporting.go +++ b/v2/pkg/reporting/reporting.go @@ -1,12 +1,13 @@ package reporting import ( - "github.com/projectdiscovery/nuclei/v2/internal/severity" - "github.com/projectdiscovery/nuclei/v2/pkg/model" - "github.com/projectdiscovery/nuclei/v2/pkg/utils" "strings" "github.com/pkg/errors" + "go.uber.org/multierr" + + "github.com/projectdiscovery/nuclei/v2/internal/severity" + "github.com/projectdiscovery/nuclei/v2/pkg/model" "github.com/projectdiscovery/nuclei/v2/pkg/output" "github.com/projectdiscovery/nuclei/v2/pkg/reporting/dedupe" "github.com/projectdiscovery/nuclei/v2/pkg/reporting/exporters/disk" @@ -14,7 +15,7 @@ import ( "github.com/projectdiscovery/nuclei/v2/pkg/reporting/trackers/github" "github.com/projectdiscovery/nuclei/v2/pkg/reporting/trackers/gitlab" "github.com/projectdiscovery/nuclei/v2/pkg/reporting/trackers/jira" - "go.uber.org/multierr" + "github.com/projectdiscovery/nuclei/v2/pkg/utils" ) // Options is a configuration file for nuclei reporting module @@ -58,10 +59,10 @@ func isTagMatch(event *output.ResultEvent, filter *Filter) bool { } func isSeverityMatch(event *output.ResultEvent, filter *Filter) bool { - severity := event.Info.SeverityHolder.Severity // TODO review + resultEventSeverity := event.Info.SeverityHolder.Severity // TODO review if utils.IsNotEmpty(filter.Severities) { for _, current := range filter.Severities { - if current == severity { + if current == resultEventSeverity { return true } } diff --git a/v2/pkg/reporting/trackers/jira/jira.go b/v2/pkg/reporting/trackers/jira/jira.go index a1e44028..62dfddb2 100644 --- a/v2/pkg/reporting/trackers/jira/jira.go +++ b/v2/pkg/reporting/trackers/jira/jira.go @@ -3,15 +3,16 @@ package jira import ( "bytes" "fmt" - "github.com/projectdiscovery/nuclei/v2/pkg/utils" "io/ioutil" "reflect" "strings" - jira "github.com/andygrunwald/go-jira" + "github.com/andygrunwald/go-jira" + "github.com/projectdiscovery/nuclei/v2/pkg/output" "github.com/projectdiscovery/nuclei/v2/pkg/reporting/format" "github.com/projectdiscovery/nuclei/v2/pkg/types" + "github.com/projectdiscovery/nuclei/v2/pkg/utils" ) // Integration is a client for a issue tracker integration diff --git a/v2/pkg/templates/compile.go b/v2/pkg/templates/compile.go index 4086364c..74d7a72e 100644 --- a/v2/pkg/templates/compile.go +++ b/v2/pkg/templates/compile.go @@ -3,17 +3,18 @@ package templates import ( "bytes" "fmt" - "github.com/projectdiscovery/nuclei/v2/pkg/utils" "io/ioutil" "os" "strings" "github.com/pkg/errors" + "gopkg.in/yaml.v2" + "github.com/projectdiscovery/nuclei/v2/pkg/operators" "github.com/projectdiscovery/nuclei/v2/pkg/protocols" "github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/executer" "github.com/projectdiscovery/nuclei/v2/pkg/protocols/offlinehttp" - "gopkg.in/yaml.v2" + "github.com/projectdiscovery/nuclei/v2/pkg/utils" ) // Parse parses a yaml request template file diff --git a/v2/pkg/types/interfaces.go b/v2/pkg/types/interfaces.go index f416fa6e..854fc2aa 100644 --- a/v2/pkg/types/interfaces.go +++ b/v2/pkg/types/interfaces.go @@ -4,9 +4,10 @@ package types import ( "fmt" - "github.com/projectdiscovery/nuclei/v2/internal/severity" "strconv" "strings" + + "github.com/projectdiscovery/nuclei/v2/internal/severity" ) // ToString converts an interface to string in a quick way diff --git a/v2/pkg/utils/utils.go b/v2/pkg/utils/utils.go index 8cf7c59f..3ffaf5cb 100644 --- a/v2/pkg/utils/utils.go +++ b/v2/pkg/utils/utils.go @@ -13,6 +13,7 @@ func isEmpty(value interface{}) bool { reflectValue := reflect.ValueOf(value) actualValueInterface := reflectValue.Interface() + // nolint:exhaustive //default branch handles other cases switch reflect.TypeOf(value).Kind() { case reflect.String: reflectedValue := actualValueInterface.(string) diff --git a/v2/pkg/utils/utils_test.go b/v2/pkg/utils/utils_test.go index 2b85b6ac..43a0f9ad 100644 --- a/v2/pkg/utils/utils_test.go +++ b/v2/pkg/utils/utils_test.go @@ -2,10 +2,12 @@ package utils import ( "fmt" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) +//nolint:scopelint //false-positive func TestIsEmpty(t *testing.T) { testCases := [...][2]interface{}{ {"", true},