config

package
v0.0.0-...-5a493b6 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const Version = "v1alpha1"

Version is the latest version of the config format.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backup

type Backup struct {
	// Name is the name of the backup. Must be unique.
	Name string `json:"name"`
	// Commands is a list of commands to execute in order.
	Commands []Command `json:"commands"`
	// Requires is an optional list of requirements.
	Requires []Requirement `json:"requires,omitempty"`
	// Interval is the time interval between backups.
	Interval Duration `json:"interval"`
}

Backup is the configuration for a backup.

type Command

type Command struct {
	// Cmd is the full path to the command to run.
	Cmd string `json:"cmd"`
	// Args is the list of arguments to pass
	Args []string `json:"args"`
	// Env is a map of environment variables with their value.
	Env map[string]string `json:"env,omitempty"`
	// Workdir specifies the working directory.
	// Defaults to the current directory.
	Workdir string `json:"workdir,omitempty"`
	// SecretEnv is a map from environment variables to identifiers, not
	// stored in the config, but asked to the user at runtime.
	// If the same identifier is used by multiple variables within a backup,
	// the value will be asked only once and the value used multiple times.
	SecretEnv map[string]Secret `json:"secretEnv,omitempty"`
}

Command represents a command to run.

type Config

type Config struct {
	Version string   `json:"version"`
	Backups []Backup `json:"backups"`
}

Config is the configuration format.

func Parse

func Parse(path string) (Config, error)

Parse takes a file path and returns a parsed config.

type Duration

type Duration time.Duration

Duration is a wrapper arond duration.

See https://github.com/golang/go/issues/10275 and https://stackoverflow.com/q/48050945/1667955.

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

MarshalJSON provides custom JSON marshalling for Duration.

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

UnmarshalJSON provides custom JSON unmarshalling for Duration.

type Requirement

type Requirement struct {
	// Path is a path in the filesystem that must be present in order for the
	// backup to proceed.
	Path *string `json:"path,omitempty"`
}

Requirement is a backup requirement.

type Secret

type Secret struct {
	ID string `json:"id"`
}

Secret represents a secret value, not stored in the config but identified with a unique string and asked at runtime.

type State

type State map[string]time.Time

State contains the state of all the backups

func LoadState

func LoadState(b []byte) (State, error)

LoadState loads the backup state from a buffer

func (State) LastBackupOf

func (s State) LastBackupOf(name string) (time.Time, bool)

LastBackupOf returns the time of the last given backup name. Returns false if the backup has been never done

func (State) Save

func (s State) Save() ([]byte, error)

Save saves the state to the given file

Jump to

Keyboard shortcuts

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