config

package
v3.2.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2017 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package config store all necessary configuration parameters for the project.

Index

Constants

This section is empty.

Variables

View Source
var Version = "development"

Version stores the release version of the tool. It is replaced in build time with ldflags argument:

go build -ldflags "-X github.com/rafaeljusto/toglacier/internal/config.Version=beta"

Functions

func Default

func Default()

Default defines all default configuration values.

func ErrorEqual

func ErrorEqual(first, second error) bool

ErrorEqual compares two Error objects. This is useful to compare down to the low level errors.

func LoadFromEnvironment

func LoadFromEnvironment() error

LoadFromEnvironment analysis all project environment variables. On error it will return an Error type encapsulated in a traceable error. To retrieve the desired error you can do:

type causer interface {
  Cause() error
}

if causeErr, ok := err.(causer); ok {
  switch specificErr := causeErr.Cause().(type) {
  case *config.Error:
    // handle specifically
  default:
    // unknown error
  }
}

func LoadFromFile

func LoadFromFile(filename string) error

LoadFromFile parse an YAML file and fill the system configuration parameters. On error it will return an Error type encapsulated in a traceable error. To retrieve the desired error you can do:

type causer interface {
  Cause() error
}

if causeErr, ok := err.(causer); ok {
  switch specificErr := causeErr.Cause().(type) {
  case *config.Error:
    // handle specifically
  default:
    // unknown error
  }
}

func PasswordEncrypt

func PasswordEncrypt(input string) (string, error)

PasswordEncrypt uses the secret to encode the password. On error it will return an Error type encapsulated in a traceable error. To retrieve the desired error you can do:

type causer interface {
  Cause() error
}

if causeErr, ok := err.(causer); ok {
  switch specificErr := causeErr.Cause().(type) {
  case *config.Error:
    // handle specifically
  default:
    // unknown error
  }
}

func Update

func Update(c *Config)

Update modify the current system configuration.

Types

type Config

type Config struct {
	Paths           []string   `yaml:"paths"`
	KeepBackups     int        `yaml:"keep backups" split_words:"true"`
	BackupSecret    aesKey     `yaml:"backup secret" split_words:"true"`
	ModifyTolerance Percentage `yaml:"modify tolerance" split_words:"true"`
	IgnorePatterns  []Pattern  `yaml:"ignore patterns" split_words:"true"`

	Scheduler struct {
		Backup            Scheduler `yaml:"backup"`
		RemoveOldBackups  Scheduler `yaml:"remove old backups" split_words:"true"`
		ListRemoteBackups Scheduler `yaml:"list remote backups" split_words:"true"`
		SendReport        Scheduler `yaml:"send report" split_words:"true"`
	} `yaml:"scheduler" envconfig:"scheduler"`

	Database struct {
		Type DatabaseType `yaml:"type"`
		File string       `yaml:"file"`
	} `yaml:"database" envconfig:"db"`

	Log struct {
		File  string   `yaml:"file"`
		Level LogLevel `yaml:"level"`
	} `yaml:"log" envconfig:"log"`

	Email struct {
		Server   string      `yaml:"server"`
		Port     int         `yaml:"port"`
		Username string      `yaml:"username"`
		Password encrypted   `yaml:"password"`
		From     string      `yaml:"from"`
		To       []string    `yaml:"to"`
		Format   EmailFormat `yaml:"format"`
	} `yaml:"email" envconfig:"email"`

	AWS struct {
		AccountID       encrypted `yaml:"account id" split_words:"true"`
		AccessKeyID     encrypted `yaml:"access key id" split_words:"true"`
		SecretAccessKey encrypted `yaml:"secret access key" split_words:"true"`
		Region          string    `yaml:"region"`
		VaultName       string    `yaml:"vault name" split_words:"true"`
	} `yaml:"aws" envconfig:"aws"`
}

Config stores all the necessary information to send backups to the cloud and keep track in the local storage.

func Current

func Current() *Config

Current return the actual system configuration, stored internally in a global variable.

type DatabaseType

type DatabaseType string

DatabaseType determinate what type of strategy will be used to store the local backups information.

const (
	// DatabaseTypeAuditFile use a human readable file, that stores one backup
	// information per line. As the structure is simple, this database format will
	// have less features than other types.
	DatabaseTypeAuditFile DatabaseType = "audit-file"

	// DatabaseTypeBoltDB use a fast key/value storage that stores all binary
	// content in only one file. For more information please check
	// https://github.com/boltdb/bolt
	DatabaseTypeBoltDB DatabaseType = "boltdb"
)

func (*DatabaseType) UnmarshalText

func (d *DatabaseType) UnmarshalText(value []byte) error

UnmarshalText ensure that the database type defined in the configuration is valid.

type EmailFormat

type EmailFormat string

EmailFormat defines the desired content format to be used in report e-mails. By default "html" is used.

const (
	// EmailFormatPlain ascii only content for e-mail clients that accept only
	// simple text.
	EmailFormatPlain EmailFormat = "plain"

	// EmailFormatHTML better structured content that requires HTML support by the
	// e-mail client.
	EmailFormatHTML EmailFormat = "html"
)

