common

package
v0.3.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ErrFileNotFound     = "file not found"
	ErrAccessDenied     = "access denied"
	ErrInvalidConfig    = "invalid backend configuration"
	ErrOperationTimeout = "operation timeout"
)

Common error definitions.

Variables

View Source
var CreateDummyBackend func(cfg *Config) StorageBackend = nil

CreateDummyBackend function that returns a pre-initialized DummyBackend.

Functions

This section is empty.

Types

type B2Backend

type B2Backend struct {
	s3iface.S3API
	// contains filtered or unexported fields
}

B2Backend is struct that holds active B2 session.

func CreateB2Backend

func CreateB2Backend(cfg *Config) *B2Backend

CreateB2Backend is the B2Backend factory function.

func (*B2Backend) GetFileInfo

func (b2 *B2Backend) GetFileInfo(uri *url.URL) (*FileInfo, error)

GetFileInfo returns a FileInfo struct filled with information about object defined by the input URI. Input URI must follow the pattern: b2://bucket/path/to/key.

func (*B2Backend) GetProgressEnabled added in v0.3.0

func (b2 *B2Backend) GetProgressEnabled() bool

GetProgressEnabled return true if progress output is enabled.

func (*B2Backend) GetProgressbarOptions added in v0.3.0

func (b2 *B2Backend) GetProgressbarOptions() []progressbar.Option

GetProgressbarOptions returns progressbar options as a list.

func (*B2Backend) ListFiles

func (b2 *B2Backend) ListFiles(uri *url.URL) ([]FileInfo, error)

ListFiles return an array of FileInfo structs filled with information about objects defined by the input URI. Input URI must follow the pattern: b2://bucket/path/to/prefix.

func (*B2Backend) RemoveFile added in v0.2.0

func (b2 *B2Backend) RemoveFile(uri *url.URL) error

RemoveFile removes an object under the given URI. Object URI must follow the pattern: b2://bucket/path/to/key.

func (*B2Backend) SetProgressEnabled added in v0.3.0

func (b2 *B2Backend) SetProgressEnabled(e bool)

SetProgressEnabled enable/disable progress output.

func (*B2Backend) SetProgressbarOptions added in v0.3.0

func (b2 *B2Backend) SetProgressbarOptions(options ...progressbar.Option)

SetProgressbarOptions sets progressbar options (see progressbar docs).

func (*B2Backend) StoreFile

func (b2 *B2Backend) StoreFile(inputStream io.ReaderAt, contentLength int64, uri *url.URL) error

StoreFile writes data from `input` to output URI. Output URI must follow the pattern: b2://bucket/path/to/key.

type Config

type Config struct {
	S3 struct {
		Region string `yaml:"region" env:"SQUIRRELUP_S3_REGION,overwrite" default:""`
		ID     string `yaml:"id" env:"SQUIRRELUP_S3_ID,overwrite" default:""`
		Secret string `yaml:"secret" env:"SQUIRRELUP_S3_SECRET,overwrite" default:""`
		Token  string `yaml:"token" env:"SQUIRRELUP_S3_TOKEN,overwrite" default:""`
	} `yaml:"s3"`
	Encryption struct {
		Pubkey string `yaml:"pubkey" env:"SQUIRRELUP_PUBKEY,overwrite" default:""`
	} `yaml:"encryption"`
	Backup struct {
		Hours float64 `yaml:"hours" env:"SQUIRRELUP_BACKUP_HOURS,overwrite" default:"240"`
		Name  string  `yaml:"name" env:"SQUIRRELUP_BACKUP_FILENAME,overwrite" default:"2006-01-02T15-0700"`
	} `yaml:"backup"`
}

Config struct contains configurations for SQUIRRELUP. Currently it contains two sections:

  • S3 configuration
  • Encryption configuration
  • Backup configuration

func (*Config) LoadConfigFromEnv added in v0.2.0

func (cfg *Config) LoadConfigFromEnv() error

LoadConfigFromEnv loads configuration into a `Config` struct from environment variables.

func (*Config) LoadConfigFromFile added in v0.2.0

func (cfg *Config) LoadConfigFromFile(file io.Reader) error

LoadConfigFromFile loads configuration into a `Config` struct from YAML file.

func (*Config) SetDefaultValues added in v0.2.0

func (cfg *Config) SetDefaultValues() error

