wire up file classifier to power-user cmd

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman
2021-04-12 17:08:50 -04:00
parent 46bfb68113
commit 870a676a5d
6 changed files with 68 additions and 19 deletions
+29
View File
@@ -20,6 +20,7 @@ func powerUserTasks() ([]powerUserTask, error) {
catalogFileMetadataTask,
catalogFileDigestsTask,
catalogSecretsTask,
catalogFileClassificationsTask,
}
for _, generator := range generators {
@@ -156,3 +157,31 @@ func catalogSecretsTask() (powerUserTask, error) {
return task, nil
}
func catalogFileClassificationsTask() (powerUserTask, error) {
if !appConfig.FileClassification.Cataloger.Enabled {
return nil, nil
}
// TODO: in the future we could expose out the classifiers via configuration
classifierCataloger, err := file.NewClassificationCataloger(file.DefaultClassifiers)
if err != nil {
return nil, err
}
task := func(results *poweruser.JSONDocumentConfig, src source.Source) error {
resolver, err := src.FileResolver(appConfig.FileClassification.Cataloger.ScopeOpt)
if err != nil {
return err
}
result, err := classifierCataloger.Catalog(resolver)
if err != nil {
return err
}
results.FileClassifications = result
return nil
}
return task, nil
}