github.com/devseccon/trivy@v0.47.1-0.20231123133102-bd902a0bd996/pkg/fanal/cache/cache.go (about) 1 package cache 2 3 import ( 4 "github.com/devseccon/trivy/pkg/fanal/types" 5 ) 6 7 const ( 8 cacheDirName = "fanal" 9 10 // artifactBucket stores artifact information with artifact ID such as image ID 11 artifactBucket = "artifact" 12 // blobBucket stores os, package and library information per blob ID such as layer ID 13 blobBucket = "blob" 14 ) 15 16 type Cache interface { 17 ArtifactCache 18 LocalArtifactCache 19 } 20 21 // ArtifactCache uses local or remote cache 22 type ArtifactCache interface { 23 // MissingBlobs returns missing blob IDs such as layer IDs in cache 24 MissingBlobs(artifactID string, blobIDs []string) (missingArtifact bool, missingBlobIDs []string, err error) 25 26 // PutArtifact stores artifact information such as image metadata in cache 27 PutArtifact(artifactID string, artifactInfo types.ArtifactInfo) (err error) 28 29 // PutBlob stores blob information such as layer information in local cache 30 PutBlob(blobID string, blobInfo types.BlobInfo) (err error) 31 32 // DeleteBlobs removes blobs by IDs 33 DeleteBlobs(blobIDs []string) error 34 } 35 36 // LocalArtifactCache always uses local cache 37 type LocalArtifactCache interface { 38 // GetArtifact gets artifact information such as image metadata from local cache 39 GetArtifact(artifactID string) (artifactInfo types.ArtifactInfo, err error) 40 41 // GetBlob gets blob information such as layer data from local cache 42 GetBlob(blobID string) (blobInfo types.BlobInfo, err error) 43 44 // Close closes the local database 45 Close() (err error) 46 47 // Clear deletes the local database 48 Clear() (err error) 49 }