mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
* add file catalogers to selection configuration Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix typos Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * warn when there is conflicting file cataloging configuration Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * allow for explicit removal of all package and file tasks Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * address PR feedback Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
41 lines
783 B
Go
41 lines
783 B
Go
package task
|
|
|
|
import (
|
|
"fmt"
|
|
"sort"
|
|
"strings"
|
|
|
|
"github.com/scylladb/go-set/strset"
|
|
)
|
|
|
|
type factory func(cfg CatalogingFactoryConfig) Task
|
|
|
|
type Factories []factory
|
|
|
|
func (f Factories) Tasks(cfg CatalogingFactoryConfig) ([]Task, error) {
|
|
var allTasks []Task
|
|
taskNames := strset.New()
|
|
duplicateTaskNames := strset.New()
|
|
var err error
|
|
for _, fact := range f {
|
|
tsk := fact(cfg)
|
|
if tsk == nil {
|
|
continue
|
|
}
|
|
tskName := tsk.Name()
|
|
if taskNames.Has(tskName) {
|
|
duplicateTaskNames.Add(tskName)
|
|
}
|
|
|
|
allTasks = append(allTasks, tsk)
|
|
taskNames.Add(tskName)
|
|
}
|
|
if duplicateTaskNames.Size() > 0 {
|
|
names := duplicateTaskNames.List()
|
|
sort.Strings(names)
|
|
err = fmt.Errorf("duplicate cataloger task names: %v", strings.Join(names, ", "))
|
|
}
|
|
|
|
return allTasks, err
|
|
}
|