mirror of
https://github.com/anchore/syft.git
synced 2026-02-12 10:36:45 +01:00
feat: CLI flag for directory base (#1867)
Signed-off-by: Avi Deitcher <avi@deitcher.net> Signed-off-by: Keith Zantow <kzantow@gmail.com> Co-authored-by: Keith Zantow <kzantow@gmail.com>
This commit is contained in:
parent
9744f4c009
commit
4ab9f393fc
@ -99,6 +99,7 @@ func buildSBOM(app *config.Application, userInput string, errs chan error) (*sbo
|
|||||||
Paths: app.Exclusions,
|
Paths: app.Exclusions,
|
||||||
},
|
},
|
||||||
DigestAlgorithms: hashers,
|
DigestAlgorithms: hashers,
|
||||||
|
BasePath: app.BasePath,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,7 @@ type PackagesOptions struct {
|
|||||||
Catalogers []string
|
Catalogers []string
|
||||||
SourceName string
|
SourceName string
|
||||||
SourceVersion string
|
SourceVersion string
|
||||||
|
BasePath string
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Interface = (*PackagesOptions)(nil)
|
var _ Interface = (*PackagesOptions)(nil)
|
||||||
@ -59,6 +60,9 @@ func (o *PackagesOptions) AddFlags(cmd *cobra.Command, v *viper.Viper) error {
|
|||||||
cmd.Flags().StringVarP(&o.SourceVersion, "source-version", "", "",
|
cmd.Flags().StringVarP(&o.SourceVersion, "source-version", "", "",
|
||||||
"set the name of the target being analyzed")
|
"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)
|
return bindPackageConfigOptions(cmd.Flags(), v)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,5 +110,9 @@ func bindPackageConfigOptions(flags *pflag.FlagSet, v *viper.Viper) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := v.BindPFlag("base-path", flags.Lookup("base-path")); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,6 +97,7 @@ func execWorker(app *config.Application, userInput string, writer sbom.Writer) <
|
|||||||
Paths: app.Exclusions,
|
Paths: app.Exclusions,
|
||||||
},
|
},
|
||||||
DigestAlgorithms: hashers,
|
DigestAlgorithms: hashers,
|
||||||
|
BasePath: app.BasePath,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -103,6 +103,7 @@ func execWorker(app *config.Application, userInput string, writer sbom.Writer) <
|
|||||||
Paths: app.Exclusions,
|
Paths: app.Exclusions,
|
||||||
},
|
},
|
||||||
DigestAlgorithms: nil,
|
DigestAlgorithms: nil,
|
||||||
|
BasePath: app.BasePath,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -64,6 +64,7 @@ type Application struct {
|
|||||||
Source sourceCfg `yaml:"source" json:"source" mapstructure:"source"`
|
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
|
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
|
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 {
|
func (cfg Application) ToCatalogerConfig() cataloger.Config {
|
||||||
|
|||||||
@ -87,6 +87,7 @@ type DetectionSourceConfig struct {
|
|||||||
Platform *image.Platform
|
Platform *image.Platform
|
||||||
Exclude ExcludeConfig
|
Exclude ExcludeConfig
|
||||||
DigestAlgorithms []crypto.Hash
|
DigestAlgorithms []crypto.Hash
|
||||||
|
BasePath string
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultDetectionSourceConfig() DetectionSourceConfig {
|
func DefaultDetectionSourceConfig() DetectionSourceConfig {
|
||||||
@ -117,10 +118,14 @@ func (d Detection) NewSource(cfg DetectionSourceConfig) (Source, error) {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
case directoryType:
|
case directoryType:
|
||||||
|
base := cfg.BasePath
|
||||||
|
if base == "" {
|
||||||
|
base = d.location
|
||||||
|
}
|
||||||
src, err = NewFromDirectory(
|
src, err = NewFromDirectory(
|
||||||
DirectoryConfig{
|
DirectoryConfig{
|
||||||
Path: d.location,
|
Path: d.location,
|
||||||
Base: d.location,
|
Base: base,
|
||||||
Exclude: cfg.Exclude,
|
Exclude: cfg.Exclude,
|
||||||
Alias: cfg.Alias,
|
Alias: cfg.Alias,
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user