providers

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KindLocal = "local"
	KindS3    = "s3"
	KindHTTP  = "http"
)
View Source
const (
	MetricTransferredBytes   = "TransferredBytes"
	MetricTransferredObjects = "TransferredObjects"
	MetricErrorsCount        = "ErrorsCount"
	ActionSync               = "sync"
	ActionSign               = "sign"
	ActionVerify             = "verify"
)
View Source
const (
	SigSuffix = ".sig"
)
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")
)
View Source
var (
	ErrRemoteSignFail   = errors.New("error in generating checksum and signature for remote file")
	ErrDownloadSign     = errors.New("error downloading files to sign")
	ErrUploadSigned     = errors.New("error uploading signed file(s)")
	ErrDownloadVerify   = errors.New("error downloading files to verify")
	ErrRemoteVerifyFail = errors.New("error in verifying signature for remote repofiles")
)
View Source
var (
	ErrSignerKeyFile    = errors.New("open key file error")
	ErrSignerPubKey     = errors.New("signer requires a public key parameter")
	ErrSignerPrivateKey = errors.New("signer requires a private key parameter")
	ErrSignerSign       = errors.New("error signing file")
	ErrSignerVerify     = errors.New("error verifying file signature")
)

Functions

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 SignFilestoreFile

func SignFilestoreFile(ctx context.Context, srcPath, fileSHA256, tmpDir string, downloader *Downloader, signer *Signer, logger *logrus.Logger) error

SignFileStoreFile signs a file present in the filestore srcPath: is the full path to the file in the filestore

nolint:gocyclo // TODO: figure if this method can be split up

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 UpdateFilesPath added in v0.0.5

func UpdateFilesPath(deviceVendor, deviceModel, slug, filename string) string

UpdateFilesPath returns the directory, file path destination for the update based on the device vendor, model, component slug attributes

This filepath structure is used to store and retrieve firmware

func VerifyFilestoreFile

func VerifyFilestoreFile(ctx context.Context, filePath, fileSHA256, tmpDir string, downloader *Downloader, signer *Signer, logger *logrus.Logger) error

verifyFilestoreFile downloads repofiles files locally to verify their signature

expects a downloader initialized with tmpDir directory as the base directory returns nil if verify was successful

func VerifyUpdateURL

func VerifyUpdateURL(ctx context.Context, updateURL, filename, fileSHA256, tmpDir string, downloader *Downloader, signer *Signer, logger *logrus.Logger) error

VerifyUpdateURL verifies the checksum, signature of the file linked in the UpdateURL parameter

returns nil if verify was successful

Types

type Downloader

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

Downloader wraps src and dst rclone Fs interface types to enable copying objects

func NewDownloader

func NewDownloader(ctx context.Context, srcURL string, storeCfg *StoreConfig) (*Downloader, error)

NewDownloader initializes a downloader object based on the srcURL and the given StoreConfig

func (*Downloader) CopyFilestoreToLocalTmp

func (c *Downloader) CopyFilestoreToLocalTmp(ctx context.Context, tmpFilename, srcFilename string) error

CopyFilestoreToLocalTmp copies files from the downloader.dst fs into the local tmp directory

func (*Downloader) CopyLocalTmpToFilestore

func (c *Downloader) CopyLocalTmpToFilestore(ctx context.Context, dstFilename, srcFilename string) error

CopyLocalTmpToFilestore copies files from the local tmp directory to the downloader.dst fs

func (*Downloader) CopyToFilestore

func (c *Downloader) CopyToFilestore(ctx context.Context, dstFilename, srcFilename string) error

CopyFile copies srcFile frm the src fs to dstFile in the filestore fs

srcFile: this is expected to be a relative path to the directory used as a mount point in the init*Fs methods

func (*Downloader) CopyURLToLocalTmp

func (c *Downloader) CopyURLToLocalTmp(ctx context.Context, tmpFilename, srcURL string) error

CopyURLToLocalTmp copies files from the srcURL to the local tmp directory

