From a70cfa6dd7a89bd9996e48af1d1e859ed39e92d6 Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Mon, 14 Mar 2022 12:30:08 -0400 Subject: [PATCH] migrate cataloging config to separate source file Signed-off-by: Alex Goodman --- syft/cataloging_config.go | 47 +++++++++++++++++++++++++++++++++++++++ syft/cataloging_option.go | 38 ------------------------------- syft/tasks.go | 5 ----- 3 files changed, 47 insertions(+), 43 deletions(-) create mode 100644 syft/cataloging_config.go diff --git a/syft/cataloging_config.go b/syft/cataloging_config.go new file mode 100644 index 000000000..d9b73dbb0 --- /dev/null +++ b/syft/cataloging_config.go @@ -0,0 +1,47 @@ +package syft + +import ( + "crypto" + + "github.com/anchore/syft/internal" + "github.com/anchore/syft/internal/version" + "github.com/anchore/syft/syft/file" + "github.com/anchore/syft/syft/pkg" + "github.com/anchore/syft/syft/source" +) + +type CatalogingConfig struct { + // tool-specific information + ToolName string + ToolVersion string + ToolConfiguration interface{} + // applies to all catalogers + Scope source.Scope + ProcessTasksInSerial bool + // package + PackageCatalogers []pkg.Cataloger + // file metadata + CaptureFileMetadata bool + DigestHashes []crypto.Hash + // secrets + CaptureSecrets bool + SecretsConfig file.SecretsCatalogerConfig + SecretsScope source.Scope + // file classification + ClassifyFiles bool + FileClassifiers []file.Classifier + // file contents + ContentsConfig file.ContentsCatalogerConfig +} + +func DefaultCatalogingConfig() CatalogingConfig { + return CatalogingConfig{ + Scope: source.SquashedScope, + ToolName: internal.ApplicationName, + ToolVersion: version.Guess(), + SecretsScope: source.AllLayersScope, + SecretsConfig: file.DefaultSecretsCatalogerConfig(), + FileClassifiers: file.DefaultClassifiers(), + ContentsConfig: file.DefaultContentsCatalogerConfig(), + } +} diff --git a/syft/cataloging_option.go b/syft/cataloging_option.go index dcabefd77..4ea2c6217 100644 --- a/syft/cataloging_option.go +++ b/syft/cataloging_option.go @@ -2,50 +2,12 @@ package syft import ( "crypto" - "github.com/anchore/syft/internal" - "github.com/anchore/syft/internal/version" "github.com/anchore/syft/syft/file" "github.com/anchore/syft/syft/pkg" "github.com/anchore/syft/syft/pkg/cataloger/packages" "github.com/anchore/syft/syft/source" ) -type CatalogingConfig struct { - // tool-specific information - ToolName string - ToolVersion string - ToolConfiguration interface{} - // applies to all catalogers - Scope source.Scope - ProcessTasksInSerial bool - // package - PackageCatalogers []pkg.Cataloger - // file metadata - CaptureFileMetadata bool - DigestHashes []crypto.Hash - // secrets - CaptureSecrets bool - SecretsConfig file.SecretsCatalogerConfig - SecretsScope source.Scope - // file classification - ClassifyFiles bool - FileClassifiers []file.Classifier - // file contents - ContentsConfig file.ContentsCatalogerConfig -} - -func DefaultCatalogingConfig() CatalogingConfig { - return CatalogingConfig{ - Scope: source.SquashedScope, - ToolName: internal.ApplicationName, - ToolVersion: version.Guess(), - SecretsScope: source.AllLayersScope, - SecretsConfig: file.DefaultSecretsCatalogerConfig(), - FileClassifiers: file.DefaultClassifiers(), - ContentsConfig: file.DefaultContentsCatalogerConfig(), - } -} - type CatalogingOption func(*source.Source, *CatalogingConfig) error func WithConfig(override CatalogingConfig) CatalogingOption { diff --git a/syft/tasks.go b/syft/tasks.go index df2e439f4..d549916f1 100644 --- a/syft/tasks.go +++ b/syft/tasks.go @@ -117,11 +117,6 @@ func generateCatalogSecretsTask(config CatalogingConfig) (task, error) { return nil, nil } - //patterns, err := file.GenerateSearchPatterns(file.DefaultSecretsPatterns, appConfig.Secrets.AdditionalPatterns, appConfig.Secrets.ExcludePatternNames) - //if err != nil { - // return nil, err - //} - secretsCataloger, err := file.NewSecretsCataloger(config.SecretsConfig) if err != nil { return nil, err