func (*EmailFormat) UnmarshalText

func (e *EmailFormat) UnmarshalText(value []byte) error

UnmarshalText ensure that the email format defined in the configuration is valid.

type Error

type Error struct {
	Filename string
	Code     ErrorCode
	Err      error
}

Error stores error details from a problem occurred while reading a configuration file or parsing the environment variables.

func (Error) Error

func (e Error) Error() string

Error returns the error in a human readable format.

func (Error) String

func (e Error) String() string

String translate the error to a human readable text.

type ErrorCode

type ErrorCode string

ErrorCode stores the error type that occurred while reading configuration parameters.

const (
	// ErrorCodeReadingFile error while reading the configuration file.
	ErrorCodeReadingFile ErrorCode = "reading-file"

	// ErrorCodeParsingYAML error while parsing the configuration file as YAML.
	ErrorCodeParsingYAML ErrorCode = "parsing-yaml"

	// ErrorCodeReadingEnvVars error while reading configuration values from
	// environment variables.
	ErrorCodeReadingEnvVars ErrorCode = "reading-env-vars"

	// ErrorCodeInitCipher error while initializing the engine used to encrypt or
	// decrypt the value.
	ErrorCodeInitCipher ErrorCode = "init-cipher"

	// ErrorCodeDecodeBase64 problem while decoding a base64 content.
	ErrorCodeDecodeBase64 ErrorCode = "decode-base64"

	// ErrorCodePasswordSize invalid password size. The password is smaller than
	// the cipher block size.
	ErrorCodePasswordSize ErrorCode = "password-size"

	// ErrorCodeFillingIV error while filling the IV array with random bytes.
	ErrorCodeFillingIV ErrorCode = "filling-iv"

	// ErrorCodeDatabaseType informed database type is unknown, it should be
	// "audit-file" or "boltdb".
	ErrorCodeDatabaseType ErrorCode = "database-type"

	// ErrorCodeLogLevel informed log level is unknown, it should be "debug",
	// "info", "warning", "error", "fatal" or "panic".
	ErrorCodeLogLevel ErrorCode = "log-level"

	// ErrorCodeEmailFormat informed email format is unknown, it should be "plain"
	// or "html".
	ErrorCodeEmailFormat ErrorCode = "email-format"

	// ErrorCodePercentageFormat invalid percentage format.
	ErrorCodePercentageFormat ErrorCode = "percentage-format"

	// ErrorCodePercentageRange percentage must be between 0 and 100.
	ErrorCodePercentageRange ErrorCode = "percentage-range"

	// ErrorCodePattern invalid pattern detected when parsing the regular
	// expression.
	ErrorCodePattern ErrorCode = "pattern"

	// ErrorCodeSchedulerFormat the number of items of the schedule is wrong, we
	// expect 6 space-separated items.
	ErrorCodeSchedulerFormat ErrorCode = "scheduler-format"

	// ErrorCodeSchedulerValue one or more values of the scheduler is invalid.
	// Could be an invalid syntax or range.
	ErrorCodeSchedulerValue ErrorCode = "scheduler-value"
)

func (ErrorCode) String

func (e ErrorCode) String() string

String translate the error code to a human readable text.

type LogLevel

type LogLevel string

LogLevel determinate the verbosity of the log entries.

const (
	// LogLevelDebug usually only enabled when debugging. Very verbose logging.
	LogLevelDebug LogLevel = "debug"

	// LogLevelInfo general operational entries about what's going on inside the
	// application.
	LogLevelInfo LogLevel = "info"

	// LogLevelWarning non-critical entries that deserve eyes.
	LogLevelWarning LogLevel = "warning"

	// LogLevelError used for errors that should definitely be noted.
	LogLevelError LogLevel = "error"

	// LogLevelFatal it will terminates the process after the the entry is logged.
	LogLevelFatal LogLevel = "fatal"

	// LogLevelPanic highest level of severity. Logs and then calls panic with the
	// message passed to Debug, Info, ...
	LogLevelPanic LogLevel = "panic"
)

func (*LogLevel) UnmarshalText

func (l *LogLevel) UnmarshalText(value []byte) error

UnmarshalText ensure that the log level defined in the configuration is valid.

type Pattern

type Pattern struct {
	Value *regexp.Regexp
}

Pattern stores a valid regular expression.

func (*Pattern) UnmarshalText

func (p *Pattern) UnmarshalText(value []byte) error

UnmarshalText compile the pattern checking for expression errors.

type Percentage

type Percentage float64

Percentage stores a valid percentage value.

func (*Percentage) UnmarshalText

func (p *Percentage) UnmarshalText(value []byte) error

UnmarshalText verifies if a percentage is a valid number.

type Scheduler

type Scheduler struct {
	Value cron.Schedule
}

Scheduler stores the periodicity of an action.

func (*Scheduler) UnmarshalText

func (s *Scheduler) UnmarshalText(value []byte) error

UnmarshalText verifies the cron format of the scheduler entry. For details about the expected format please check http://godoc.org/github.com/robfig/cron#hdr-CRON_Expression_Format

Jump to

Keyboard shortcuts

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