Skip to content

Commit

Permalink
improve as logic
Browse files Browse the repository at this point in the history
  • Loading branch information
XTeam-Wing committed Apr 27, 2024
1 parent 787f0b8 commit 22cd1ec
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 24 deletions.
22 changes: 1 addition & 21 deletions pkg/catalog/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,27 +229,7 @@ func (store *Store) ReadTemplateFromURI(uri string, remote bool) ([]byte, error)
}
}

// Update tagFilter
func (store *Store) UpdateTagFilter(tags, cfg *Config) (err error) {
tagFilter, err := templates.NewTagFilter(&templates.TagFilterConfig{
Tags: cfg.Tags,
ExcludeTags: cfg.ExcludeTags,
Authors: cfg.Authors,
Severities: cfg.Severities,
ExcludeSeverities: cfg.ExcludeSeverities,
IncludeTags: cfg.IncludeTags,
IncludeIds: cfg.IncludeIds,
ExcludeIds: cfg.ExcludeIds,
Protocols: cfg.Protocols,
ExcludeProtocols: cfg.ExcludeProtocols,
IncludeConditions: cfg.IncludeConditions,
})
if err != nil {
return err
}
store.tagFilter = tagFilter
return
}
// ClearFilter
func (store *Store) ClearFilter() (err error) {
tagFilter, err := templates.NewTagFilter(&templates.TagFilterConfig{
Tags: nil,
Expand Down
2 changes: 2 additions & 0 deletions pkg/protocols/common/automaticscan/automaticscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ func (s *Service) executeAutomaticScanOnTarget(input *contextargs.MetaInput) {
return
}
finalTemplates = sliceutil.Dedupe(finalTemplates)

gologger.Info().Msgf("Executing %d templates on %v", len(finalTemplates), input.Input)

eng := core.New(s.opts.Options)
execOptions := s.opts.Copy()
execOptions.Progress = &testutils.MockProgressClient{} // stats are not supported yet due to centralized logic and cannot be reinitialized
Expand Down
5 changes: 2 additions & 3 deletions pkg/protocols/common/automaticscan/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ func getTemplateDirs(opts Options) ([]string, error) {

// LoadTemplatesWithTags loads and returns templates with given tags
func LoadTemplatesWithTags(opts Options, templateDirs []string, tags []string, useIncludeID, logInfo bool) ([]*templates.Template, error) {
newOpt := opts
err := newOpt.Store.ClearFilter()
err := opts.Store.ClearFilter()
if err != nil {
return nil, err
}

finalTemplates := newOpt.Store.LoadTemplatesWithTags(templateDirs, tags)
finalTemplates := opts.Store.LoadTemplatesWithTags(templateDirs, tags)
if len(finalTemplates) == 0 && !useIncludeID {
return nil, errors.New(fmt.Sprintf("could not find any templates with %s tag", strings.Join(tags, ",")))
}
Expand Down

0 comments on commit 22cd1ec

Please sign in to comment.