config

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FormatTOML = "toml"
	FormatYAML = "yaml"
	FormatJSON = "json"
	FormatHCL  = "hcl"
)
View Source
const (
	// ScheduleLockModeDefault waits on acquiring a lock (local and repository) for up to ScheduleConfig lockWait (duration), before failing a schedule.
	// With lockWait set to 0, ScheduleLockModeDefault and ScheduleLockModeFail behave the same.
	ScheduleLockModeDefault = ScheduleLockMode(0)
	// ScheduleLockModeFail fails immediately on a lock failure without waiting.
	ScheduleLockModeFail = ScheduleLockMode(1)
	// ScheduleLockModeIgnore does not create or fail on resticprofile locks. Repository locks cause an immediate failure.
	ScheduleLockModeIgnore = ScheduleLockMode(2)
)
View Source
const ConfidentialReplacement = "×××"

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
)

Functions

func GetNonConfidentialArgs added in v0.15.0

func GetNonConfidentialArgs(profile *Profile, args *shell.Args) *shell.Args

GetNonConfidentialArgs returns new shell.Args with confidential values being replaced with their public representation

func GetNonConfidentialValues added in v0.15.0

func GetNonConfidentialValues(profile *Profile, values []string) []string

GetNonConfidentialValues returns a new list with confidential values being replaced with their public representation

func ProcessConfidentialValues added in v0.15.0

func ProcessConfidentialValues(profile *Profile)

ProcessConfidentialValues hides confidential parts inside the specified Profile.

func ShowStruct added in v0.8.1

func ShowStruct(w io.Writer, orig interface{}, name string) error

ShowStruct write out to w a human readable text representation of the orig parameter

Types

type BackupSection

type BackupSection struct {
	SectionWithScheduleAndMonitoring `mapstructure:",squash"`
	RunShellCommandsSection          `mapstructure:",squash"`
	CheckBefore                      bool     `mapstructure:"check-before"`
	CheckAfter                       bool     `mapstructure:"check-after"`
	UseStdin                         bool     `mapstructure:"stdin" argument:"stdin"`
	StdinCommand                     []string `mapstructure:"stdin-command"`
	Source                           []string `mapstructure:"source"`
	Exclude                          []string `mapstructure:"exclude" argument:"exclude" argument-type:"no-glob"`
	Iexclude                         []string `mapstructure:"iexclude" argument:"iexclude" argument-type:"no-glob"`
	ExcludeFile                      []string `mapstructure:"exclude-file" argument:"exclude-file"`
	FilesFrom                        []string `mapstructure:"files-from" argument:"files-from"`
	ExtendedStatus                   bool     `mapstructure:"extended-status" argument:"json"`
	NoErrorOnWarning                 bool     `mapstructure:"no-error-on-warning"`
}

BackupSection contains the specific configuration to the 'backup' command

func (*BackupSection) IsEmpty added in v0.17.0

func (s *BackupSection) IsEmpty() bool

type ConfidentialValue added in v0.15.0

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

ConfidentialValue is a string value with a public and a confidential representation

func NewConfidentialValue added in v0.15.0

func NewConfidentialValue(value string) ConfidentialValue

func (*ConfidentialValue) IsConfidential added in v0.15.0

func (c *ConfidentialValue) IsConfidential() bool

func (ConfidentialValue) String added in v0.15.0

func (c ConfidentialValue) String() string

func (ConfidentialValue) Value added in v0.15.0

func (c ConfidentialValue) Value() string

type Config added in v0.8.0

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

Config wraps up a viper configuration object

func Load added in v0.8.0

func Load(input io.Reader, format string) (config *Config, err error)

Load configuration from reader This should only be used for unit tests

func LoadFile added in v0.8.0

func LoadFile(configFile, format string) (config *Config, err error)

LoadFile loads configuration from file Leave format blank for auto-detection from the file extension

func (*Config) DisplayConfigurationIssues added in v0.17.0

func (c *Config) DisplayConfigurationIssues()

DisplayConfigurationIssues logs issues in the configuration for all profiles previously returned by GetProfile

func (*Config) Get added in v0.8.0

func (c *Config) Get(key ...string) interface{}

