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

CLI flag for directory base #1867

Merged
merged 5 commits into from
Jul 10, 2023
Merged
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/cli/attest/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func buildSBOM(app *config.Application, userInput string, errs chan error) (*sbo
Paths: app.Exclusions,
},
DigestAlgorithms: hashers,
BasePath: app.BasePath,
},
)

Expand Down
8 changes: 8 additions & 0 deletions cmd/syft/cli/options/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type PackagesOptions struct {
Catalogers []string
SourceName string
SourceVersion string
BasePath string
}

var _ Interface = (*PackagesOptions)(nil)
Expand Down Expand Up @@ -59,6 +60,9 @@ func (o *PackagesOptions) AddFlags(cmd *cobra.Command, v *viper.Viper) error {
cmd.Flags().StringVarP(&o.SourceVersion, "source-version", "", "",
"set the name of the target being analyzed")

cmd.Flags().StringVarP(&o.BasePath, "base-path", "", "",
"base directory for scanning, no links will be followed above this directory, and all paths will be reported relative to this directory")

return bindPackageConfigOptions(cmd.Flags(), v)
}

Expand Down Expand Up @@ -106,5 +110,9 @@ func bindPackageConfigOptions(flags *pflag.FlagSet, v *viper.Viper) error {
return err
}

if err := v.BindPFlag("base-path", flags.Lookup("base-path")); err != nil {
return err
}

return nil
}
1 change: 1 addition & 0 deletions cmd/syft/cli/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func execWorker(app *config.Application, userInput string, writer sbom.Writer) <
Paths: app.Exclusions,
},
DigestAlgorithms: hashers,
BasePath: app.BasePath,
},
)

Expand Down
1 change: 1 addition & 0 deletions cmd/syft/cli/poweruser/poweruser.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func execWorker(app *config.Application, userInput string, writer sbom.Writer) <
Paths: app.Exclusions,
},
DigestAlgorithms: nil,
BasePath: app.BasePath,
},
)

Expand Down
1 change: 1 addition & 0 deletions internal/config/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type Application struct {
Source sourceCfg `yaml:"source" json:"source" mapstructure:"source"`
Parallelism int `yaml:"parallelism" json:"parallelism" mapstructure:"parallelism"` // the number of catalog workers to run in parallel
DefaultImagePullSource string `yaml:"default-image-pull-source" json:"default-image-pull-source" mapstructure:"default-image-pull-source"` // specify default image pull source
BasePath string `yaml:"base-path" json:"base-path" mapstructure:"base-path"` // specify base path for all file paths
}

func (cfg Application) ToCatalogerConfig() cataloger.Config {
Expand Down
7 changes: 6 additions & 1 deletion syft/source/detection.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type DetectionSourceConfig struct {
Platform *image.Platform
Exclude ExcludeConfig
DigestAlgorithms []crypto.Hash
BasePath string
}

func DefaultDetectionSourceConfig() DetectionSourceConfig {
Expand Down Expand Up @@ -117,10 +118,14 @@ func (d Detection) NewSource(cfg DetectionSourceConfig) (Source, error) {
},
)
case directoryType:
base := cfg.BasePath
if base == "" {
base = d.location
}
src, err = NewFromDirectory(
DirectoryConfig{
Path: d.location,
Base: d.location,
Base: base,
Exclude: cfg.Exclude,
Alias: cfg.Alias,
},
Expand Down