SetDefaultValues reset Config fields to default values. An implementation handling a generic struct:

func setDefaultValues() error {
	if reflect.TypeOf(ptr).Kind() != reflect.Ptr {
		return fmt.Errorf("Not a pointer")
	}
	valueof := reflect.ValueOf(ptr).Elem()
	if ! valueof.IsValid() {
		return fmt.Errorf("setDefaultValues called on a nil pointer")
	}
	fmt.Printf("setDefaultValues: kind = %v\n", valueof.Kind())
	if valueof.Kind() == reflect.Struct {
		if err := setDefaultValuesStruct(valueof); err != nil {
			// fmt.Printf("setDefaultValues: err = %v\n", err)
			return err
		}
		return nil
	}
	return fmt.Errorf("setDefaultValues called with unsupported value of kind '%v'", valueof.Kind())
}

type DummyBackend

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

DummyBackend defines a dummy backend.

func (*DummyBackend) GenerateDummyFiles added in v0.3.0

func (d *DummyBackend) GenerateDummyFiles(path string, number uint64)

GenerateDummyFiles generate dummy file info list.

func (*DummyBackend) GetDummyError added in v0.3.0

func (d *DummyBackend) GetDummyError() error

GetDummyError get dummy error.

func (*DummyBackend) GetDummyFiles added in v0.3.0

func (d *DummyBackend) GetDummyFiles() []FileInfo

GetDummyFiles get dummy file info list.

func (*DummyBackend) GetFileInfo

func (d *DummyBackend) GetFileInfo(uri *url.URL) (*FileInfo, error)

GetFileInfo returns a FileInfo struct filled with information about object defined by the input URI. Input URI must follow the pattern: dummy://path/to/file.

func (*DummyBackend) ListFiles

func (d *DummyBackend) ListFiles(uri *url.URL) ([]FileInfo, error)

ListFiles return an array of FileInfo structs filled with information about objects defined by the input URI. Input URI must follow the pattern: dummy://path/to/dir.

func (*DummyBackend) RemoveFile added in v0.2.0

func (d *DummyBackend) RemoveFile(uri *url.URL) error

RemoveFile remove objects defined by the input URI. Input URI must follow the pattern: dummy://path/to/dir.

func (*DummyBackend) SetDummyError added in v0.3.0

func (d *DummyBackend) SetDummyError(err error)

SetDummyError set dummy error.

func (*DummyBackend) StoreFile

func (d *DummyBackend) StoreFile(input io.ReaderAt, length int64, uri *url.URL) error

StoreFile writes a data from `input` to output URI. Output URI must follow the pattern: dummy://path/to/file.

type FileInfo

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

FileInfo contains file information.

func (*FileInfo) IsFile added in v0.3.0

func (fi *FileInfo) IsFile() bool

Modified returns last modified date of the file object.

func (*FileInfo) Modified added in v0.2.0

func (fi *FileInfo) Modified() time.Time

Modified returns last modified date of the file object.

func (*FileInfo) Name added in v0.2.0

func (fi *FileInfo) Name() string

Name returns name of the file object.

func (*FileInfo) Size added in v0.2.0

func (fi *FileInfo) Size() uint64

Size returns size of the file object.

type ProgressReporterFacade added in v0.3.0

type ProgressReporterFacade interface {
	GetProgressEnabled() bool
	SetProgressEnabled(bool)
	GetProgressbarOptions() []progressbar.Option
	SetProgressbarOptions(options ...progressbar.Option)
}

ProgressReporterFacade is a generic interface to setting up progress reporting: enable and disable progress reporting and set progressbar settings.

type StorageBackend

type StorageBackend interface {
	GetFileInfo(uri *url.URL) (*FileInfo, error)
	ListFiles(*url.URL) ([]FileInfo, error)
	StoreFile(io.ReaderAt, int64, *url.URL) error
	RemoveFile(*url.URL) error
}

StorageBackend is a generic interface to storage backends. Currently, it provisions following methods:

  • GetFileInfo to get file information in FileInfo struct.
  • ListFiles to list files under a given URI.
  • StoreFile to store data to a given URI.
  • RemoveFile to remove files under a given URI.

func CreateStorageBackend

func CreateStorageBackend(uri *url.URL, cfg *Config) (StorageBackend, error)

CreateStorageBackend is a StorageBackend factory function.

Jump to

Keyboard shortcuts

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