diff --git a/cmd/power_user_tasks.go b/cmd/power_user_tasks.go index d6510922e..feacb7174 100644 --- a/cmd/power_user_tasks.go +++ b/cmd/power_user_tasks.go @@ -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 +} diff --git a/internal/config/application.go b/internal/config/application.go index 0f1ea7b5a..3c0f2f112 100644 --- a/internal/config/application.go +++ b/internal/config/application.go @@ -27,17 +27,18 @@ type parser interface { // Application is the main syft application configuration. type Application struct { - ConfigPath string `yaml:",omitempty" json:"configPath"` // the location where the application config was read from (either from -c or discovered while loading) - Output string `yaml:"output" json:"output" mapstructure:"output"` // -o, the Presenter hint string to use for report formatting - Quiet bool `yaml:"quiet" json:"quiet" mapstructure:"quiet"` // -q, indicates to not show any status output to stderr (ETUI or logging UI) - Log logging `yaml:"log" json:"log" mapstructure:"log"` // all logging-related options - CliOptions CliOnlyOptions `yaml:"-" json:"-"` // all options only available through the CLI (not via env vars or config) - Dev Development `yaml:"dev" json:"dev" mapstructure:"dev"` - CheckForAppUpdate bool `yaml:"check-for-app-update" json:"check-for-app-update" mapstructure:"check-for-app-update"` // whether to check for an application update on start up or not - Anchore anchore `yaml:"anchore" json:"anchore" mapstructure:"anchore"` // options for interacting with Anchore Engine/Enterprise - Package Packages `yaml:"package" json:"package" mapstructure:"package"` - FileMetadata FileMetadata `yaml:"file-metadata" json:"file-metadata" mapstructure:"file-metadata"` - Secrets Secrets `yaml:"secrets" json:"secrets" mapstructure:"secrets"` + ConfigPath string `yaml:",omitempty" json:"configPath"` // the location where the application config was read from (either from -c or discovered while loading) + Output string `yaml:"output" json:"output" mapstructure:"output"` // -o, the Presenter hint string to use for report formatting + Quiet bool `yaml:"quiet" json:"quiet" mapstructure:"quiet"` // -q, indicates to not show any status output to stderr (ETUI or logging UI) + CheckForAppUpdate bool `yaml:"check-for-app-update" json:"check-for-app-update" mapstructure:"check-for-app-update"` // whether to check for an application update on start up or not + Anchore anchore `yaml:"anchore" json:"anchore" mapstructure:"anchore"` // options for interacting with Anchore Engine/Enterprise + CliOptions CliOnlyOptions `yaml:"-" json:"-"` // all options only available through the CLI (not via env vars or config) + Dev development `yaml:"dev" json:"dev" mapstructure:"dev"` + Log logging `yaml:"log" json:"log" mapstructure:"log"` // all logging-related options + Package packages `yaml:"package" json:"package" mapstructure:"package"` + FileMetadata FileMetadata `yaml:"file-metadata" json:"file-metadata" mapstructure:"file-metadata"` + FileClassification fileClassification `yaml:"file-classification" json:"file-classification" mapstructure:"file-classification"` + Secrets secrets `yaml:"secrets" json:"secrets" mapstructure:"secrets"` } func newApplicationConfig(v *viper.Viper, cliOpts CliOnlyOptions) *Application { diff --git a/internal/config/development.go b/internal/config/development.go index ece8faea8..4e1e8b01a 100644 --- a/internal/config/development.go +++ b/internal/config/development.go @@ -2,12 +2,12 @@ package config import "github.com/spf13/viper" -type Development struct { +type development struct { ProfileCPU bool `yaml:"profile-cpu" json:"profile-cpu" mapstructure:"profile-cpu"` ProfileMem bool `yaml:"profile-mem" json:"profile-mem" mapstructure:"profile-mem"` } -func (cfg Development) loadDefaultValues(v *viper.Viper) { +func (cfg development) loadDefaultValues(v *viper.Viper) { v.SetDefault("dev.profile-cpu", false) v.SetDefault("dev.profile-mem", false) } diff --git a/internal/config/file_classification.go b/internal/config/file_classification.go new file mode 100644 index 000000000..f7069979a --- /dev/null +++ b/internal/config/file_classification.go @@ -0,0 +1,19 @@ +package config + +import ( + "github.com/anchore/syft/syft/source" + "github.com/spf13/viper" +) + +type fileClassification struct { + Cataloger catalogerOptions `yaml:"cataloger" json:"cataloger" mapstructure:"cataloger"` +} + +func (cfg fileClassification) loadDefaultValues(v *viper.Viper) { + v.SetDefault("file-classification.cataloger.enabled", true) + v.SetDefault("file-classification.cataloger.scope", source.SquashedScope) +} + +func (cfg *fileClassification) parseConfigValues() error { + return cfg.Cataloger.parseConfigValues() +} diff --git a/internal/config/packages.go b/internal/config/packages.go index e3aa0e03c..be306d9e5 100644 --- a/internal/config/packages.go +++ b/internal/config/packages.go @@ -2,14 +2,14 @@ package config import "github.com/spf13/viper" -type Packages struct { +type packages struct { Cataloger catalogerOptions `yaml:"cataloger" json:"cataloger" mapstructure:"cataloger"` } -func (cfg Packages) loadDefaultValues(v *viper.Viper) { +func (cfg packages) loadDefaultValues(v *viper.Viper) { v.SetDefault("package.cataloger.enabled", true) } -func (cfg *Packages) parseConfigValues() error { +func (cfg *packages) parseConfigValues() error { return cfg.Cataloger.parseConfigValues() } diff --git a/internal/config/secrets.go b/internal/config/secrets.go index 54ee17dc7..fc7457f95 100644 --- a/internal/config/secrets.go +++ b/internal/config/secrets.go @@ -6,7 +6,7 @@ import ( "github.com/spf13/viper" ) -type Secrets struct { +type secrets struct { Cataloger catalogerOptions `yaml:"cataloger" json:"cataloger" mapstructure:"cataloger"` AdditionalPatterns map[string]string `yaml:"additional-patterns" json:"additional-patterns" mapstructure:"additional-patterns"` ExcludePatternNames []string `yaml:"exclude-pattern-names" json:"exclude-pattern-names" mapstructure:"exclude-pattern-names"` @@ -14,7 +14,7 @@ type Secrets struct { SkipFilesAboveSize int64 `yaml:"skip-files-above-size" json:"skip-files-above-size" mapstructure:"skip-files-above-size"` } -func (cfg Secrets) loadDefaultValues(v *viper.Viper) { +func (cfg secrets) loadDefaultValues(v *viper.Viper) { v.SetDefault("secrets.cataloger.enabled", true) v.SetDefault("secrets.cataloger.scope", source.AllLayersScope) v.SetDefault("secrets.reveal-values", false) @@ -23,6 +23,6 @@ func (cfg Secrets) loadDefaultValues(v *viper.Viper) { v.SetDefault("secrets.exclude-pattern-names", []string{}) } -func (cfg *Secrets) parseConfigValues() error { +func (cfg *secrets) parseConfigValues() error { return cfg.Cataloger.parseConfigValues() }