Skip to content

Commit

Permalink
add deprecation notices and split old and new cataloging config
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
  • Loading branch information
wagoodman committed Dec 16, 2022
1 parent 81f6983 commit 99f9d1e
Show file tree
Hide file tree
Showing 24 changed files with 209 additions and 144 deletions.
19 changes: 18 additions & 1 deletion cmd/syft/cli/eventloop/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import (
"github.com/anchore/syft/syft"
"github.com/anchore/syft/syft/artifact"
"github.com/anchore/syft/syft/file"
"github.com/anchore/syft/syft/pkg/cataloger"
"github.com/anchore/syft/syft/sbom"
"github.com/anchore/syft/syft/source"
)

// Deprecated: will be removed in syft 1.0
type Task func(*sbom.Artifacts, *source.Source) ([]artifact.Relationship, error)

// Deprecated: will be removed in syft 1.0
func Tasks(app *config.Application) ([]Task, error) {
var tasks []Task

Expand All @@ -39,13 +42,22 @@ func Tasks(app *config.Application) ([]Task, error) {
return tasks, nil
}

// Deprecated: will be removed in syft 1.0
func generateCatalogPackagesTask(app *config.Application) (Task, error) {
if !app.Package.Cataloger.Enabled {
return nil, nil
}

task := func(results *sbom.Artifacts, src *source.Source) ([]artifact.Relationship, error) {
packageCatalog, relationships, theDistro, err := syft.CatalogPackages(src, app.ToCatalogerConfig())
cfg := cataloger.Config{
Search: cataloger.SearchConfig{
IncludeIndexedArchives: app.Package.SearchIndexedArchives,
IncludeUnindexedArchives: app.Package.SearchUnindexedArchives,
Scope: app.Package.Cataloger.ScopeOpt,
},
Catalogers: app.Catalogers,
}
packageCatalog, relationships, theDistro, err := syft.CatalogPackages(src, cfg)
if err != nil {
return nil, err
}
Expand All @@ -59,6 +71,7 @@ func generateCatalogPackagesTask(app *config.Application) (Task, error) {
return task, nil
}

// Deprecated: will be removed in syft 1.0
func generateCatalogFileMetadataTask(app *config.Application) (Task, error) {
if !app.FileMetadata.Cataloger.Enabled {
return nil, nil
Expand All @@ -83,6 +96,7 @@ func generateCatalogFileMetadataTask(app *config.Application) (Task, error) {
return task, nil
}

// Deprecated: will be removed in syft 1.0
func generateCatalogFileDigestsTask(app *config.Application) (Task, error) {
if !app.FileMetadata.Cataloger.Enabled {
return nil, nil
Expand Down Expand Up @@ -126,6 +140,7 @@ func generateCatalogFileDigestsTask(app *config.Application) (Task, error) {
return task, nil
}

// Deprecated: will be removed in syft 1.0
func generateCatalogSecretsTask(app *config.Application) (Task, error) {
if !app.Secrets.Cataloger.Enabled {
return nil, nil
Expand Down Expand Up @@ -158,6 +173,7 @@ func generateCatalogSecretsTask(app *config.Application) (Task, error) {
return task, nil
}

// Deprecated: will be removed in syft 1.0
func generateCatalogContentsTask(app *config.Application) (Task, error) {
if !app.FileContents.Cataloger.Enabled {
return nil, nil
Expand Down Expand Up @@ -185,6 +201,7 @@ func generateCatalogContentsTask(app *config.Application) (Task, error) {
return task, nil
}

// Deprecated: will be removed in syft 1.0
func RunTask(t Task, a *sbom.Artifacts, src *source.Source, c chan<- artifact.Relationship, errs chan<- error) {
defer close(c)

Expand Down
2 changes: 1 addition & 1 deletion cmd/syft/cli/options/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/spf13/viper"

"github.com/anchore/syft/syft"
"github.com/anchore/syft/syft/cataloger"
"github.com/anchore/syft/syft/formats/table"
"github.com/anchore/syft/syft/pkg/cataloger"
"github.com/anchore/syft/syft/source"
)

Expand Down
24 changes: 18 additions & 6 deletions cmd/syft/cli/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package packages
import (
"context"
"fmt"
"strings"

"github.com/wagoodman/go-partybus"

Expand All @@ -15,10 +14,11 @@ import (
"github.com/anchore/syft/internal/log"
"github.com/anchore/syft/internal/ui"
"github.com/anchore/syft/syft"
"github.com/anchore/syft/syft/artifact"
"github.com/anchore/syft/syft/cataloger"
"github.com/anchore/syft/syft/event"
"github.com/anchore/syft/syft/file"
"github.com/anchore/syft/syft/formats/template"
"github.com/anchore/syft/syft/pkg/cataloger"
"github.com/anchore/syft/syft/sbom"
"github.com/anchore/syft/syft/source"
)
Expand Down Expand Up @@ -103,7 +103,7 @@ func GenerateSBOM(src *source.Source, errs chan error, app *config.Application)
}

cfg := syft.DefaultSBOMBuilderConfig().
WithCatalogers(src.Metadata,
WithDefaultCatalogers(src.Metadata,
cataloger.Config{
Search: cataloger.SearchConfig{
IncludeIndexedArchives: app.Package.SearchIndexedArchives,
Expand All @@ -118,13 +118,14 @@ func GenerateSBOM(src *source.Source, errs chan error, app *config.Application)
GenerateCPEs: true, // TODO: tie to app config
GuessLanguageFromPURL: true, // TODO: tie to app config
},
FileCatalogingSelection: cataloger.OwnedFilesSelection, // TODO: tie to app config
// TODO: make default the owned-files selection
FileCatalogingSelection: cataloger.NoFilesSelection, // TODO: tie to app config
FileHashers: hashers,
},
strings.Join(app.Catalogers, ","), // TODO: update app config to just be a string?
app.Catalogers...,
)

return syft.BuildSBOM(src, cfg)
return syft.CreateSBOM(src, cfg)
}

func validateOutputOptions(app *config.Application) error {
Expand All @@ -142,3 +143,14 @@ func validateOutputOptions(app *config.Application) error {

return nil
}

// Deprecated: will be removed in v1.0.0
func MergeRelationships(cs ...<-chan artifact.Relationship) (relationships []artifact.Relationship) {
for _, c := range cs {
for n := range c {
relationships = append(relationships, n)
}
}

return relationships
}
1 change: 1 addition & 0 deletions cmd/syft/cli/poweruser.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const powerUserExample = ` {{.appName}} {{.command}} <image>
All behavior is controlled via application configuration and environment variables (see https://github.com/anchore/syft#configuration)
`

// Deprecated: will be removed in syft v1.0.0
func PowerUser(v *viper.Viper, app *config.Application, ro *options.RootOptions) *cobra.Command {
cmd := &cobra.Command{
Use: "power-user [IMAGE]",
Expand Down
2 changes: 2 additions & 0 deletions cmd/syft/cli/poweruser/poweruser.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/anchore/syft/syft/source"
)

// Deprecated: will be removed in syft v1.0.0
func Run(ctx context.Context, app *config.Application, args []string) error {
writer, err := sbom.NewWriter(sbom.WriterOption{
Format: syftjson.Format(),
Expand Down Expand Up @@ -65,6 +66,7 @@ func Run(ctx context.Context, app *config.Application, args []string) error {
)
}

// Deprecated: will be removed in syft v1.0.0
func execWorker(app *config.Application, si source.Input, writer sbom.Writer) <-chan error {
errs := make(chan error)
go func() {
Expand Down
4 changes: 1 addition & 3 deletions internal/config/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ import (
"github.com/anchore/go-logger"
"github.com/anchore/syft/internal"
"github.com/anchore/syft/internal/log"
"github.com/anchore/syft/syft/pkg/cataloger"
"github.com/anchore/syft/syft/cataloger"
)

var (
ErrApplicationConfigNotFound = fmt.Errorf("application config not found")
catalogerEnabledDefault = false
)

type defaultValueLoader interface {
Expand Down Expand Up @@ -65,7 +64,6 @@ func (cfg Application) ToCatalogerConfig() cataloger.Config {
IncludeUnindexedArchives: cfg.Package.SearchUnindexedArchives,
Scope: cfg.Package.Cataloger.ScopeOpt,
},
Catalogers: cfg.Catalogers,
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/config/file_classification.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type fileClassification struct {
}

func (cfg fileClassification) loadDefaultValues(v *viper.Viper) {
v.SetDefault("file-classification.cataloger.enabled", catalogerEnabledDefault)
v.SetDefault("file-classification.cataloger.enabled", false)
v.SetDefault("file-classification.cataloger.scope", source.SquashedScope)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/config/file_contents.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type fileContents struct {
}

func (cfg fileContents) loadDefaultValues(v *viper.Viper) {
v.SetDefault("file-contents.cataloger.enabled", catalogerEnabledDefault)
v.SetDefault("file-contents.cataloger.enabled", false)
v.SetDefault("file-contents.cataloger.scope", source.SquashedScope)
v.SetDefault("file-contents.skip-files-above-size", 1*file.MB)
v.SetDefault("file-contents.globs", []string{})
Expand Down
2 changes: 1 addition & 1 deletion internal/config/file_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type FileMetadata struct {
}

func (cfg FileMetadata) loadDefaultValues(v *viper.Viper) {
v.SetDefault("file-metadata.cataloger.enabled", catalogerEnabledDefault)
v.SetDefault("file-metadata.cataloger.enabled", false)
v.SetDefault("file-metadata.cataloger.scope", source.SquashedScope)
v.SetDefault("file-metadata.digests", []string{"sha256"})
}
Expand Down
2 changes: 1 addition & 1 deletion internal/config/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package config
import (
"github.com/spf13/viper"

"github.com/anchore/syft/syft/pkg/cataloger"
"github.com/anchore/syft/syft/cataloger"
)

type pkg struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/config/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type secrets struct {
}

func (cfg secrets) loadDefaultValues(v *viper.Viper) {
v.SetDefault("secrets.cataloger.enabled", catalogerEnabledDefault)
v.SetDefault("secrets.cataloger.enabled", false)
v.SetDefault("secrets.cataloger.scope", source.AllLayersScope)
v.SetDefault("secrets.reveal-values", false)
v.SetDefault("secrets.skip-files-above-size", 1*file.MB)
Expand Down
78 changes: 78 additions & 0 deletions syft/cataloger/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package cataloger

import (
"crypto"

"github.com/anchore/syft/syft/pkg/cataloger/java"
"github.com/anchore/syft/syft/source"
)

const (
NoFilesSelection FileCatalogingSelection = "no-files"
OwnedFilesSelection FileCatalogingSelection = "owned-files"
AllFilesSelection FileCatalogingSelection = "all-files"
)

type FileCatalogingSelection string

type Config struct {
Search SearchConfig
Relationships RelationshipsConfig
SyntheticData SyntheticConfig
FileCatalogingSelection FileCatalogingSelection
FileHashers []crypto.Hash
}

type RelationshipsConfig struct {
FileOwnership bool
FileOwnershipOverlap bool
}

type SyntheticConfig struct {
GenerateCPEs bool
GuessLanguageFromPURL bool
}

type SearchConfig struct {
IncludeIndexedArchives bool
IncludeUnindexedArchives bool
Scope source.Scope
}

func DefaultConfig() Config {
return Config{
Search: DefaultSearchConfig(),
Relationships: DefaultRelationshipsConfig(),
SyntheticData: DefaultSyntheticConfig(),
FileCatalogingSelection: OwnedFilesSelection,
}
}

func DefaultSearchConfig() SearchConfig {
return SearchConfig{
IncludeIndexedArchives: true,
IncludeUnindexedArchives: false,
Scope: source.SquashedScope,
}
}

func DefaultSyntheticConfig() SyntheticConfig {
return SyntheticConfig{
GenerateCPEs: true,
GuessLanguageFromPURL: true,
}
}

func DefaultRelationshipsConfig() RelationshipsConfig {
return RelationshipsConfig{
FileOwnership: true,
FileOwnershipOverlap: true,
}
}

func (c Config) Java() java.Config {
return java.Config{
SearchUnindexedArchives: c.Search.IncludeUnindexedArchives,
SearchIndexedArchives: c.Search.IncludeIndexedArchives,
}
}
Loading

0 comments on commit 99f9d1e

Please sign in to comment.