Get the value from the key

func (*Config) GetConfigFile added in v0.8.0

func (c *Config) GetConfigFile() string

GetConfigFile returns the config file used

func (*Config) GetGlobalSection added in v0.8.0

func (c *Config) GetGlobalSection() (*Global, error)

GetGlobalSection returns the global configuration

func (*Config) GetProfile added in v0.8.0

func (c *Config) GetProfile(profileKey string) (profile *Profile, err error)

GetProfile in configuration. If the profile is not found, it returns errNotFound

func (*Config) GetProfileGroup added in v0.8.0

func (c *Config) GetProfileGroup(groupKey string) (*Group, error)

GetProfileGroup returns the list of profiles in a group

func (*Config) GetProfileGroups added in v0.8.0

func (c *Config) GetProfileGroups() map[string]Group

GetProfileGroups returns all groups from the configuration

If the groups section does not exist, it returns an empty map

func (*Config) GetProfileNames added in v0.17.0

func (c *Config) GetProfileNames() (names []string)

GetProfileNames returns all profile names defined in the configuration

func (*Config) GetProfiles added in v0.17.0

func (c *Config) GetProfiles() map[string]*Profile

GetProfiles returns a map of all available profiles with their configuration

func (*Config) GetScheduleSections added in v0.16.1

func (c *Config) GetScheduleSections() (schedules map[string]Schedule, err error)

GetScheduleSections returns a list of schedules

func (*Config) GetSchedules added in v0.16.1

func (c *Config) GetSchedules() ([]*ScheduleConfig, error)

GetSchedules loads all schedules from the configuration. !!! Nothing is using this method yet !!!

func (*Config) GetVersion added in v0.16.1

func (c *Config) GetVersion() Version

GetVersion returns the version of the configuration file. Default is Version01 if not specified or invalid

func (*Config) HasProfile added in v0.8.0

func (c *Config) HasProfile(profileKey string) bool

HasProfile returns true if the profile exists in the configuration

func (*Config) HasProfileGroup added in v0.8.0

func (c *Config) HasProfileGroup(groupKey string) bool

HasProfileGroup returns true if the group of profiles exists in the configuration

func (*Config) IsSet added in v0.8.0

func (c *Config) IsSet(key ...string) bool

IsSet checks if the key contains a value. Key and subkey can be queried with IsSet(key, subkey) or by separating them with keyDelim.

type CopySection added in v0.16.0

type CopySection struct {
	SectionWithScheduleAndMonitoring `mapstructure:",squash"`
	RunShellCommandsSection          `mapstructure:",squash"`
	Initialize                       bool              `mapstructure:"initialize"`
	InitializeCopyChunkerParams      bool              `mapstructure:"initialize-copy-chunker-params"`
	Repository                       ConfidentialValue `mapstructure:"repository" argument:"repo2"`
	RepositoryFile                   string            `mapstructure:"repository-file" argument:"repository-file2"`
	PasswordFile                     string            `mapstructure:"password-file" argument:"password-file2"`
	PasswordCommand                  string            `mapstructure:"password-command" argument:"password-command2"`
	KeyHint                          string            `mapstructure:"key-hint" argument:"key-hint2"`
}

CopySection contains the destination parameters for a copy command

func (*CopySection) IsEmpty added in v0.17.0

func (s *CopySection) IsEmpty() bool

type Display added in v0.11.0

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

Display is a temporary struct to display a config object to the console

func (*Display) Flush added in v0.11.0

func (d *Display) Flush()

type Empty added in v0.17.0

type Empty interface {
	IsEmpty() bool
}

type Entry added in v0.11.0

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

Entry of configuration to display to the console

type Global

