migrate cataloging config to separate source file

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman 2022-03-14 12:30:08 -04:00
parent 3323ce2b6b
commit a70cfa6dd7
No known key found for this signature in database
GPG Key ID: 5CB45AE22BAB7EA7
3 changed files with 47 additions and 43 deletions

47
syft/cataloging_config.go Normal file
View File

@ -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(),
}
}

View File

@ -2,50 +2,12 @@ package syft
import ( import (
"crypto" "crypto"
"github.com/anchore/syft/internal"
"github.com/anchore/syft/internal/version"
"github.com/anchore/syft/syft/file" "github.com/anchore/syft/syft/file"
"github.com/anchore/syft/syft/pkg" "github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/pkg/cataloger/packages" "github.com/anchore/syft/syft/pkg/cataloger/packages"
"github.com/anchore/syft/syft/source" "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 type CatalogingOption func(*source.Source, *CatalogingConfig) error
func WithConfig(override CatalogingConfig) CatalogingOption { func WithConfig(override CatalogingConfig) CatalogingOption {

View File

@ -117,11 +117,6 @@ func generateCatalogSecretsTask(config CatalogingConfig) (task, error) {
return nil, nil 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) secretsCataloger, err := file.NewSecretsCataloger(config.SecretsConfig)
if err != nil { if err != nil {
return nil, err return nil, err