Skip to content

Commit

Permalink
fix none in files
Browse files Browse the repository at this point in the history
Signed-off-by: tomersein <[email protected]>
  • Loading branch information
tomersein committed Aug 17, 2024
1 parent 4b7ae0e commit 3b18321
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
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
3 changes: 3 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 @@ -41,6 +43,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

0 comments on commit 3b18321

Please sign in to comment.