func (*Downloader) DstURL

func (c *Downloader) DstURL() string

DstURL returns the destination URL configured when initializing the downloader

func (*Downloader) FilestoreRootDir

func (c *Downloader) FilestoreRootDir() string

func (*Downloader) FilestoreURL

func (c *Downloader) FilestoreURL() string

StoreURL the file store URL configured for the downloader

func (*Downloader) SrcName

func (c *Downloader) SrcName() string

SrcName returns the name of the source fs - set in the init*Fs methods

func (*Downloader) SrcURL

func (c *Downloader) SrcURL() string

SrcURL returns the destination URL configured when initializing the downloader

func (*Downloader) Stats

func (c *Downloader) Stats() *DownloaderStats

Stats returns bytes, file transfer stats on the downloader

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

func (m *Metrics) FromDownloader(downloader *Downloader, deviceVendor, actionKind string)

FromDownloader collects metrics from the given downloader object

func (*Metrics) GetAllInt64Values

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

GetAllInt64Values returns a map of metrics that are of type int64

type Provider

type Provider interface {
	Sync(ctx context.Context) error
	Verify(ctx context.Context) error
	Stats() *Metrics
}

type S3Downloader added in v0.0.5

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

func NewS3Downloader added in v0.0.5

func NewS3Downloader(ctx context.Context, vendor string, srcCfg, dstCfg *config.S3Bucket, logLevel logrus.Level) (*S3Downloader, error)

func (*S3Downloader) CopyFile added in v0.0.5

func (s *S3Downloader) CopyFile(ctx context.Context, fw *config.Firmware) error

CopyFile wraps rclone CopyFile to copy firmware file from src to dst

func (*S3Downloader) DstBucket added in v0.0.5

func (s *S3Downloader) DstBucket() string

func (*S3Downloader) DstPath added in v0.0.5

func (s *S3Downloader) DstPath(fw *config.Firmware) string

func (*S3Downloader) SrcBucket added in v0.0.5

func (s *S3Downloader) SrcBucket() string

func (*S3Downloader) SrcPath added in v0.0.5

func (s *S3Downloader) SrcPath(fw *config.Firmware) string

func (*S3Downloader) VerifyFile added in v0.0.5

func (s *S3Downloader) VerifyFile(ctx context.Context, fw *config.Firmware) error

type Signer

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

Signer exposes methods to sign and verify files

func NewSigner

func NewSigner(privateKeyFile, publicKeyfile string) (*Signer, error)

NewSigner returns a Signer object to sign and verify files

A signer always requires the public key, the private key is optional since its required only to sign files.

func (*Signer) Sign

func (s *Signer) Sign(targetFile, sigFile string) error

Sign signs the targetFile and stores the signature in the sigFile

sigFile is optional and defaults to targetFile.sig

func (*Signer) Verify

func (s *Signer) Verify(targetFile, sigFile string) error

Verify verifies signature on the targetFile

sigFile is optional and defaults to targetFile.sig

type StoreConfig

type StoreConfig struct {
	// URL points to the destination file store, the filestore is initialized based on the url scheme
	// examples:
	//   s3://<bucket-name>/<root>
	//   local:///tmp/foo
	URL string
	// Path to mount as the tmp directory when downloading files to sign and verify
	Tmp string
	// S3 configuration - required when URL points to an s3 bucket
	S3 *config.S3Bucket
	// Local filesystem configuration - required when URL points to a local directory
	Local *LocalFsConfig
	// Path to root of the fs
	Root string
}

StoreConfig holds attributes for the filestore where files are downloaded

func FilestoreConfig

func FilestoreConfig(rootDir string, cfg *config.Filestore) (*StoreConfig, error)

FilestoreConfig accepts a srcURL and config.Filestore to return a StoreConfig that can be passed to init a downloader

This method sets up the StoreConfig.URL based on the filestore configuration included nolint:gocyclo // validation is cyclomatic

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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