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

     1  package indexer
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/quay/claircore"
     7  )
     8  
     9  // Store is an interface for dealing with objects libindex needs to persist.
    10  // Stores may be implemented per storage backend.
    11  type Store interface {
    12  	Setter
    13  	Querier
    14  	Indexer
    15  	// Close frees any resources associated with the Store.
    16  	Close(context.Context) error
    17  }
    18  
    19  // Setter interface provides the method set for required marking events, or registering
    20  // components, associated with an Index operation.
    21  type Setter interface {
    22  	// PersistManifest must store the presence of a manifest and it's layers into the system.
    23  	//
    24  	// Typically this will write into identity tables so later methods have a foreign key
    25  	// to reference and data integrity is applied.
    26  	PersistManifest(ctx context.Context, manifest claircore.Manifest) error
    27  	// DeleteManifests removes the manifests indicated by the passed digests
    28  	// from the backing store.
    29  	DeleteManifests(context.Context, ...claircore.Digest) ([]claircore.Digest, error)
    30  
    31  	// SetLayerScanned marks the provided layer hash successfully scanned by the provided versioned scanner.
    32  	//
    33  	// After this method is returned a call to Querier.LayerScanned with the same arguments must return true.
    34  	SetLayerScanned(ctx context.Context, hash claircore.Digest, scnr VersionedScanner) error
    35  	// RegisterPackageScanners registers the provided scanners with the persistence layer.
    36  	RegisterScanners(ctx context.Context, scnrs VersionedScanners) error
    37  	// SetIndexReport persists the current state of the IndexReport.
    38  	//
    39  	// IndexReports maybe in intermediate states to provide feedback for clients. this method should be
    40  	// used to communicate scanning state updates. to signal the scan has completely successfully
    41  	// see SetIndexFinished.
    42  	SetIndexReport(context.Context, *claircore.IndexReport) error
    43  	// SetIndexFinished marks a scan successfully completed.
    44  	//
    45  	// After this method returns a call to Querier.ManifestScanned with the manifest hash represted in the provided IndexReport
    46  	// must return true.
    47  	//
    48  	// Also a call to Querier.IndexReport with the manifest hash represted in the provided IndexReport must return the IndexReport
    49  	// in finished state.
    50  	SetIndexFinished(ctx context.Context, sr *claircore.IndexReport, scnrs VersionedScanners) error
    51  }
    52  
    53  // Querier interface provides the method set to ascertain indexed artifacts and query whether a layer
    54  // or manifest has been scanned.
    55  type Querier interface {
    56  	// ManifestScanned returns whether the given manifest was scanned by the provided scanners.
    57  	ManifestScanned(ctx context.Context, hash claircore.Digest, scnrs VersionedScanners) (bool, error)
    58  	// LayerScanned returns whether the given layer was scanned by the provided scanner.
    59  	LayerScanned(ctx context.Context, hash claircore.Digest, scnr VersionedScanner) (bool, error)
    60  	// PackagesByLayer gets all the packages found in a layer limited by the provided scanners.
    61  	PackagesByLayer(ctx context.Context, hash claircore.Digest, scnrs VersionedScanners) ([]*claircore.Package, error)
    62  	// DistributionsByLayer gets all the distributions found in a layer limited by the provided scanners.
    63  	DistributionsByLayer(ctx context.Context, hash claircore.Digest, scnrs VersionedScanners) ([]*claircore.Distribution, error)
    64  	// RepositoriesByLayer gets all the repositories found in a layer limited by the provided scanners.
    65  	RepositoriesByLayer(ctx context.Context, hash claircore.Digest, scnrs VersionedScanners) ([]*claircore.Repository, error)
    66  	// FilesByLayer gets all the interesting files found in a layer limited by the provided scanners.
    67  	FilesByLayer(ctx context.Context, hash claircore.Digest, scnrs VersionedScanners) ([]claircore.File, error)
    68  	// IndexReport attempts to retrieve a persisted IndexReport.
    69  	IndexReport(ctx context.Context, hash claircore.Digest) (*claircore.IndexReport, bool, error)
    70  	// AffectedManifests returns a list of manifest digests which the target vulnerability
    71  	// affects.
    72  	AffectedManifests(ctx context.Context, v claircore.Vulnerability, f claircore.CheckVulnernableFunc) ([]claircore.Digest, error)
    73  }
    74  
    75  // Indexer interface provide the method set required for indexing layer and manifest contents into
    76  // a persistent store.
    77  type Indexer interface {
    78  	// IndexPackages indexes a package into the persistence layer.
    79  	IndexPackages(ctx context.Context, pkgs []*claircore.Package, layer *claircore.Layer, scnr VersionedScanner) error
    80  	// IndexDistributions indexes distributions into the persistence layer.
    81  	IndexDistributions(ctx context.Context, dists []*claircore.Distribution, layer *claircore.Layer, scnr VersionedScanner) error
    82  	// IndexRepositories indexes repositories into the persistence layer.
    83  	IndexRepositories(ctx context.Context, repos []*claircore.Repository, layer *claircore.Layer, scnr VersionedScanner) error
    84  	// IndexFiles indexes the interesting files into the persistence layer.
    85  	IndexFiles(ctx context.Context, files []claircore.File, layer *claircore.Layer, scnr VersionedScanner) error
    86  	// IndexManifest should index the coalesced manifest's content given an IndexReport.
    87  	IndexManifest(ctx context.Context, ir *claircore.IndexReport) error
    88  }