filesystem

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package filesystem provides the interface for inventory extraction plugins.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrExtractorMemoryLimitExceeded is returned when an extractor skips a file
	// due to the extraction process exceeding a configured memory limit.
	ErrExtractorMemoryLimitExceeded = errors.New("extraction failed due to extractor exceeding the configured memory limit")
)
View Source
var (
	// ErrNotRelativeToScanRoots is returned when one of the file or directory to be retrieved or
	// skipped is not relative to any of the scan roots.
	ErrNotRelativeToScanRoots = fmt.Errorf("path not relative to any of the scan roots")
)

Functions

func ExtractorErrorToFileExtractedResult added in v0.1.2

func ExtractorErrorToFileExtractedResult(err error) stats.FileExtractedResult

ExtractorErrorToFileExtractedResult converts an error returned by an extractor to a FileExtractedResult for stats collection. Converting the error to a result minimizes the memory used for reporting stats.

func InitWalkContext added in v0.1.2

func InitWalkContext(ctx context.Context, config *Config, absScanRoots []*scalibrfs.ScanRoot) (*walkContext, error)

InitWalkContext initializes the walk context for a filesystem walk. It strips all the paths that are expected to be relative to the scan root. This function is exported for TESTS ONLY.

func Run

func Run(ctx context.Context, config *Config) ([]*extractor.Inventory, []*plugin.Status, error)

Run runs the specified extractors and returns their extraction results, as well as info about whether the plugin runs completed successfully.

func RunFS

func RunFS(ctx context.Context, config *Config, wc *walkContext) ([]*extractor.Inventory, []*plugin.Status, error)

RunFS runs the specified extractors and returns their extraction results, as well as info about whether the plugin runs completed successfully. scanRoot is the location of fsys. This method is for testing, use Run() to avoid confusion with scanRoot vs fsys.

Types

type Config

type Config struct {
	Extractors []Extractor
	ScanRoots  []*scalibrfs.ScanRoot
	// Optional: Individual files to extract inventory from. If specified, the
	// extractors will only look at these files during the filesystem traversal.
	// Note that these are not relative to the ScanRoots and thus need to be
	// sub-directories of one of the ScanRoots.
	FilesToExtract []string
	// Optional: Directories that the file system walk should ignore.
	// Note that these are not relative to the ScanRoots and thus need to be
	// sub-directories of one of the ScanRoots.
	// TODO(b/279413691): Also skip local paths, e.g. "Skip all .git dirs"
	DirsToSkip []string
	// Optional: If the regex matches a directory, it will be skipped.
	SkipDirRegex *regexp.Regexp
	// Optional: stats allows to enter a metric hook. If left nil, no metrics will be recorded.
	Stats stats.Collector
	// Optional: Whether to read symlinks.
	ReadSymlinks bool
	// Optional: Limit for visited inodes. If 0, no limit is applied.
	MaxInodes int
	// Optional: By default, inventories stores a path relative to the scan root. If StoreAbsolutePath
	// is set, the absolute path is stored instead.
	StoreAbsolutePath bool
	// Optional: If true, print a detailed analysis of the duration of each extractor.
	PrintDurationAnalysis bool
}

Config stores the config settings for an extraction run.

type Extractor

type Extractor interface {
	extractor.Extractor
	// FileRequired should return true if the file described by path and file info is
	// relevant for the extractor.
	// Note that the plugin doesn't traverse the filesystem itself but relies on the core
	// library for that.
	FileRequired(path string, fileinfo fs.FileInfo) bool
	// Extract extracts inventory data relevant for the extractor from a given file.
	Extract(ctx context.Context, input *ScanInput) ([]*extractor.Inventory, error)
}

Extractor is the filesystem-based inventory extraction plugin, used to extract inventory data from the filesystem such as OS and language packages.

type ScanInput

type ScanInput struct {
	// FS for file access. This is rooted at Root.
	FS scalibrfs.FS
	// The path of the file to extract, relative to Root.
	Path string
	// The root directory where the extraction file walking started from.
	Root string
	Info fs.FileInfo
	// A reader for accessing contents of the file.
	// Note that the file is closed by the core library, not the plugin.
	Reader io.Reader
}

ScanInput describes one file to extract from.

Directories

Path Synopsis
containers
containerd
Package containerd extracts container inventory from containerd metadb database.
Package containerd extracts container inventory from containerd metadb database.
Package internal contains miscellaneous functions and objects useful within Scalibr
Package internal contains miscellaneous functions and objects useful within Scalibr
units
Package units provides constants for common units.
Package units provides constants for common units.
language
cpp/conanlock
Package conanlock extracts conan.lock files.
Package conanlock extracts conan.lock files.
dart/pubspec
Package pubspec extracts Dart pubspec.lock files.
Package pubspec extracts Dart pubspec.lock files.
dotnet/packageslockjson
Package packageslockjson extracts packages.lock.json files.
Package packageslockjson extracts packages.lock.json files.
erlang/mixlock
Package mixlock extracts erlang mix.lock files.
Package mixlock extracts erlang mix.lock files.
golang/gobinary
Package gobinary extracts packages from buildinfo inside go binaries files.
Package gobinary extracts packages from buildinfo inside go binaries files.
golang/gomod
Package gomod extracts go.mod files.
Package gomod extracts go.mod files.
java/archive
Package archive extracts Java archive files.
Package archive extracts Java archive files.
java/gradlelockfile
Package gradlelockfile extracts pom.xml files.
Package gradlelockfile extracts pom.xml files.
java/gradleverificationmetadataxml
Package gradleverificationmetadataxml extracts Gradle files.
Package gradleverificationmetadataxml extracts Gradle files.
java/groupid
Package groupid provides functionality for retrieving the group ID of a Java package.
Package groupid provides functionality for retrieving the group ID of a Java package.
java/javalockfile
Package javalockfile provides shared structures for Java extractors.
Package javalockfile provides shared structures for Java extractors.
java/pomxml
Package pomxml extracts pom.xml files.
Package pomxml extracts pom.xml files.
javascript/internal/commitextractor
Package commitextractor provides a function to extract commit hash from the full git URL
Package commitextractor provides a function to extract commit hash from the full git URL
javascript/packagejson
Package packagejson extracts package.json files.
Package packagejson extracts package.json files.
javascript/packagelockjson
Package packagelockjson extracts package-lock.json files.
Package packagelockjson extracts package-lock.json files.
javascript/pnpmlock
Package pnpmlock extracts pnpm-lock.yaml files.
Package pnpmlock extracts pnpm-lock.yaml files.
javascript/yarnlock
Package yarnlock extracts NPC yarn.lock files.
Package yarnlock extracts NPC yarn.lock files.
php/composerlock
Package composerlock extracts composer.lock files.
Package composerlock extracts composer.lock files.
python/internal/pypipurl
Package pypipurl converts an inventory to a PyPI type PackageURL.
Package pypipurl converts an inventory to a PyPI type PackageURL.
python/pdmlock
Package pdmlock extracts pdm.lock files.
Package pdmlock extracts pdm.lock files.
python/pipfilelock
Package pipfilelock extracts Pipfile.lock files.
Package pipfilelock extracts Pipfile.lock files.
python/poetrylock
Package poetrylock extracts poetry.lock files.
Package poetrylock extracts poetry.lock files.
python/requirements
Package requirements extracts requirements files.
Package requirements extracts requirements files.
python/wheelegg
Package wheelegg extracts wheel and egg files.
Package wheelegg extracts wheel and egg files.
r/renvlock
Package renvlock extracts renv.lock files.
Package renvlock extracts renv.lock files.
ruby/gemfilelock
Package gemfilelock extracts Gemfile.lock files.
Package gemfilelock extracts Gemfile.lock files.
ruby/gemspec
Package gemspec extracts *.gemspec files.
Package gemspec extracts *.gemspec files.
rust/cargolock
Package cargolock extracts Cargo.lock files for rust projects
Package cargolock extracts Cargo.lock files for rust projects
Package list provides a public list of SCALIBR-internal extraction plugins.
Package list provides a public list of SCALIBR-internal extraction plugins.
os
apk
Package apk extracts packages from the APK database.
Package apk extracts packages from the APK database.
cos
Package cos extracts OS packages from Container Optimized OSes (go/cos).
Package cos extracts OS packages from Container Optimized OSes (go/cos).
dpkg
Package dpkg extracts packages from dpkg database.
Package dpkg extracts packages from dpkg database.
flatpak
Package flatpak extracts packages from flatpak metainfo files.
Package flatpak extracts packages from flatpak metainfo files.
homebrew
Package homebrew extracts package information from OSX homebrew INSTALL_RECEIPT.json files.
Package homebrew extracts package information from OSX homebrew INSTALL_RECEIPT.json files.
osrelease
Package osrelease parses the os-release file.
Package osrelease parses the os-release file.
rpm
Package rpm extracts packages from rpm database.
Package rpm extracts packages from rpm database.
snap
Package snap extracts snap packages
Package snap extracts snap packages
Package osv provides a Wrapper for osv plugins.
Package osv provides a Wrapper for osv plugins.
sbom
cdx
Package cdx extracts software dependencies from an CycloneDX SBOM.
Package cdx extracts software dependencies from an CycloneDX SBOM.
spdx
Package spdx extracts software dependencies from an SPDX SBOM.
Package spdx extracts software dependencies from an SPDX SBOM.

Jump to

Keyboard shortcuts

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