Documentation ¶
Index ¶
- Constants
- Variables
- func SHA256Checksum(filename string) error
- func SHA256ChecksumValidate(filename, checksum string) error
- func SignFilestoreFile(ctx context.Context, srcPath, fileSHA256, tmpDir string, ...) error
- func SplitURLPath(httpURL string) (hostPart, pathPart string, err error)
- func UpdateFilesPath(deviceVendor, deviceModel, slug, filename string) string
- func VerifyFilestoreFile(ctx context.Context, filePath, fileSHA256, tmpDir string, ...) error
- func VerifyUpdateURL(ctx context.Context, updateURL, filename, fileSHA256, tmpDir string, ...) error
- type Downloader
- func (c *Downloader) CopyFilestoreToLocalTmp(ctx context.Context, tmpFilename, srcFilename string) error
- func (c *Downloader) CopyLocalTmpToFilestore(ctx context.Context, dstFilename, srcFilename string) error
- func (c *Downloader) CopyToFilestore(ctx context.Context, dstFilename, srcFilename string) error
- func (c *Downloader) CopyURLToLocalTmp(ctx context.Context, tmpFilename, srcURL string) error
- func (c *Downloader) DstURL() string
- func (c *Downloader) FilestoreRootDir() string
- func (c *Downloader) FilestoreURL() string
- func (c *Downloader) SrcName() string
- func (c *Downloader) SrcURL() string
- func (c *Downloader) Stats() *DownloaderStats
- type DownloaderStats
- type LocalFsConfig
- type Metrics
- type Provider
- type S3Downloader
- func (s *S3Downloader) CopyFile(ctx context.Context, fw *config.Firmware) error
- func (s *S3Downloader) DstBucket() string
- func (s *S3Downloader) DstPath(fw *config.Firmware) string
- func (s *S3Downloader) SrcBucket() string
- func (s *S3Downloader) SrcPath(fw *config.Firmware) string
- func (s *S3Downloader) VerifyFile(ctx context.Context, fw *config.Firmware) error
- type Signer
- type StoreConfig
Constants ¶
const ( KindLocal = "local" KindS3 = "s3" KindHTTP = "http" )
const ( MetricTransferredBytes = "TransferredBytes" MetricTransferredObjects = "TransferredObjects" MetricErrorsCount = "ErrorsCount" ActionSync = "sync" ActionSign = "sign" ActionVerify = "verify" )
const (
SigSuffix = ".sig"
)
const (
SumSuffix = ".SHA256"
)
Variables ¶
var ( ErrChecksumGenerate = errors.New("error generate file checksum") ErrChecksumValidate = errors.New("error validating file checksum") ErrChecksumInvalid = errors.New("file checksum does not match") )
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") )
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") )
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 ¶
SHA256FileChecksum calculates the sha256 checksum of the given filename and writes a filename.SHA256 file with its checksum value
func SHA256ChecksumValidate ¶
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 ¶
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
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 ¶
DownloaderStats includes fields for stats on file/object transfer for 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 ¶
AddInt64Value adds a given string key and int64 value
func (*Metrics) FromDownloader ¶
func (m *Metrics) FromDownloader(downloader *Downloader, deviceVendor, actionKind string)
FromDownloader collects metrics from the given downloader object
func (*Metrics) GetAllInt64Values ¶
GetAllInt64Values returns a map of metrics that are of type int64
type S3Downloader ¶ added in v0.0.5
type S3Downloader struct {
// contains filtered or unexported fields
}
func NewS3Downloader ¶ added in v0.0.5
func (*S3Downloader) CopyFile ¶ added in v0.0.5
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
type Signer ¶
type Signer struct {
// contains filtered or unexported fields
}
Signer exposes methods to sign and verify files
func NewSigner ¶
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.
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