diff --git a/cmd/syft/internal/options/catalog.go b/cmd/syft/internal/options/catalog.go index 99359abec51..06f74ca1dda 100644 --- a/cmd/syft/internal/options/catalog.go +++ b/cmd/syft/internal/options/catalog.go @@ -109,6 +109,7 @@ func (cfg Catalog) ToFilesConfig() filecataloging.Config { } return filecataloging.Config{ + Enabled: cfg.File.Enabled, Selection: cfg.File.Metadata.Selection, Hashers: hashers, Content: filecontent.Config{ diff --git a/cmd/syft/internal/options/file.go b/cmd/syft/internal/options/file.go index 6ac9c8d2ba3..18fa7d86d2d 100644 --- a/cmd/syft/internal/options/file.go +++ b/cmd/syft/internal/options/file.go @@ -12,6 +12,7 @@ import ( ) type fileConfig struct { + Enabled bool `yaml:"enabled" json:"enabled" mapstructure:"enabled"` Metadata fileMetadata `yaml:"metadata" json:"metadata" mapstructure:"metadata"` Content fileContent `yaml:"content" json:"content" mapstructure:"content"` Executable fileExecutable `yaml:"executable" json:"executable" mapstructure:"executable"` @@ -33,6 +34,7 @@ type fileExecutable struct { func defaultFileConfig() fileConfig { return fileConfig{ + Enabled: true, Metadata: fileMetadata{ Selection: file.FilesOwnedByPackageSelection, Digests: []string{"sha1", "sha256"}, diff --git a/syft/cataloging/filecataloging/config.go b/syft/cataloging/filecataloging/config.go index cc639c2f17b..2dd37e84c11 100644 --- a/syft/cataloging/filecataloging/config.go +++ b/syft/cataloging/filecataloging/config.go @@ -14,6 +14,7 @@ import ( ) type Config struct { + Enabled bool `yaml:"enabled" json:"enabled" mapstructure:"enabled"` Selection file.Selection `yaml:"selection" json:"selection" mapstructure:"selection"` Hashers []crypto.Hash `yaml:"hashers" json:"hashers" mapstructure:"hashers"` Content filecontent.Config `yaml:"content" json:"content" mapstructure:"content"` @@ -21,6 +22,7 @@ type Config struct { } type configMarshaledForm struct { + Enabled bool `yaml:"enabled" json:"enabled" mapstructure:"enabled"` Selection file.Selection `yaml:"selection" json:"selection" mapstructure:"selection"` Hashers []string `yaml:"hashers" json:"hashers" mapstructure:"hashers"` Content filecontent.Config `yaml:"content" json:"content" mapstructure:"content"` @@ -32,6 +34,7 @@ func DefaultConfig() Config { log.WithFields("error", err).Warn("unable to create file hashers") } return Config{ + Enabled: true, Selection: file.FilesOwnedByPackageSelection, Hashers: hashers, Content: filecontent.DefaultConfig(), @@ -41,6 +44,7 @@ func DefaultConfig() Config { func (cfg Config) MarshalJSON() ([]byte, error) { marshaled := configMarshaledForm{ + Enabled: cfg.Enabled, Selection: cfg.Selection, Hashers: hashersToString(cfg.Hashers), } diff --git a/syft/create_sbom_config.go b/syft/create_sbom_config.go index 1f7deb18d72..998e9c5ed01 100644 --- a/syft/create_sbom_config.go +++ b/syft/create_sbom_config.go @@ -201,18 +201,19 @@ func (c *CreateSBOMConfig) makeTaskGroups(src source.Description) ([][]task.Task // fileTasks returns the set of tasks that should be run to catalog files. func (c *CreateSBOMConfig) fileTasks() []task.Task { var tsks []task.Task - - if t := task.NewFileDigestCatalogerTask(c.Files.Selection, c.Files.Hashers...); t != nil { - tsks = append(tsks, t) - } - if t := task.NewFileMetadataCatalogerTask(c.Files.Selection); t != nil { - tsks = append(tsks, t) - } - if t := task.NewFileContentCatalogerTask(c.Files.Content); t != nil { - tsks = append(tsks, t) - } - if t := task.NewExecutableCatalogerTask(c.Files.Selection, c.Files.Executable); t != nil { - tsks = append(tsks, t) + if c.Files.Enabled { + if t := task.NewFileDigestCatalogerTask(c.Files.Selection, c.Files.Hashers...); t != nil { + tsks = append(tsks, t) + } + if t := task.NewFileMetadataCatalogerTask(c.Files.Selection); t != nil { + tsks = append(tsks, t) + } + if t := task.NewFileContentCatalogerTask(c.Files.Content); t != nil { + tsks = append(tsks, t) + } + if t := task.NewExecutableCatalogerTask(c.Files.Selection, c.Files.Executable); t != nil { + tsks = append(tsks, t) + } } return tsks diff --git a/syft/sbom/sbom.go b/syft/sbom/sbom.go index ba3f95f3d46..46ee2dc2846 100644 --- a/syft/sbom/sbom.go +++ b/syft/sbom/sbom.go @@ -62,9 +62,11 @@ func (s SBOM) AllCoordinates() []file.Coordinates { for coordinates := range s.Artifacts.FileDigests { set.Add(coordinates) } - for _, relationship := range s.Relationships { - for _, coordinates := range extractCoordinates(relationship) { - set.Add(coordinates) + if len(set.ToSlice()) > 0 { + for _, relationship := range s.Relationships { + for _, coordinates := range extractCoordinates(relationship) { + set.Add(coordinates) + } } } return set.ToSlice()