Documentation
¶
Overview ¶
Package config store all necessary configuration parameters for the project.
Index ¶
- Variables
- func Default()
- func ErrorEqual(first, second error) bool
- func LoadFromEnvironment() error
- func LoadFromFile(filename string) error
- func PasswordEncrypt(input string) (string, error)
- func Update(c *Config)
- type Config
- type DatabaseType
- type EmailFormat
- type Error
- type ErrorCode
- type LogLevel
- type Pattern
- type Percentage
- type Scheduler
Constants ¶
This section is empty.
Variables ¶
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 ErrorEqual ¶
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 ¶
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 ¶
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 } }
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.
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 ¶ added in v3.1.0
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 ¶ added in v3.1.0
func (e *EmailFormat) UnmarshalText(value []byte) error
UnmarshalText ensure that the email format defined in the configuration is valid.
type Error ¶
Error stores error details from a problem occurred while reading a configuration file or parsing the environment variables.
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" )
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 ¶
UnmarshalText ensure that the log level defined in the configuration is valid.
type Pattern ¶ added in v3.1.0
Pattern stores a valid regular expression.
func (*Pattern) UnmarshalText ¶ added in v3.1.0
UnmarshalText compile the pattern checking for expression errors.
type Percentage ¶ added in v3.1.0
type Percentage float64
Percentage stores a valid percentage value.
func (*Percentage) UnmarshalText ¶ added in v3.1.0
func (p *Percentage) UnmarshalText(value []byte) error
UnmarshalText verifies if a percentage is a valid number.
type Scheduler ¶ added in v3.2.0
Scheduler stores the periodicity of an action.
func (*Scheduler) UnmarshalText ¶ added in v3.2.0
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