type Global struct {
	IONice               bool          `mapstructure:"ionice"`
	IONiceClass          int           `mapstructure:"ionice-class"`
	IONiceLevel          int           `mapstructure:"ionice-level"`
	Nice                 int           `mapstructure:"nice"`
	Priority             string        `mapstructure:"priority"`
	DefaultCommand       string        `mapstructure:"default-command"`
	Initialize           bool          `mapstructure:"initialize"`
	ResticBinary         string        `mapstructure:"restic-binary"`
	ResticLockRetryAfter time.Duration `mapstructure:"restic-lock-retry-after"`
	ResticStaleLockAge   time.Duration `mapstructure:"restic-stale-lock-age"`
	ShellBinary          []string      `mapstructure:"shell"`
	MinMemory            uint64        `mapstructure:"min-memory"`
	Scheduler            string        `mapstructure:"scheduler"`
	LegacyArguments      bool          `mapstructure:"legacy-arguments"` // broken arguments mode (before v0.15.0)
	SystemdUnitTemplate  string        `mapstructure:"systemd-unit-template"`
	SystemdTimerTemplate string        `mapstructure:"systemd-timer-template"`
	SenderTimeout        time.Duration `mapstructure:"send-timeout"`
	CACertificates       []string      `mapstructure:"ca-certificates"`
	PreventSleep         bool          `mapstructure:"prevent-sleep"`
	GroupContinueOnError bool          `mapstructure:"group-continue-on-error"`
}

Global holds the configuration from the global section

func NewGlobal added in v0.14.0

func NewGlobal() *Global

NewGlobal instantiates a new Global with default values

func (*Global) SetRootPath added in v0.16.0

func (p *Global) SetRootPath(rootPath string)

type Group added in v0.16.1

type Group struct {
	Description     string   `mapstructure:"description"`
	Profiles        []string `mapstructure:"profiles"`
	ContinueOnError *bool    `mapstructure:"continue-on-error"`
}

Group of profiles

type InitSection added in v0.18.0

type InitSection struct {
	OtherFlagsSection   `mapstructure:",squash"`
	FromRepository      ConfidentialValue `mapstructure:"from-repository" argument:"repo2"`
	FromRepositoryFile  string            `mapstructure:"from-repository-file" argument:"repository-file2"`
	FromPasswordFile    string            `mapstructure:"from-password-file" argument:"password-file2"`
	FromPasswordCommand string            `mapstructure:"from-password-command" argument:"password-command2"`
}

InitSection contains the specific configuration to the 'init' command

func (*InitSection) IsEmpty added in v0.19.0

func (i *InitSection) IsEmpty() bool

type Monitoring added in v0.19.0

type Monitoring interface {
	GetSendMonitoring() *SendMonitoringSections
}

type OtherFlags added in v0.19.0

type OtherFlags interface {
	GetOtherFlags() map[string]interface{}
}

type OtherFlagsSection added in v0.19.0

type OtherFlagsSection struct {
	OtherFlags map[string]interface{} `mapstructure:",remain"`
}

OtherFlagsSection contains additional restic command line flags

func (OtherFlagsSection) GetOtherFlags added in v0.19.0

func (o OtherFlagsSection) GetOtherFlags() map[string]interface{}

type Profile

