config

package
v0.1.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config loads and validates the runner's settings from its environment.

Index

Constants

View Source
const (
	EnvToken       = "BACKPROOF_TOKEN"
	EnvRunnerKey   = "BACKPROOF_RUNNER_KEY"
	EnvAPIURL      = "BACKPROOF_API_URL"
	EnvName        = "BACKPROOF_NAME"
	EnvConcurrency = "BACKPROOF_CONCURRENCY"
	EnvWorkDir     = "BACKPROOF_WORK_DIR"
	EnvLogLevel    = "BACKPROOF_LOG_LEVEL"
	EnvMemoryLimit = "BACKPROOF_MEMORY_LIMIT"
	EnvCPULimit    = "BACKPROOF_CPU_LIMIT"
	EnvDiskMargin  = "BACKPROOF_DISK_MARGIN"
)

Environment variables the runner reads. docs/config.md describes each one.

View Source
const (
	DefaultAPIURL      = "https://api.backproof.dev"
	DefaultConcurrency = 1
	DefaultWorkDir     = "/var/lib/backproof"
	DefaultLogLevel    = slog.LevelInfo
	DefaultDiskMargin  = 3.0
)

Defaults for settings that are not set in the environment.

View Source
const RunnerEnvFile = "/etc/backproof/runner.env"

RunnerEnvFile is where registration stores the runner's settings.

View Source
const SourcesEnvFile = "/etc/backproof/sources.env"

SourcesEnvFile holds local secrets for backup sources. It is read again before each job.

Variables

View Source
var ErrRunnerFileExists = errors.New("runner file exists")

ErrRunnerFileExists means this machine has already registered a runner.

Functions

func EnvSourceAgeIdentity

func EnvSourceAgeIdentity(sourceID string) string

EnvSourceAgeIdentity names the variable holding a source's age private key.

func EnvSourceGPGKey

func EnvSourceGPGKey(sourceID string) string

EnvSourceGPGKey names the variable holding a source's GPG private key.

func EnvSourceGPGPassphrase

func EnvSourceGPGPassphrase(sourceID string) string

EnvSourceGPGPassphrase names the variable holding the passphrase of a source's GPG key.

func EnvSourceNameSalt

func EnvSourceNameSalt(sourceID string) string

EnvSourceNameSalt names the variable holding the salt for hashing a source's table names.

func EnvSourceS3AccessKey

func EnvSourceS3AccessKey(sourceID string) string

EnvSourceS3AccessKey names the variable holding a source's bucket access key.

func EnvSourceS3SecretKey

func EnvSourceS3SecretKey(sourceID string) string

EnvSourceS3SecretKey names the variable holding a source's bucket secret key.

Types

type Config

type Config struct {
	Token       Secret
	RunnerKey   Secret
	APIURL      string
	Name        string
	Concurrency int
	WorkDir     string
	LogLevel    slog.Level
	// Zero means no limit.
	MemoryLimitBytes int64
	CPULimitNanos    int64
	// DiskMargin is how many times the backup's size must be free before downloading it.
	DiskMargin float64
}

Config holds the validated runner settings.

func Load

func Load(lookup LookupFunc) (Config, error)

Load reads the settings through lookup and reports every invalid setting at once. Error messages never contain the rejected values, because a value may be a misplaced secret.

type LookupFunc

type LookupFunc func(key string) (string, bool)

LookupFunc reads one environment variable. os.LookupEnv satisfies it.

func WithEnvFile

func WithEnvFile(lookup LookupFunc, path string) (LookupFunc, error)

WithEnvFile adds the values of an env file to lookup. Real environment variables win, and a missing file adds nothing. Lines are KEY=VALUE, taken literally like docker run --env-file.

type RunnerFile

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

RunnerFile is a settings file that is reserved before registering. An install token works only once, so a directory that can't be written must be found before the token is spent.

func ReserveRunnerFile

func ReserveRunnerFile(path string) (*RunnerFile, error)

ReserveRunnerFile checks that the settings can be saved at path.

func (*RunnerFile) Commit

func (f *RunnerFile) Commit(settings RunnerSettings) error

Commit saves the settings. The result can be passed to docker run --env-file, which takes every line literally, so values are written without quotes.

func (*RunnerFile) Discard

func (f *RunnerFile) Discard()

Discard removes the reservation. It is safe to call after Commit.

type RunnerSettings

type RunnerSettings struct {
	Token     Secret
	RunnerKey Secret
	Name      string
	APIURL    string
}

RunnerSettings are the values saved when a runner registers.

type Secret

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

Secret holds a sensitive value and redacts it in logs, formatted output and JSON.

func NewSecret

func NewSecret(value string) Secret

NewSecret wraps a sensitive value.

func (Secret) Format

func (s Secret) Format(state fmt.State, _ rune)

Format redacts every fmt verb, including %d and %x, which would otherwise bypass String.

func (Secret) IsSet

func (s Secret) IsSet() bool

IsSet reports whether the secret holds a value.

func (Secret) LogValue

func (s Secret) LogValue() slog.Value

LogValue redacts the secret in slog output.

func (Secret) MarshalText

func (s Secret) MarshalText() ([]byte, error)

MarshalText redacts the secret in JSON and other text encodings.

func (Secret) Reveal

func (s Secret) Reveal() string

Reveal returns the plain value. Call it only where the value is used, never to log it.

func (Secret) String

func (s Secret) String() string

String returns a redacted placeholder.

type SourceSecrets

type SourceSecrets struct {
	S3AccessKey   Secret
	S3SecretKey   Secret
	AgeIdentity   Secret
	GPGKey        Secret
	GPGPassphrase Secret
	NameSalt      Secret
}

SourceSecrets holds the local keys of one backup source.

func LoadSourceSecrets

func LoadSourceSecrets(lookup LookupFunc, sourceID string) SourceSecrets

LoadSourceSecrets reads the local keys of a backup source.

Jump to

Keyboard shortcuts

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