Documentation ¶
Overview ¶
Package source provides an abstraction to allow a user to loosely define a data source to catalog and expose a common interface that catalogers and use explore and analyze data from the data source. All valid (cataloggable) data sources are defined within this package.
Index ¶
- Variables
- func GetXid(info os.FileInfo) (uid, gid int)
- type CoordinateSet
- type Coordinates
- type FileContentResolver
- type FileLocationResolver
- type FileMetadata
- type FileMetadataResolver
- type FilePathResolver
- type FileResolver
- type FileType
- type ImageMetadata
- type LayerMetadata
- type Location
- func NewLocation(realPath string) Location
- func NewLocationFromCoordinates(coordinates Coordinates) Location
- func NewLocationFromDirectory(responsePath string, ref file.Reference) Location
- func NewLocationFromImage(virtualPath string, ref file.Reference, img *image.Image) Location
- func NewVirtualLocation(realPath, virtualPath string) Location
- type Metadata
- type MockResolver
- func (r MockResolver) AllLocations() <-chan Location
- func (r MockResolver) FileContentsByLocation(location Location) (io.ReadCloser, error)
- func (r MockResolver) FileMetadataByLocation(l Location) (FileMetadata, error)
- func (r MockResolver) FilesByGlob(patterns ...string) ([]Location, error)
- func (r MockResolver) FilesByMIMEType(types ...string) ([]Location, error)
- func (r MockResolver) FilesByPath(paths ...string) ([]Location, error)
- func (r MockResolver) HasPath(path string) bool
- func (r MockResolver) RelativeFileByPath(_ Location, path string) *Location
- func (r MockResolver) String() string
- type Scheme
- type Scope
- type Source
Constants ¶
This section is empty.
Variables ¶
var AllSchemes = []Scheme{ DirectoryScheme, ImageScheme, FileScheme, }
var AllScopes = []Scope{ SquashedScope, AllLayersScope, }
AllScopes is a slice containing all possible scope options
var ErrIgnoreIrregularFile = errors.New("ignoring irregular file type")
Functions ¶
Types ¶
type CoordinateSet ¶ added in v0.31.0
type CoordinateSet map[Coordinates]struct{}
CoordinateSet represents a set of string types.
func NewCoordinateSet ¶ added in v0.31.0
func NewCoordinateSet(start ...Coordinates) CoordinateSet
NewCoordinateSet creates a CoordinateSet populated with values from the given slice.
func (CoordinateSet) Add ¶ added in v0.31.0
func (s CoordinateSet) Add(i Coordinates)
Add a string to the set.
func (CoordinateSet) Contains ¶ added in v0.31.0
func (s CoordinateSet) Contains(i Coordinates) bool
Contains indicates if the given string is contained within the set.
func (CoordinateSet) Remove ¶ added in v0.31.0
func (s CoordinateSet) Remove(i Coordinates)
Remove a string from the set.
func (CoordinateSet) ToSlice ¶ added in v0.31.0
func (s CoordinateSet) ToSlice() []Coordinates
ToSlice returns a sorted slice of Locations that are contained within the set.
type Coordinates ¶ added in v0.31.0
type Coordinates struct { RealPath string `json:"path"` // The path where all path ancestors have no hardlinks / symlinks FileSystemID string `json:"layerID,omitempty"` // An ID representing the filesystem. For container images, this is a layer digest. For directories or a root filesystem, this is blank. }
Coordinates contains the minimal information needed to describe how to find a file within any possible source object (e.g. image and directory sources)
func (Coordinates) ID ¶ added in v0.31.0
func (c Coordinates) ID() artifact.ID
func (Coordinates) String ¶ added in v0.31.0
func (c Coordinates) String() string
type FileContentResolver ¶ added in v0.15.0
type FileContentResolver interface {
FileContentsByLocation(Location) (io.ReadCloser, error)
}
FileContentResolver knows how to get file content for a given Location
type FileLocationResolver ¶ added in v0.15.0
type FileLocationResolver interface {
AllLocations() <-chan Location
}
type FileMetadata ¶ added in v0.15.0
type FileMetadataResolver ¶ added in v0.15.0
type FileMetadataResolver interface {
FileMetadataByLocation(Location) (FileMetadata, error)
}
type FilePathResolver ¶ added in v0.15.0
type FilePathResolver interface { // HasPath indicates if the given path exists in the underlying source. HasPath(string) bool // FilesByPath fetches a set of file references which have the given path (for an image, there may be multiple matches) FilesByPath(paths ...string) ([]Location, error) // FilesByGlob fetches a set of file references which the given glob matches FilesByGlob(patterns ...string) ([]Location, error) // FilesByMIMEType fetches a set of file references which the contents have been classified as one of the given MIME Types FilesByMIMEType(types ...string) ([]Location, error) // RelativeFileByPath fetches a single file at the given path relative to the layer squash of the given reference. // This is helpful when attempting to find a file that is in the same layer or lower as another file. RelativeFileByPath(_ Location, path string) *Location }
FilePathResolver knows how to get a Location for given string paths and globs
type FileResolver ¶
type FileResolver interface { FileContentResolver FilePathResolver FileLocationResolver FileMetadataResolver }
FileResolver is an interface that encompasses how to get specific file references and file contents for a generic data source.
type FileType ¶ added in v0.15.0
type FileType string
const ( UnknownFileType FileType = "UnknownFileType" RegularFile FileType = "RegularFile" // IrregularFile is how syft defines files that are neither regular, symbolic or directory. // For ref: the seven standard Unix file types are regular, directory, symbolic link, // FIFO special, block special, character special, and socket as defined by POSIX. IrregularFile FileType = "IrregularFile" HardLink FileType = "HardLink" SymbolicLink FileType = "SymbolicLink" CharacterDevice FileType = "CharacterDevice" BlockDevice FileType = "BlockDevice" Directory FileType = "Directory" FIFONode FileType = "FIFONode" )
type ImageMetadata ¶
type ImageMetadata struct { UserInput string `json:"userInput"` ID string `json:"imageID"` ManifestDigest string `json:"manifestDigest"` MediaType string `json:"mediaType"` Tags []string `json:"tags"` Size int64 `json:"imageSize"` Layers []LayerMetadata `json:"layers"` RawManifest []byte `json:"manifest"` RawConfig []byte `json:"config"` RepoDigests []string `json:"repoDigests"` }
ImageMetadata represents all static metadata that defines what a container image is. This is useful to later describe "what" was cataloged without needing the more complicated stereoscope Image objects or FileResolver objects.
func NewImageMetadata ¶
func NewImageMetadata(img *image.Image, userInput string) ImageMetadata
NewImageMetadata creates a new ImageMetadata object populated from the given stereoscope Image object and user configuration.
type LayerMetadata ¶
type LayerMetadata struct { MediaType string `json:"mediaType"` Digest string `json:"digest"` Size int64 `json:"size"` }
LayerMetadata represents all static metadata that defines what a container image layer is.
type Location ¶
type Location struct { Coordinates VirtualPath string // The path to the file which may or may not have hardlinks / symlinks // contains filtered or unexported fields }
Location represents a path relative to a particular filesystem resolved to a specific file.Reference. This struct is used as a key in content fetching to uniquely identify a file relative to a request (the VirtualPath).
func NewLocation ¶
NewLocation creates a new Location representing a path without denoting a filesystem or FileCatalog reference.
func NewLocationFromCoordinates ¶ added in v0.31.0
func NewLocationFromCoordinates(coordinates Coordinates) Location
NewLocationFromCoordinates creates a new location for the given Coordinates.
func NewLocationFromDirectory ¶ added in v0.23.0
NewLocationFromDirectory creates a new Location representing the given path (extracted from the ref) relative to the given directory.
func NewLocationFromImage ¶
NewLocationFromImage creates a new Location representing the given path (extracted from the ref) relative to the given image.
func NewVirtualLocation ¶ added in v0.31.0
NewVirtualLocation creates a new location for a path accessed by a virtual path (a path with a symlink or hardlink somewhere in the path)
type Metadata ¶
type Metadata struct { Scheme Scheme // the source data scheme type (directory or image) ImageMetadata ImageMetadata // all image info (image only) Path string // the root path to be cataloged (directory only) }
Metadata represents any static source data that helps describe "what" was cataloged.
type MockResolver ¶ added in v0.11.1
type MockResolver struct {
// contains filtered or unexported fields
}
MockResolver implements the FileResolver interface and is intended for use *only in test code*. It provides an implementation that can resolve local filesystem paths using only a provided discrete list of file paths, which are typically paths to test fixtures.
func NewMockResolverForPaths ¶ added in v0.11.1
func NewMockResolverForPaths(paths ...string) *MockResolver
NewMockResolverForPaths creates a new MockResolver, where the only resolvable files are those specified by the supplied paths.
func NewMockResolverForPathsWithMetadata ¶ added in v0.15.0
func NewMockResolverForPathsWithMetadata(metadata map[Location]FileMetadata) *MockResolver
func (MockResolver) AllLocations ¶ added in v0.15.0
func (r MockResolver) AllLocations() <-chan Location
func (MockResolver) FileContentsByLocation ¶ added in v0.11.1
func (r MockResolver) FileContentsByLocation(location Location) (io.ReadCloser, error)
FileContentsByLocation fetches file contents for a single location. If the path does not exist, an error is returned.
func (MockResolver) FileMetadataByLocation ¶ added in v0.15.0
func (r MockResolver) FileMetadataByLocation(l Location) (FileMetadata, error)
func (MockResolver) FilesByGlob ¶ added in v0.11.1
func (r MockResolver) FilesByGlob(patterns ...string) ([]Location, error)
FilesByGlob returns all Locations that match the given path glob pattern.
func (MockResolver) FilesByMIMEType ¶ added in v0.25.0
func (r MockResolver) FilesByMIMEType(types ...string) ([]Location, error)
func (MockResolver) FilesByPath ¶ added in v0.11.1
func (r MockResolver) FilesByPath(paths ...string) ([]Location, error)
FilesByPath returns all Locations that match the given paths.
func (MockResolver) HasPath ¶ added in v0.12.1
func (r MockResolver) HasPath(path string) bool
HasPath indicates if the given path exists in the underlying source.
func (MockResolver) RelativeFileByPath ¶ added in v0.11.1
func (r MockResolver) RelativeFileByPath(_ Location, path string) *Location
RelativeFileByPath returns a single Location for the given path.
func (MockResolver) String ¶ added in v0.11.1
func (r MockResolver) String() string
String returns the string representation of the MockResolver.
type Scheme ¶
type Scheme string
Scheme represents the optional prefixed string at the beginning of a user request (e.g. "docker:").
const ( // UnknownScheme is the default scheme UnknownScheme Scheme = "UnknownScheme" // DirectoryScheme indicates the source being cataloged is a directory on the root filesystem DirectoryScheme Scheme = "DirectoryScheme" // ImageScheme indicates the source being cataloged is a container image ImageScheme Scheme = "ImageScheme" // FileScheme indicates the source being cataloged is a single file FileScheme Scheme = "FileScheme" )
type Scope ¶
type Scope string
Scope indicates "how" or from "which perspectives" the source object should be cataloged from.
const ( // UnknownScope is the default scope UnknownScope Scope = "UnknownScope" // SquashedScope indicates to only catalog content visible from the squashed filesystem representation (what can be seen only within the container at runtime) SquashedScope Scope = "Squashed" // AllLayersScope indicates to catalog content on all layers, irregardless if it is visible from the container at runtime. AllLayersScope Scope = "AllLayers" )
func ParseScope ¶
ParseScope returns a scope as indicated from the given string.
type Source ¶
type Source struct { Image *image.Image // the image object to be cataloged (image only) Metadata Metadata // contains filtered or unexported fields }
Source is an object that captures the data source to be cataloged, configuration, and a specific resolver used in cataloging (based on the data source and configuration)
func New ¶
func New(userInput string, registryOptions *image.RegistryOptions) (*Source, func(), error)
New produces a Source based on userInput like dir: or image:tag
func NewFromDirectory ¶
NewFromDirectory creates a new source object tailored to catalog a given filesystem directory recursively.
func NewFromFile ¶ added in v0.30.0
NewFromFile creates a new source object tailored to catalog a file.
func NewFromImage ¶
NewFromImage creates a new source object tailored to catalog a given container image, relative to the option given (e.g. all-layers, squashed, etc)
func (*Source) FileResolver ¶ added in v0.15.0
func (s *Source) FileResolver(scope Scope) (FileResolver, error)