provider

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2023 License: LGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrProviderUnavailable is a generic error when a provider is not available
	ErrProviderUnavailable = errors.New("provider not available")
	// ErrFileNotFound is a generic error when a file is not found
	ErrFileNotFound = errors.New("file not found")

	// ErrNotOpenned is a generic error when a provider have been called while it is not openned
	ErrNotOpenned = errors.New("provider have not been openned")
)

Functions

func GetLatestVersionFromPath

func GetLatestVersionFromPath(path string) (string, error)

GetLatestVersionFromPath finds the latest version from a path This is used by provider zip and gzip Example: /example/binaries-v1.4.53.zip is going to match "v1.4.53"

func GlobNewestFile

func GlobNewestFile(pattern string) (string, error)

GlobNewestFile same as filepath.Glob but returns only one file with the latest modification time

Types

type AccessProvider

type AccessProvider interface {
	GetLatestVersion() (string, error) // Get the latest version (Should be accessible even if Open() was not called)
	Walk(walkFn WalkFunc) error
	Retrieve(srcPath string, destPath string) error
}

AccessProvider describes the access methods of a Provider This methods shouldn't change the state of the provider

type BitBucket

type BitBucket struct {
	RepositoryURL string // The URL of the BitBucket repository, e.g. bitbucket.org/BenTomsett/go-rocket-update-example
	ArchiveName   string // The name of the archive file uploaded to BitBucket Downloads, e.g. project-v0.0.1.tar.gz
	// contains filtered or unexported fields
}

BitBucket provider finds an archive file in the repository's downloads to provide updated binaries As BitBucket does not have a releases feature, we use the downloads feature instead.

func (*BitBucket) Close

func (c *BitBucket) Close() error

func (*BitBucket) GetLatestVersion

func (c *BitBucket) GetLatestVersion() (string, error)

func (*BitBucket) Open

func (c *BitBucket) Open() (err error)

func (*BitBucket) Retrieve

func (c *BitBucket) Retrieve(src string, dest string) error

func (*BitBucket) Walk

func (c *BitBucket) Walk(walkFn WalkFunc) error

type FileInfo

type FileInfo struct {
	Path string
	Mode os.FileMode
}

A FileInfo describes a file given by a provider

type Github

type Github struct {
	RepositoryURL string // Repository URL, example github.com/mouuff/go-rocket-update
	ArchiveName   string // Archive name (the zip/tar.gz you upload for a release on github), example: binaries.zip
	// contains filtered or unexported fields
}

Github provider finds a archive file in the repository's releases to provide files

func (*Github) Close

func (c *Github) Close() error

Close closes the provider

func (*Github) GetLatestVersion

func (c *Github) GetLatestVersion() (string, error)

GetLatestVersion gets the latest version

func (*Github) Open

func (c *Github) Open() (err error)

Open opens the provider

func (*Github) Retrieve

func (c *Github) Retrieve(src string, dest string) error

Retrieve file relative to "provider" to destination

func (*Github) Walk

func (c *Github) Walk(walkFn WalkFunc) error

Walk walks all the files provided

type Gitlab

type Gitlab struct {
	ProjectID   int
	ArchiveName string // ArchiveName (the archive you upload for a release on gitlab), example: binaries.zip
	// contains filtered or unexported fields
}

Gitlab provider finds a archive file in the repository's releases to provide files

func (*Gitlab) Close

func (c *Gitlab) Close() error

Close closes the provider

func (*Gitlab) GetLatestVersion

func (c *Gitlab) GetLatestVersion() (string, error)

GetLatestVersion gets the latest version

func (*Gitlab) Open

func (c *Gitlab) Open() (err error)

Open opens the provider

func (*Gitlab) Retrieve

func (c *Gitlab) Retrieve(src string, dest string) error

Retrieve file relative to "provider" to destination

func (*Gitlab) Walk

func (c *Gitlab) Walk(walkFn WalkFunc) error

Walk walks all the files provided

type Gzip

type Gzip struct {
	Path string // Path of the Gzip file (provider.GlobNewestFile might help)
	// contains filtered or unexported fields
}

Gzip provider

func (*Gzip) Close

func (c *Gzip) Close() (err error)

Close closes the provider

func (*Gzip) GetLatestVersion

func (c *Gzip) GetLatestVersion() (string, error)

GetLatestVersion gets the latest version

func (*Gzip) Open

func (c *Gzip) Open() (err error)

Open opens the provider

func (*Gzip) Retrieve

func (c *Gzip) Retrieve(src string, dest string) error

Retrieve file relative to "provider" to destination

func (*Gzip) Walk

func (c *Gzip) Walk(walkFn WalkFunc) error

Walk walks all the files provided

type Local

type Local struct {
	Path string // Path of the folder
	// contains filtered or unexported fields
}

A Local provider use a local directory to provide files This provider is mainly here for mocking and testing but it could be used on a shared network folder

func (*Local) Close

func (c *Local) Close() error

Close closes the provider

func (*Local) GetLatestVersion

func (c *Local) GetLatestVersion() (string, error)

GetLatestVersion gets the latest version

func (*Local) Open

func (c *Local) Open() error

Open opens the provider

func (*Local) Retrieve

func (c *Local) Retrieve(src string, dest string) error

Retrieve file relative to "provider" to destination

func (*Local) Walk

func (c *Local) Walk(walkFn WalkFunc) error

Walk walks all the files provided

type Provider

type Provider interface {
	AccessProvider
	Open() error
	Close() error
}

A Provider describes an interface for providing files

func Decompress

func Decompress(path string) (Provider, error)

Decompress gets a provider to decompress zip or tar.gz files

type Secure

type Secure struct {
	BackendProvider Provider
	PublicKeyPEM    []byte
	PublicKey       *rsa.PublicKey
	// contains filtered or unexported fields
}

Secure is a provider which uses another provider and verifies the signatures when Retrieve() is called If you pass a nil PublicKey, then it will try to load the PublicKeyPEM. PublicKeyPEM must be a public key in the PEM format

func (*Secure) Close

func (c *Secure) Close() error

Close the provider

func (*Secure) GetLatestVersion

func (c *Secure) GetLatestVersion() (string, error)

GetLatestVersion gets the latest version

func (*Secure) Open

func (c *Secure) Open() (err error)

Open the provider

func (*Secure) Retrieve

func (c *Secure) Retrieve(src string, dest string) error

Retrieve file and verifies the signature

func (*Secure) Walk

func (c *Secure) Walk(walkFn WalkFunc) error

Walk all the files provided

type WalkFunc

type WalkFunc func(info *FileInfo) error

WalkFunc is the type of the function called for each file or directory visited by Walk. path is relative

type Zip

type Zip struct {
	Path string // Path of the zip file (provider.GlobNewestFile might help)
	// contains filtered or unexported fields
}

Zip provider

func (*Zip) Close

func (c *Zip) Close() error

Close closes the provider

func (*Zip) GetLatestVersion

func (c *Zip) GetLatestVersion() (string, error)

GetLatestVersion gets the latest version

func (*Zip) Open

func (c *Zip) Open() error

Open opens the provider

func (*Zip) Retrieve

func (c *Zip) Retrieve(src string, dest string) error

Retrieve file relative to "provider" to destination

func (*Zip) Walk

func (c *Zip) Walk(walkFn WalkFunc) error

Walk walks all the files provided

Jump to

Keyboard shortcuts

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