type Profile struct {
	RunShellCommandsSection `mapstructure:",squash"`
	OtherFlagsSection       `mapstructure:",squash"`

	Name                 string
	Description          string                            `mapstructure:"description"`
	Quiet                bool                              `mapstructure:"quiet" argument:"quiet"`
	Verbose              bool                              `mapstructure:"verbose" argument:"verbose"`
	Repository           ConfidentialValue                 `mapstructure:"repository" argument:"repo"`
	RepositoryFile       string                            `mapstructure:"repository-file" argument:"repository-file"`
	PasswordFile         string                            `mapstructure:"password-file" argument:"password-file"`
	CacheDir             string                            `mapstructure:"cache-dir" argument:"cache-dir"`
	CACert               string                            `mapstructure:"cacert" argument:"cacert"`
	TLSClientCert        string                            `mapstructure:"tls-client-cert" argument:"tls-client-cert"`
	Initialize           bool                              `mapstructure:"initialize"`
	Inherit              string                            `mapstructure:"inherit" show:"noshow"`
	Lock                 string                            `mapstructure:"lock"`
	ForceLock            bool                              `mapstructure:"force-inactive-lock"`
	StreamError          []StreamErrorSection              `mapstructure:"stream-error"`
	StatusFile           string                            `mapstructure:"status-file"`
	PrometheusSaveToFile string                            `mapstructure:"prometheus-save-to-file"`
	PrometheusPush       string                            `mapstructure:"prometheus-push"`
	PrometheusLabels     map[string]string                 `mapstructure:"prometheus-labels"`
	Environment          map[string]ConfidentialValue      `mapstructure:"env"`
	Init                 *InitSection                      `mapstructure:"init"`
	Backup               *BackupSection                    `mapstructure:"backup"`
	Retention            *RetentionSection                 `mapstructure:"retention"`
	Check                *SectionWithScheduleAndMonitoring `mapstructure:"check"`
	Prune                *SectionWithScheduleAndMonitoring `mapstructure:"prune"`
	Snapshots            *OtherFlagsSection                `mapstructure:"snapshots"`
	Forget               *SectionWithScheduleAndMonitoring `mapstructure:"forget"`
	Mount                *OtherFlagsSection                `mapstructure:"mount"`
	Copy                 *CopySection                      `mapstructure:"copy"`
	Dump                 *OtherFlagsSection                `mapstructure:"dump"`
	Find                 *OtherFlagsSection                `mapstructure:"find"`
	Ls                   *OtherFlagsSection                `mapstructure:"ls"`
	Restore              *OtherFlagsSection                `mapstructure:"restore"`
	Stats                *OtherFlagsSection                `mapstructure:"stats"`
	Tag                  *OtherFlagsSection                `mapstructure:"tag"`
	// contains filtered or unexported fields
}

Profile contains the whole profile configuration

func NewProfile

func NewProfile(c *Config, name string) *Profile

NewProfile instantiates a new blank profile

func (*Profile) DefinedCommands added in v0.17.0

func (p *Profile) DefinedCommands() []string

DefinedCommands returns all commands (also called sections) defined in the profile (backup, check, forget, etc.)

func (*Profile) GetBackupSource

func (p *Profile) GetBackupSource() []string

GetBackupSource returns the directories to backup

func (*Profile) GetCommandFlags

func (p *Profile) GetCommandFlags(command string) *shell.Args

GetCommandFlags returns the flags specific to the command (backup, snapshots, forget, etc.)

func (*Profile) GetCommonFlags

func (p *Profile) GetCommonFlags() *shell.Args

GetCommonFlags returns the flags common to all commands

func (*Profile) GetMonitoringSections added in v0.18.0

func (p *Profile) GetMonitoringSections(command string) (monitoring *SendMonitoringSections)

func (*Profile) GetRetentionFlags

func (p *Profile) GetRetentionFlags() *shell.Args

GetRetentionFlags returns the flags specific to the "forget" command being run as part of a backup

func (*Profile) GetRunShellCommandsSections added in v0.19.0

func (p *Profile) GetRunShellCommandsSections(command string) (profileCommands RunShellCommandsSection, sectionCommands RunShellCommandsSection)

func (*Profile) HasDeprecatedRetentionSchedule added in v0.11.0

func (p *Profile) HasDeprecatedRetentionSchedule() bool

HasDeprecatedRetentionSchedule indicates if there's one or more schedule parameters in the retention section, which is deprecated as of 0.11.0

func (*Profile) ResolveConfiguration added in v0.17.0

func (p *Profile) ResolveConfiguration()

ResolveConfiguration resolves dependencies between profile config flags

func (*Profile) SchedulableCommands added in v0.12.0

func (p *Profile) SchedulableCommands() []string

SchedulableCommands returns all command names that could have a schedule

func (*Profile) Schedules added in v0.9.0

func (p *Profile) Schedules() []*ScheduleConfig

Schedules returns a slice of ScheduleConfig that satisfy the schedule.Config interface

func (*Profile) SetHost

func (p *Profile) SetHost(hostname string)

SetHost will replace any host value from a boolean to the hostname

func (*Profile) SetLegacyArg added in v0.15.0

func (p *Profile) SetLegacyArg(legacy bool)

SetLegacyArg is used to activate the legacy (broken) mode of sending arguments on the restic command line

func (*Profile) SetPath added in v0.17.0

func (p *Profile) SetPath(sourcePaths ...string)

SetPath will replace any path value from a boolean to sourcePaths and change paths to absolute

