Path: blob/dev/pkg/loader/workflow/workflow_loader.go
2070 views
package workflow12import (3"github.com/projectdiscovery/gologger"4"github.com/projectdiscovery/nuclei/v3/pkg/catalog/config"5"github.com/projectdiscovery/nuclei/v3/pkg/catalog/loader/filter"6"github.com/projectdiscovery/nuclei/v3/pkg/model"7"github.com/projectdiscovery/nuclei/v3/pkg/protocols"8"github.com/projectdiscovery/nuclei/v3/pkg/templates"9)1011type workflowLoader struct {12pathFilter *filter.PathFilter13tagFilter *templates.TagFilter14options *protocols.ExecutorOptions15}1617// NewLoader returns a new workflow loader structure18func NewLoader(options *protocols.ExecutorOptions) (model.WorkflowLoader, error) {19tagFilter, err := templates.NewTagFilter(&templates.TagFilterConfig{20Authors: options.Options.Authors,21Tags: options.Options.Tags,22ExcludeTags: options.Options.ExcludeTags,23IncludeTags: options.Options.IncludeTags,24IncludeIds: options.Options.IncludeIds,25ExcludeIds: options.Options.ExcludeIds,26Severities: options.Options.Severities,27ExcludeSeverities: options.Options.ExcludeSeverities,28Protocols: options.Options.Protocols,29ExcludeProtocols: options.Options.ExcludeProtocols,30IncludeConditions: options.Options.IncludeConditions,31})32if err != nil {33return nil, err34}35pathFilter := filter.NewPathFilter(&filter.PathFilterConfig{36IncludedTemplates: options.Options.IncludeTemplates,37ExcludedTemplates: options.Options.ExcludedTemplates,38}, options.Catalog)3940return &workflowLoader{pathFilter: pathFilter, tagFilter: tagFilter, options: options}, nil41}4243func (w *workflowLoader) GetTemplatePathsByTags(templateTags []string) []string {44includedTemplates, errs := w.options.Catalog.GetTemplatesPath([]string{config.DefaultConfig.TemplatesDirectory})45for template, err := range errs {46gologger.Error().Msgf("Could not find template '%s': %s", template, err)47}4849templatePathMap := w.pathFilter.Match(includedTemplates)5051loadedTemplates := make([]string, 0, len(templatePathMap))52for templatePath := range templatePathMap {53loaded, _ := w.options.Parser.LoadTemplate(templatePath, w.tagFilter, templateTags, w.options.Catalog)54if loaded {55loadedTemplates = append(loadedTemplates, templatePath)56}57}58return loadedTemplates59}6061func (w *workflowLoader) GetTemplatePaths(templatesList []string, noValidate bool) []string {62includedTemplates, errs := w.options.Catalog.GetTemplatesPath(templatesList)63for template, err := range errs {64gologger.Error().Msgf("Could not find template '%s': %s", template, err)65}66templatesPathMap := w.pathFilter.Match(includedTemplates)6768loadedTemplates := make([]string, 0, len(templatesPathMap))69for templatePath := range templatesPathMap {70matched, err := w.options.Parser.LoadTemplate(templatePath, w.tagFilter, nil, w.options.Catalog)71if err != nil && !matched {72gologger.Warning().Msg(err.Error())73} else if matched || noValidate {74loadedTemplates = append(loadedTemplates, templatePath)75}76}77return loadedTemplates78}798081