Projects STRLCPY syft Commits 79a955b1
🤬
  • ■ ■ ■ ■
    cmd/syft/cli/attest/attest.go
    skipped 46 lines
    47 47   // could be an image or a directory, with or without a scheme
    48 48   // TODO: validate that source is image
    49 49   userInput := args[0]
    50  - si, err := source.ParseInputWithName(userInput, app.Platform, app.Name, app.DefaultImagePullSource)
     50 + si, err := source.ParseInputWithNameVersion(userInput, app.Platform, app.SourceName, app.SourceVersion, app.DefaultImagePullSource)
    51 51   if err != nil {
    52 52   return fmt.Errorf("could not generate source input for packages command: %w", err)
    53 53   }
    skipped 192 lines
  • ■ ■ ■ ■ ■
    cmd/syft/cli/options/packages.go
    skipped 20 lines
    21 21   Platform string
    22 22   Exclude []string
    23 23   Catalogers []string
    24  - Name string
     24 + SourceName string
     25 + SourceVersion string
    25 26  }
    26 27   
    27 28  var _ Interface = (*PackagesOptions)(nil)
    skipped 20 lines
    48 49   cmd.Flags().StringArrayVarP(&o.Catalogers, "catalogers", "", nil,
    49 50   "enable one or more package catalogers")
    50 51   
    51  - cmd.Flags().StringVarP(&o.Name, "name", "", "",
     52 + cmd.Flags().StringVarP(&o.SourceName, "name", "", "",
     53 + "set the name of the target being analyzed")
     54 + cmd.Flags().Lookup("name").Deprecated = "use: source-name"
     55 + 
     56 + cmd.Flags().StringVarP(&o.SourceName, "source-name", "", "",
     57 + "set the name of the target being analyzed")
     58 + 
     59 + cmd.Flags().StringVarP(&o.SourceVersion, "source-version", "", "",
    52 60   "set the name of the target being analyzed")
    53 61   
    54 62   return bindPackageConfigOptions(cmd.Flags(), v)
    skipped 20 lines
    75 83   }
    76 84   
    77 85   if err := v.BindPFlag("name", flags.Lookup("name")); err != nil {
     86 + return err
     87 + }
     88 + 
     89 + if err := v.BindPFlag("source-name", flags.Lookup("source-name")); err != nil {
     90 + return err
     91 + }
     92 + 
     93 + if err := v.BindPFlag("source-version", flags.Lookup("source-version")); err != nil {
    78 94   return err
    79 95   }
    80 96   
    skipped 15 lines
  • ■ ■ ■ ■
    cmd/syft/cli/packages/packages.go
    skipped 41 lines
    42 42   
    43 43   // could be an image or a directory, with or without a scheme
    44 44   userInput := args[0]
    45  - si, err := source.ParseInputWithName(userInput, app.Platform, app.Name, app.DefaultImagePullSource)
     45 + si, err := source.ParseInputWithNameVersion(userInput, app.Platform, app.SourceName, app.SourceVersion, app.DefaultImagePullSource)
    46 46   if err != nil {
    47 47   return fmt.Errorf("could not generate source input for packages command: %w", err)
    48 48   }
    skipped 104 lines
  • ■ ■ ■ ■
    cmd/syft/cli/poweruser/poweruser.go
    skipped 46 lines
    47 47   }()
    48 48   
    49 49   userInput := args[0]
    50  - si, err := source.ParseInputWithName(userInput, app.Platform, app.Name, app.DefaultImagePullSource)
     50 + si, err := source.ParseInputWithNameVersion(userInput, app.Platform, app.SourceName, app.SourceVersion, app.DefaultImagePullSource)
    51 51   if err != nil {
    52 52   return fmt.Errorf("could not generate source input for packages command: %w", err)
    53 53   }
    skipped 67 lines
  • ■ ■ ■ ■ ■ ■
    internal/config/application.go
    skipped 60 lines
    61 61   Exclusions []string `yaml:"exclude" json:"exclude" mapstructure:"exclude"`
    62 62   Platform string `yaml:"platform" json:"platform" mapstructure:"platform"`
    63 63   Name string `yaml:"name" json:"name" mapstructure:"name"`
     64 + SourceName string `yaml:"source-name" json:"source-name" mapstructure:"source-name"`
     65 + SourceVersion string `yaml:"source-version" json:"source-version" mapstructure:"source-version"`
    64 66   Parallelism int `yaml:"parallelism" json:"parallelism" mapstructure:"parallelism"` // the number of catalog workers to run in parallel
    65 67   DefaultImagePullSource string `yaml:"default-image-pull-source" json:"default-image-pull-source" mapstructure:"default-image-pull-source"` // specify default image pull source
    66 68  }
    skipped 74 lines
    141 143   
    142 144   if err := checkDefaultSourceValues(cfg.DefaultImagePullSource); err != nil {
    143 145   return err
     146 + }
     147 + 
     148 + if cfg.Name != "" {
     149 + log.Warnf("name parameter is deprecated. please use: source-name. name will be removed in a future version")
     150 + if cfg.SourceName == "" {
     151 + cfg.SourceName = cfg.Name
     152 + }
    144 153   }
    145 154   
    146 155   // check for valid default source options
    skipped 175 lines
  • ■ ■ ■ ■ ■
    syft/source/metadata.go
    skipped 7 lines
    8 8   Path string // the root path to be cataloged (directory only)
    9 9   Base string // the base path to be cataloged (directory only)
    10 10   Name string
     11 + Version string
    11 12  }
    12 13   
  • ■ ■ ■ ■ ■ ■
    syft/source/source.go
    skipped 47 lines
    48 48   Location string
    49 49   Platform string
    50 50   Name string
     51 + Version string
    51 52  }
    52 53   
    53 54  // ParseInput generates a source Input that can be used as an argument to generate a new source
    skipped 5 lines
    59 60  // ParseInputWithName generates a source Input that can be used as an argument to generate a new source
    60 61  // from specific providers including a registry, with an explicit name.
    61 62  func ParseInputWithName(userInput string, platform, name, defaultImageSource string) (*Input, error) {
     63 + return ParseInputWithNameVersion(userInput, platform, name, "", defaultImageSource)
     64 +}
     65 + 
     66 +// ParseInputWithNameVersion generates a source Input that can be used as an argument to generate a new source
     67 +// from specific providers including a registry, with an explicit name and version.
     68 +func ParseInputWithNameVersion(userInput, platform, name, version, defaultImageSource string) (*Input, error) {
    62 69   fs := afero.NewOsFs()
    63 70   scheme, source, location, err := DetectScheme(fs, image.DetectSource, userInput)
    64 71   if err != nil {
    skipped 32 lines
    97 104   Location: location,
    98 105   Platform: platform,
    99 106   Name: name,
     107 + Version: version,
    100 108   }, nil
    101 109  }
    102 110   
    skipped 51 lines
    154 162   return nil, cleanup, fmt.Errorf("could not fetch image %q: %w", in.Location, err)
    155 163   }
    156 164   
    157  - s, err := NewFromImageWithName(img, in.Location, in.Name)
     165 + s, err := NewFromImageWithNameVersion(img, in.Location, in.Name, in.Version)
    158 166   if err != nil {
    159 167   return nil, cleanup, fmt.Errorf("could not populate source with image: %w", err)
    160 168   }
    skipped 90 lines
    251 259   return nil, func() {}, fmt.Errorf("given path is not a directory (path=%q): %w", in.Location, err)
    252 260   }
    253 261   
    254  - s, err := NewFromDirectoryWithName(in.Location, in.Name)
     262 + s, err := NewFromDirectoryWithNameVersion(in.Location, in.Name, in.Version)
    255 263   if err != nil {
    256 264   return nil, func() {}, fmt.Errorf("could not populate source from path=%q: %w", in.Location, err)
    257 265   }
    skipped 11 lines
    269 277   return nil, func() {}, fmt.Errorf("given path is not a directory (path=%q): %w", in.Location, err)
    270 278   }
    271 279   
    272  - s, cleanupFn := NewFromFileWithName(in.Location, in.Name)
     280 + s, cleanupFn := NewFromFileWithNameVersion(in.Location, in.Name, in.Version)
    273 281   
    274 282   return &s, cleanupFn, nil
    275 283  }
    skipped 3 lines
    279 287   return NewFromDirectoryWithName(path, "")
    280 288  }
    281 289   
    282  -// NewFromDirectory creates a new source object tailored to catalog a given filesystem directory recursively.
    283  -func NewFromDirectoryRoot(path string) (Source, error) {
    284  - return NewFromDirectoryRootWithName(path, "")
     290 +// NewFromDirectoryWithName creates a new source object tailored to catalog a given filesystem directory recursively, with an explicitly provided name.
     291 +func NewFromDirectoryWithName(path string, name string) (Source, error) {
     292 + return NewFromDirectoryWithNameVersion(path, name, "")
    285 293  }
    286 294   
    287  -// NewFromDirectoryWithName creates a new source object tailored to catalog a given filesystem directory recursively, with an explicitly provided name.
    288  -func NewFromDirectoryWithName(path string, name string) (Source, error) {
     295 +// NewFromDirectoryWithNameVersion creates a new source object tailored to catalog a given filesystem directory recursively, with an explicitly provided name.
     296 +func NewFromDirectoryWithNameVersion(path string, name string, version string) (Source, error) {
    289 297   s := Source{
    290 298   mutex: &sync.Mutex{},
    291 299   Metadata: Metadata{
    292  - Name: name,
    293  - Scheme: DirectoryScheme,
    294  - Path: path,
     300 + Name: name,
     301 + Version: version,
     302 + Scheme: DirectoryScheme,
     303 + Path: path,
    295 304   },
    296 305   path: path,
    297 306   }
    skipped 1 lines
    299 308   return s, nil
    300 309  }
    301 310   
     311 +// NewFromDirectoryRoot creates a new source object tailored to catalog a given filesystem directory recursively.
     312 +func NewFromDirectoryRoot(path string) (Source, error) {
     313 + return NewFromDirectoryRootWithName(path, "")
     314 +}
     315 + 
    302 316  // NewFromDirectoryRootWithName creates a new source object tailored to catalog a given filesystem directory recursively, with an explicitly provided name.
    303 317  func NewFromDirectoryRootWithName(path string, name string) (Source, error) {
     318 + return NewFromDirectoryRootWithNameVersion(path, name, "")
     319 +}
     320 + 
     321 +// NewFromDirectoryRootWithNameVersion creates a new source object tailored to catalog a given filesystem directory recursively, with an explicitly provided name.
     322 +func NewFromDirectoryRootWithNameVersion(path string, name string, version string) (Source, error) {
    304 323   s := Source{
    305 324   mutex: &sync.Mutex{},
    306 325   Metadata: Metadata{
    307  - Name: name,
    308  - Scheme: DirectoryScheme,
    309  - Path: path,
    310  - Base: path,
     326 + Name: name,
     327 + Version: version,
     328 + Scheme: DirectoryScheme,
     329 + Path: path,
     330 + Base: path,
    311 331   },
    312 332   path: path,
    313 333   base: path,
    skipped 9 lines
    323 343   
    324 344  // NewFromFileWithName creates a new source object tailored to catalog a file, with an explicitly provided name.
    325 345  func NewFromFileWithName(path string, name string) (Source, func()) {
     346 + return NewFromFileWithNameVersion(path, name, "")
     347 +}
     348 + 
     349 +// NewFromFileWithNameVersion creates a new source object tailored to catalog a file, with an explicitly provided name and version.
     350 +func NewFromFileWithNameVersion(path string, name string, version string) (Source, func()) {
    326 351   analysisPath, cleanupFn := fileAnalysisPath(path)
    327 352   
    328 353   s := Source{
    329 354   mutex: &sync.Mutex{},
    330 355   Metadata: Metadata{
    331  - Name: name,
    332  - Scheme: FileScheme,
    333  - Path: path,
     356 + Name: name,
     357 + Version: version,
     358 + Scheme: FileScheme,
     359 + Path: path,
    334 360   },
    335 361   path: analysisPath,
    336 362   }
    skipped 43 lines
    380 406  // NewFromImageWithName creates a new source object tailored to catalog a given container image, relative to the
    381 407  // option given (e.g. all-layers, squashed, etc), with an explicit name.
    382 408  func NewFromImageWithName(img *image.Image, userImageStr string, name string) (Source, error) {
     409 + return NewFromImageWithNameVersion(img, userImageStr, name, "")
     410 +}
     411 + 
     412 +// NewFromImageWithNameVersion creates a new source object tailored to catalog a given container image, relative to the
     413 +// option given (e.g. all-layers, squashed, etc), with an explicit name and version.
     414 +func NewFromImageWithNameVersion(img *image.Image, userImageStr string, name string, version string) (Source, error) {
    383 415   if img == nil {
    384 416   return Source{}, fmt.Errorf("no image given")
    385 417   }
    skipped 2 lines
    388 420   Image: img,
    389 421   Metadata: Metadata{
    390 422   Name: name,
     423 + Version: version,
    391 424   Scheme: ImageScheme,
    392 425   ImageMetadata: NewImageMetadata(img, userImageStr),
    393 426   },
    skipped 208 lines
  • ■ ■ ■ ■
    syft/source/source_test.go
    skipped 124 lines
    125 125   Path: "test-fixtures/image-simple",
    126 126   },
    127 127   },
    128  - expected: artifact.ID("1b0dc351e6577b01"),
     128 + expected: artifact.ID("9ee9e786412d6ae5"),
    129 129   },
    130 130   }
    131 131   
    skipped 806 lines
Please wait...
Page is in error, reload to recover