func (*Profile) SetRootPath

func (p *Profile) SetRootPath(rootPath string)

SetRootPath changes the path of all the relative paths and files in the configuration

func (*Profile) SetTag added in v0.17.0

func (p *Profile) SetTag(tags ...string)

SetTag will replace any tag value from a boolean to the tags

type ProfileInfo added in v0.15.0

type ProfileInfo struct {
	Description string
	Sections    []string
}

ProfileInfo is used to display a quick information on available profiles (descrition and defined commands)

func NewProfileInfo added in v0.15.0

func NewProfileInfo() ProfileInfo

type ProfileTemplateData added in v0.10.0

type ProfileTemplateData struct {
	Name string
}

ProfileTemplateData contains profile data

type RetentionSection

type RetentionSection struct {
	ScheduleBaseSection `mapstructure:",squash"`
	OtherFlagsSection   `mapstructure:",squash"`
	BeforeBackup        bool `mapstructure:"before-backup"`
	AfterBackup         bool `mapstructure:"after-backup"`
}

RetentionSection contains the specific configuration to the 'forget' command when running as part of a backup

func (*RetentionSection) IsEmpty added in v0.17.0

func (r *RetentionSection) IsEmpty() bool

type RunShellCommands added in v0.19.0

type RunShellCommands interface {
	GetRunShellCommands() *RunShellCommandsSection
}

type RunShellCommandsSection added in v0.19.0

type RunShellCommandsSection struct {
	RunBefore    []string `mapstructure:"run-before"`
	RunAfter     []string `mapstructure:"run-after"`
	RunAfterFail []string `mapstructure:"run-after-fail"`
	RunFinally   []string `mapstructure:"run-finally"`
}

RunShellCommandsSection is used to define shell commands that run before or after restic commands

func (*RunShellCommandsSection) GetRunShellCommands added in v0.19.0

func (r *RunShellCommandsSection) GetRunShellCommands() *RunShellCommandsSection

type Schedule added in v0.16.1

type Schedule struct {
	Group      string        `mapstructure:"group"`
	Profiles   []string      `mapstructure:"profiles"`
	Command    string        `mapstructure:"run"`
	Schedule   []string      `mapstructure:"schedule"`
	Permission string        `mapstructure:"permission"`
	Log        string        `mapstructure:"log"`
	Priority   string        `mapstructure:"priority"`
	LockMode   string        `mapstructure:"lock-mode"`
	LockWait   time.Duration `mapstructure:"lock-wait"`
}

type ScheduleBaseSection added in v0.18.0

type ScheduleBaseSection struct {
	Schedule           []string      `mapstructure:"schedule" show:"noshow"`
	SchedulePermission string        `mapstructure:"schedule-permission" show:"noshow"`
	ScheduleLog        string        `mapstructure:"schedule-log" show:"noshow"`
	SchedulePriority   string        `mapstructure:"schedule-priority" show:"noshow"`
	ScheduleLockMode   string        `mapstructure:"schedule-lock-mode" show:"noshow"`
	ScheduleLockWait   time.Duration `mapstructure:"schedule-lock-wait" show:"noshow"`
}

ScheduleBaseSection contains the parameters for scheduling a command (backup, check, forget, etc.)

func (*ScheduleBaseSection) GetSchedule added in v0.19.0

func (s *ScheduleBaseSection) GetSchedule() *ScheduleBaseSection

type ScheduleConfig added in v0.9.0

type ScheduleConfig struct {
	Title            string
	SubTitle         string
	Schedules        []string
	Permission       string
	WorkingDirectory string
	Command          string
	Arguments        []string
	Environment      map[string]string
	JobDescription   string
	TimerDescription string
	Priority         string
	Log              string
	LockMode         string
	LockWait         time.Duration
	ConfigFile       string
	Flags            map[string]string
	RemoveOnly       bool
}

ScheduleConfig contains all information to schedule a profile command

func NewRemoveOnlyConfig added in v0.18.0

func NewRemoveOnlyConfig(profileName, commandName string) *ScheduleConfig

NewRemoveOnlyConfig creates a job config that may be used to call Job.Remove() on a scheduled job

