github.com/quay/claircore@v1.5.28/indexer/packagescanner.go (about)

     1  package indexer
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/quay/claircore"
     7  )
     8  
     9  // PackageScanner provides an interface for unique identification or a PackageScanner
    10  // and a Scan method for extracting installed packages from an individual container layer
    11  type PackageScanner interface {
    12  	VersionedScanner
    13  	// Scan performs a package scan on the given layer and returns all
    14  	// the found packages
    15  	Scan(context.Context, *claircore.Layer) ([]*claircore.Package, error)
    16  }
    17  
    18  type mockPackageScanner struct {
    19  	name    string
    20  	version string
    21  	kind    string
    22  }
    23  
    24  func (p *mockPackageScanner) Scan(context.Context, *claircore.Layer) ([]*claircore.Package, error) {
    25  	return nil, nil
    26  }
    27  
    28  func (p *mockPackageScanner) Name() string {
    29  	return p.name
    30  }
    31  
    32  func (p *mockPackageScanner) Version() string {
    33  	return p.version
    34  }
    35  
    36  func (p *mockPackageScanner) Kind() string {
    37  	return p.kind
    38  }
    39  
    40  func NewPackageScannerMock(name, version, kind string) PackageScanner {
    41  	return &mockPackageScanner{
    42  		name:    name,
    43  		version: version,
    44  		kind:    kind,
    45  	}
    46  }
    47  
    48  // DefaultRepoScanner provides a DefaultRepository method to allow Package Scanners
    49  // to define what the default repository should be if the Scanner returned packages.
    50  // This is useful to avoid having a dedicated RepositoryScanner for an ecosystem that
    51  // largely duplicates the work of the PackageScanner and would always return the same
    52  // pre-defined repository.
    53  type DefaultRepoScanner interface {
    54  	DefaultRepository(context.Context) *claircore.Repository
    55  }