source

package
v0.12.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2021 License: Apache-2.0 Imports: 19 Imported by: 123

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

Constants

This section is empty.

Variables

AllScopes is a slice containing all possible scope options

Functions

This section is empty.

Types

type AllLayersResolver

type AllLayersResolver struct {
	// contains filtered or unexported fields
}

AllLayersResolver implements path and content access for the AllLayers source option for container image data sources.

func NewAllLayersResolver

func NewAllLayersResolver(img *image.Image) (*AllLayersResolver, error)

NewAllLayersResolver returns a new resolver from the perspective of all image layers for the given image.

func (*AllLayersResolver) FileContentsByLocation

func (r *AllLayersResolver) FileContentsByLocation(location Location) (io.ReadCloser, error)

FileContentsByLocation fetches file contents for a single file reference, irregardless of the source layer. If the path does not exist an error is returned.

func (*AllLayersResolver) FilesByGlob

func (r *AllLayersResolver) FilesByGlob(patterns ...string) ([]Location, error)

FilesByGlob returns all file.References that match the given path glob pattern from any layer in the image. nolint:gocognit

func (*AllLayersResolver) FilesByPath

func (r *AllLayersResolver) FilesByPath(paths ...string) ([]Location, error)

FilesByPath returns all file.References that match the given paths from any layer in the image.

func (*AllLayersResolver) HasPath added in v0.12.1

func (r *AllLayersResolver) HasPath(path string) bool

HasPath indicates if the given path exists in the underlying source.

func (*AllLayersResolver) MultipleFileContentsByLocation

func (r *AllLayersResolver) MultipleFileContentsByLocation(locations []Location) (map[Location]io.ReadCloser, error)

MultipleFileContentsByLocation returns the file contents for all file.References relative to the image. Note that a file.Reference is a path relative to a particular layer.

func (*AllLayersResolver) RelativeFileByPath

func (r *AllLayersResolver) RelativeFileByPath(location Location, path string) *Location

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.

type ContentRequester added in v0.11.0

type ContentRequester struct {
	// contains filtered or unexported fields
}

ContentRequester is an object tailored for taking source.Location objects which file contents will be resolved upon invoking Execute().

func NewContentRequester added in v0.11.0

func NewContentRequester(data ...*FileData) *ContentRequester

NewContentRequester creates a new ContentRequester object with the given initial request data.

func (*ContentRequester) Add added in v0.11.0

func (r *ContentRequester) Add(data *FileData)

Add appends a new single FileData containing a source.Location to later have the contents fetched and stored within the given FileData object.

func (*ContentRequester) Execute added in v0.11.0

func (r *ContentRequester) Execute(resolver ContentResolver) error

Execute takes the previously provided source.Location's and resolves the file contents, storing the results within the previously provided FileData objects.

type ContentResolver

type ContentResolver interface {
	FileContentsByLocation(Location) (io.ReadCloser, error)
	// TODO: it is possible to be given duplicate locations that will be overridden in the map (key), a subtle problem that coule easily be misued.
	MultipleFileContentsByLocation([]Location) (map[Location]io.ReadCloser, error)
}

ContentResolver knows how to get file content for given file.References

type DirectoryResolver

type DirectoryResolver struct {
	Path string
}

DirectoryResolver implements path and content access for the directory data source.

func (DirectoryResolver) FileContentsByLocation

func (r DirectoryResolver) FileContentsByLocation(location Location) (io.ReadCloser, error)

FileContentsByLocation fetches file contents for a single file reference relative to a directory. If the path does not exist an error is returned.

func (DirectoryResolver) FilesByGlob

func (r DirectoryResolver) FilesByGlob(patterns ...string) ([]Location, error)

FilesByGlob returns all file.References that match the given path glob pattern from any layer in the image.

func (DirectoryResolver) FilesByPath

func (r DirectoryResolver) FilesByPath(userPaths ...string) ([]Location, error)

FilesByPath returns all file.References that match the given paths from the directory.

func (*DirectoryResolver) HasPath added in v0.12.1

func (r *DirectoryResolver) HasPath(userPath string) bool

HasPath indicates if the given path exists in the underlying source.

func (DirectoryResolver) MultipleFileContentsByLocation

func (r DirectoryResolver) MultipleFileContentsByLocation(locations []Location) (map[Location]io.ReadCloser, error)

MultipleFileContentsByLocation returns the file contents for all file.References relative a directory.

func (*DirectoryResolver) RelativeFileByPath

func (r *DirectoryResolver) RelativeFileByPath(_ Location, path string) *Location

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. For the DirectoryResolver, this is a simple path lookup.

func (DirectoryResolver) String

func (r DirectoryResolver) String() string

Stringer to represent a directory path data source

