Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add enable to files cataloger #3115

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/syft/internal/options/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 2 additions & 0 deletions cmd/syft/internal/options/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -33,6 +34,7 @@ type fileExecutable struct {

func defaultFileConfig() fileConfig {
return fileConfig{
Enabled: true,
Metadata: fileMetadata{
Selection: file.FilesOwnedByPackageSelection,
Digests: []string{"sha1", "sha256"},
Expand Down
4 changes: 4 additions & 0 deletions syft/cataloging/filecataloging/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ 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"`
Executable executable.Config `yaml:"executable" json:"executable" mapstructure:"executable"`
}

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"`
Expand All @@ -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(),
Expand All @@ -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),
}
Expand Down
25 changes: 13 additions & 12 deletions syft/create_sbom_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions syft/sbom/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading