vendors

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetricTransferredBytes   = "TransferredBytes"
	MetricTransferredObjects = "TransferredObjects"
	MetricErrorsCount        = "ErrorsCount"
	ActionSync               = "sync"
	ActionSign               = "sign"
	ActionVerify             = "verify"
)
View Source
const (
	SumSuffix = ".SHA256"
)

Variables

View Source
var (
	ErrChecksumGenerate = errors.New("error generate file checksum")
	ErrChecksumValidate = errors.New("error validating file checksum")
	ErrChecksumInvalid  = errors.New("file checksum does not match")
)
View Source
var (
	ErrDestPathUndefined  = errors.New("destination path is not specified")
	ErrCopy               = errors.New("error copying files")
	ErrSync               = errors.New("error syncing files")
	ErrInitS3Downloader   = errors.New("error intializing s3 downloader")
	ErrInitHTTPDownloader = errors.New("error initializing http downloader")
	ErrInitFSDownloader   = errors.New("error initializing filesystem downloader")

	ErrFileStoreConfig      = errors.New("filestore configuration invalid")
	ErrRootDirUndefined     = errors.New("expected a root directory path to mount")
	ErrInitS3Fs             = errors.New("error initializing s3 vfs")
	ErrUnsupportedFileStore = errors.New("unsupported file store")
	ErrSourceURL            = errors.New("invalid/unsupported source URL")
	ErrStoreConfig          = errors.New("error in/invalid FileStore configuration")
	ErrURLUnsupported       = errors.New("error URL scheme/format unsupported")

	ErrFileNotFound    = errors.New("file not found")
	ErrCheckFileExists = errors.New("error checking file exists")
	ErrListingFiles    = errors.New("error listing files in directory")
	ErrDirEmpty        = errors.New("directory empty")
	ErrModTimeFile     = errors.New("error retrieving file mod time")
	ErrCreatingTmpDir  = errors.New("error creating tmp dir")

	ErrUnexpectedStatusCode = errors.New("unexpected status code")
	ErrDownloadingFile      = errors.New("failed to download file")
)

Functions

func DownloadFirmwareArchive added in v0.0.10

func DownloadFirmwareArchive(ctx context.Context, tmpDir, archiveURL, archiveChecksum string) (string, error)

DownloadFirmwareArchive downloads a zip archive from archiveURL to tmpDir optionally checking the archive checksum

func DstPath added in v0.0.10

func ExtractFromZipArchive added in v0.0.10

func ExtractFromZipArchive(archivePath, firmwareFilename, firmwareChecksum string) (*os.File, error)

ExtractFromZipArchive extracts the given firmareFilename from zip archivePath and checks if MD5 checksum matches. nolint:gocyclo // see Test_ExtractFromZipArchive for examples of zip archives found in the wild.

func InitLocalFs added in v0.0.10

func InitLocalFs(ctx context.Context, cfg *LocalFsConfig) (rcloneFs.Fs, error)

InitLocalFs initializes and returns a rcloneFs.Fs interface on the local filesystem

func InitS3Fs added in v0.0.10

func InitS3Fs(ctx context.Context, cfg *config.S3Bucket, root string) (rcloneFs.Fs, error)

InitS3Fs initializes and returns a rcloneFs.Fs interface on an s3 store

root: the directory mounted as the root/top level directory of the returned fs

func SHA256Checksum

func SHA256Checksum(filename string) error

SHA256FileChecksum calculates the sha256 checksum of the given filename and writes a filename.SHA256 file with its checksum value

func SHA256ChecksumValidate

func SHA256ChecksumValidate(filename, checksum string) error

SHA256FileChecksumValidate verifies the sha256 checksum of the given filename

If a checksum parameter is provided, the method compares the file checksum with the one provided. If no checksum parameter was given, the method looks for 'filename.SHA256' to read the checksum to validate. when the checksum does not match the expected, an error is returned

func SetRcloneLogging added in v0.0.10

func SetRcloneLogging(logger *logrus.Logger)

func SplitURLPath

func SplitURLPath(httpURL string) (hostPart, pathPart string, err error)

SplitURLPath returns the URL host and Path parts while including the URL scheme, user info and fragments if any

func SrcPath added in v0.0.10

func ValidateChecksum added in v0.0.11

func ValidateChecksum(filename, checksum string) bool

ValidateChecksum validates the file checksum matches the given value. Defaults to md5 but allows for sha256 checks

Types

type ArchiveDownloader added in v0.0.18

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

func (*ArchiveDownloader) Download added in v0.0.18

func (m *ArchiveDownloader) Download(ctx context.Context, downloadDir string, firmware *serverservice.ComponentFirmwareVersion) (string, error)

Download will download the file for the given firmware into the given downloadDir, and return the full path to the downloaded file.

type Downloader

type Downloader interface {
	// Download takes in the directory to download the file to, and the firmware to be downloaded.
	// It should also return the full path to the downloaded file.
	Download(ctx context.Context, downloadDir string, firmware *serverservice.ComponentFirmwareVersion) (string, error)
}

Downloader is something that can download a file for a given firmware.

func NewArchiveDownloader added in v0.0.18

func NewArchiveDownloader(logger *logrus.Logger) Downloader

NewArchiveDownloader creates a new ArchiveDownloader.

func NewRcloneDownloader added in v0.0.18

func NewRcloneDownloader(logger *logrus.Logger) Downloader

NewRcloneDownloader creates a new RcloneDownloader.

func NewS3Downloader

func NewS3Downloader(logger *logrus.Logger, s3Fs rcloneFs.Fs) Downloader

NewS3Downloader creats a new S3Downloader.

func NewSourceOverrideDownloader added in v0.0.20

func NewSourceOverrideDownloader(logger *logrus.Logger, client serverservice.Doer, sourceURL string) Downloader

NewSourceOverrideDownloader creates a SourceOverrideDownloader.

type DownloaderStats

type DownloaderStats struct {
	BytesTransferred   int64
	ObjectsTransferred int64
	Errors             int64
}

DownloaderStats includes fields for stats on file/object transfer for Downloader

type LocalFsConfig

type LocalFsConfig struct {
	Root string
}

LocalFsConfig for the downloader

type Metrics

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

Metrics is a struct with a key value map under an RWMutex to collect file transfer metrics in a provider syncer context

func NewMetrics

func NewMetrics() *Metrics

func (*Metrics) AddInt64Value

func (m *Metrics) AddInt64Value(key string, value int64)

AddInt64Value adds a given string key and int64 value

func (*Metrics) Clear

func (m *Metrics) Clear()

Clear purges all existing key, values

func (*Metrics) GetAllInt64Values

func (m *Metrics) GetAllInt64Values() map[string]int64

GetAllInt64Values returns a map of metrics that are of type int64

type RcloneDownloader added in v0.0.18

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

func (*RcloneDownloader) Download added in v0.0.18

func (r *RcloneDownloader) Download(ctx context.Context, downloadDir string, firmware *serverservice.ComponentFirmwareVersion) (string, error)

Download will download the file for the given firmware into the given downloadDir, and return the full path to the downloaded file.

type S3Downloader

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

func (*S3Downloader) Download added in v0.0.18

func (s *S3Downloader) Download(ctx context.Context, downloadDir string, firmware *serverservice.ComponentFirmwareVersion) (string, error)

Download will download the file for the given firmware into the given downloadDir, and return the full path to the downloaded file.

type SourceOverrideDownloader added in v0.0.20

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

SourceOverrideDownloader is meant to download firmware from an alternate source than the firmware's UpstreamURL.

func (*SourceOverrideDownloader) Download added in v0.0.20

Download will download the given firmware into the given downloadDir, and return the full path to the downloaded file. The file will be downloaded from the sourceURL provided to the SourceOverrideDownloader instead of the firmware's UpstreamURL.

type Syncer added in v0.0.18

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

func (*Syncer) Sync added in v0.0.18

func (s *Syncer) Sync(ctx context.Context) (err error)

Sync will synchronize the firmwares with the destination file system and inventory. Files that do not exist on the destination will be downloaded from their source and uploaded to the destination. Information about the firmware file will be updated using the inventory client.

type Vendor

type Vendor interface {
	Sync(ctx context.Context) error
}

func NewSyncer added in v0.0.18

func NewSyncer(
	dstFs fs.Fs,
	tmpFs fs.Fs,
	downloader Downloader,
	inventoryClient inventory.ServerService,
	firmwares []*serverservice.ComponentFirmwareVersion,
	logger *logrus.Logger,
) Vendor

NewSyncer creates a new Syncer.

Directories

Path Synopsis
Code generated by MockGen.
Code generated by MockGen.

Jump to

Keyboard shortcuts

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