github.com/kastenhq/syft@v0.0.0-20230821225854-0710af25cdbe/syft/file/resolver.go (about) 1 package file 2 3 import "io" 4 5 // Resolver is an interface that encompasses how to get specific file references and file contents for a generic data source. 6 type Resolver interface { 7 ContentResolver 8 PathResolver 9 LocationResolver 10 MetadataResolver 11 } 12 13 // ContentResolver knows how to get file content for a given Location 14 type ContentResolver interface { 15 FileContentsByLocation(Location) (io.ReadCloser, error) 16 } 17 18 type MetadataResolver interface { 19 FileMetadataByLocation(Location) (Metadata, error) 20 } 21 22 // PathResolver knows how to get a Location for given string paths and globs 23 type PathResolver interface { 24 // HasPath indicates if the given path exists in the underlying source. 25 // The implementation for this may vary, however, generally the following considerations should be made: 26 // - full symlink resolution should be performed on all requests 27 // - returns locations for any file or directory 28 HasPath(string) bool 29 30 // FilesByPath fetches a set of file references which have the given path (for an image, there may be multiple matches). 31 // The implementation for this may vary, however, generally the following considerations should be made: 32 // - full symlink resolution should be performed on all requests 33 // - only returns locations to files (NOT directories) 34 FilesByPath(paths ...string) ([]Location, error) 35 36 // FilesByGlob fetches a set of file references for the given glob matches 37 // The implementation for this may vary, however, generally the following considerations should be made: 38 // - full symlink resolution should be performed on all requests 39 // - if multiple paths to the same file are found, the best single match should be returned 40 // - only returns locations to files (NOT directories) 41 FilesByGlob(patterns ...string) ([]Location, error) 42 43 // FilesByMIMEType fetches a set of file references which the contents have been classified as one of the given MIME Types. 44 FilesByMIMEType(types ...string) ([]Location, error) 45 46 // RelativeFileByPath fetches a single file at the given path relative to the layer squash of the given reference. 47 // This is helpful when attempting to find a file that is in the same layer or lower as another file. 48 RelativeFileByPath(_ Location, path string) *Location 49 } 50 51 type LocationResolver interface { 52 // AllLocations returns a channel of all file references from the underlying source. 53 // The implementation for this may vary, however, generally the following considerations should be made: 54 // - NO symlink resolution should be performed on results 55 // - returns locations for any file or directory 56 AllLocations() <-chan Location 57 } 58 59 type WritableResolver interface { 60 Resolver 61 62 Write(location Location, reader io.Reader) error 63 }