func (*ScheduleConfig) Export added in v0.16.1

func (s *ScheduleConfig) Export() Schedule

func (*ScheduleConfig) GetFlag added in v0.11.0

func (s *ScheduleConfig) GetFlag(name string) (string, bool)

func (*ScheduleConfig) GetLockMode added in v0.18.0

func (s *ScheduleConfig) GetLockMode() ScheduleLockMode

func (*ScheduleConfig) GetLockWait added in v0.18.0

func (s *ScheduleConfig) GetLockWait() time.Duration

func (*ScheduleConfig) GetPriority added in v0.18.0

func (s *ScheduleConfig) GetPriority() string

Priority is either "background" or "standard"

func (*ScheduleConfig) SetCommand added in v0.9.0

func (s *ScheduleConfig) SetCommand(wd, command string, args []string)

func (*ScheduleConfig) SetFlag added in v0.11.0

func (s *ScheduleConfig) SetFlag(name, value string)

type ScheduleLockMode added in v0.14.0

type ScheduleLockMode int8

type ScheduleTemplateData added in v0.16.1

type ScheduleTemplateData struct {
	Name string
}

ScheduleTemplateData contains schedule data

type Scheduling added in v0.19.0

type Scheduling interface {
	GetSchedule() *ScheduleBaseSection
}

type SectionWithScheduleAndMonitoring added in v0.18.0

type SectionWithScheduleAndMonitoring struct {
	ScheduleBaseSection    `mapstructure:",squash"`
	SendMonitoringSections `mapstructure:",squash"`
	OtherFlagsSection      `mapstructure:",squash"`
}

SectionWithScheduleAndMonitoring is a section containing schedule, shell command hooks and monitoring (all the other parameters being for restic)

func (*SectionWithScheduleAndMonitoring) IsEmpty added in v0.18.0

type SendMonitoringHeader added in v0.18.0

type SendMonitoringHeader struct {
	Name  string `mapstructure:"name"`
	Value string `mapstructure:"value"`
}

SendMonitoringHeader is used to send HTTP headers

type SendMonitoringSection added in v0.18.0

type SendMonitoringSection struct {
	Method       string                 `mapstructure:"method"`
	URL          string                 `mapstructure:"url"`
	Headers      []SendMonitoringHeader `mapstructure:"headers"`
	Body         string                 `mapstructure:"body"`
	BodyTemplate string                 `mapstructure:"body-template"`
	SkipTLS      bool                   `mapstructure:"skip-tls-verification"`
}

SendMonitoringSection is used to send monitoring information to third party software

type SendMonitoringSections added in v0.18.0

type SendMonitoringSections struct {
	SendBefore    []SendMonitoringSection `mapstructure:"send-before"`
	SendAfter     []SendMonitoringSection `mapstructure:"send-after"`
	SendAfterFail []SendMonitoringSection `mapstructure:"send-after-fail"`
	SendFinally   []SendMonitoringSection `mapstructure:"send-finally"`
}

SendMonitoringSections is a group of target to send monitoring information

func (*SendMonitoringSections) GetSendMonitoring added in v0.19.0

func (s *SendMonitoringSections) GetSendMonitoring() *SendMonitoringSections

type StreamErrorSection added in v0.17.0

type StreamErrorSection struct {
	Pattern    string `mapstructure:"pattern"`
	MinMatches int    `mapstructure:"min-matches"`
	MaxRuns    int    `mapstructure:"max-runs"`
	Run        string `mapstructure:"run"`
}

type TemplateData added in v0.10.0

type TemplateData struct {
	Profile    ProfileTemplateData
	Schedule   ScheduleTemplateData
	Now        time.Time
	CurrentDir string
	ConfigDir  string
	TempDir    string
	BinaryDir  string
	Hostname   string
	Env        map[string]string
}

TemplateData contain the variables fed to a config template

type Version added in v0.16.1

type Version int
const (
	VersionUnknown Version = iota
	Version01
	Version02
	VersionMax = Version02
)

func ParseVersion added in v0.16.1

func ParseVersion(raw string) Version

ParseVersion return the version number, if invalid the default version is Version01

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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