type FileData added in v0.11.0

type FileData struct {
	Location Location
	Contents io.ReadCloser
}

type FileResolver

type FileResolver interface {
	// HasPath indicates if the given path exists in the underlying source.
	HasPath(path 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)
	// 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
}

FileResolver knows how to get a Location for given string paths and globs

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"`
	Scope          Scope           `json:"scope"` // specific perspective to catalog
	Layers         []LayerMetadata `json:"layers"`
	RawManifest    []byte          `json:"manifest"`
	RawConfig      []byte          `json:"config"`
}

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 Resolver objects.

func NewImageMetadata

func NewImageMetadata(img *image.Image, userInput string, scope Scope) ImageMetadata

NewImageMetadata creates a new ImageMetadata object populated from the given stereoscope Image object and user configuration.

type ImageSquashResolver

type ImageSquashResolver struct {
	// contains filtered or unexported fields
}

ImageSquashResolver implements path and content access for the Squashed source option for container image data sources.

func NewImageSquashResolver

func NewImageSquashResolver(img *image.Image) (*ImageSquashResolver, error)

NewImageSquashResolver returns a new resolver from the perspective of the squashed representation for the given image.

func (*ImageSquashResolver) FileContentsByLocation

func (r *ImageSquashResolver) FileContentsByLocation(location Location) (io.ReadCloser, error)

FileContentsByLocation fetches file contents for a single file reference, irregardless of the source layer. If the path does not exist an error is returned.

func (*ImageSquashResolver) FilesByGlob

func (r *ImageSquashResolver) FilesByGlob(patterns ...string) ([]Location, error)

FilesByGlob returns all file.References that match the given path glob pattern within the squashed representation of the image.

func (*ImageSquashResolver) FilesByPath

func (r *ImageSquashResolver) FilesByPath(paths ...string) ([]Location, error)

FilesByPath returns all file.References that match the given paths within the squashed representation of the image.

func (*ImageSquashResolver) HasPath added in v0.12.1

func (r *ImageSquashResolver) HasPath(path string) bool

HasPath indicates if the given path exists in the underlying source.

func (*ImageSquashResolver) MultipleFileContentsByLocation

func (r *ImageSquashResolver) MultipleFileContentsByLocation(locations []Location) (map[Location]io.ReadCloser, error)

MultipleFileContentsByLocation returns the file contents for all file.References relative to the image. Note that a file.Reference is a path relative to a particular layer, in this case only from the squashed representation.

func (*ImageSquashResolver) RelativeFileByPath

func (r *ImageSquashResolver) RelativeFileByPath(_ Location, path string) *Location

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. For the ImageSquashResolver, this is a simple path lookup.

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 {
	RealPath     string `json:"path"`              // The path where all path ancestors have no hardlinks / symlinks
	VirtualPath  string `json:"-"`                 // The path to the file which may or may not have hardlinks / symlinks
	FileSystemID string `json:"layerID,omitempty"` // An ID representing the filesystem. For container images this is a layer digest, directories or root filesystem this is blank.
	// 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

func NewLocation(path string) Location

NewLocation creates a new Location representing a path without denoting a filesystem or FileCatalog reference.

func NewLocationFromImage

func NewLocationFromImage(virtualPath string, ref file.Reference, img *image.Image) Location

NewLocationFromImage creates a new Location representing the given path (extracted from the ref) relative to the given image.

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 {
	Locations []Location
}

MockResolver implements the Resolver 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 (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) 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) 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) MultipleFileContentsByLocation added in v0.11.1

func (r MockResolver) MultipleFileContentsByLocation(locations []Location) (map[Location]io.ReadCloser, error)

MultipleFileContentsByLocation returns the file contents for all specified Locations.

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 Resolver

type Resolver interface {
	ContentResolver
	FileResolver
}

Resolver is an interface that encompasses how to get specific file references and file contents for a generic data source.

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"
)

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

func ParseScope(userStr string) Scope

ParseScope returns a scope as indicated from the given string.

func (Scope) String

func (o Scope) String() string

type Source

type Source struct {
	Resolver Resolver     // a Resolver object to use in file path/glob resolution and file contents resolution
	Image    *image.Image // the image object to be cataloged (image only)
	Metadata Metadata
}

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, o Scope) (Source, func(), error)

New produces a Source based on userInput like dir: or image:tag

func NewFromDirectory

func NewFromDirectory(path string) (Source, error)

NewFromDirectory creates a new source object tailored to catalog a given filesystem directory recursively.

func NewFromImage

func NewFromImage(img *image.Image, scope Scope, userImageStr string) (Source, error)

NewFromImage creates a new source object tailored to catalog a given container image, relative to the option given (e.g. all-layers, squashed, etc)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL