Documentation
¶
Overview ¶
Package config loads and validates the runner's settings from its environment.
Index ¶
- Constants
- Variables
- func EnvSourceAgeIdentity(sourceID string) string
- func EnvSourceGPGKey(sourceID string) string
- func EnvSourceGPGPassphrase(sourceID string) string
- func EnvSourceNameSalt(sourceID string) string
- func EnvSourceS3AccessKey(sourceID string) string
- func EnvSourceS3SecretKey(sourceID string) string
- type Config
- type LookupFunc
- type RunnerFile
- type RunnerSettings
- type Secret
- type SourceSecrets
Constants ¶
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.
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.
const RunnerEnvFile = "/etc/backproof/runner.env"
RunnerEnvFile is where registration stores the runner's settings.
const SourcesEnvFile = "/etc/backproof/sources.env"
SourcesEnvFile holds local secrets for backup sources. It is read again before each job.
Variables ¶
var ErrRunnerFileExists = errors.New("runner file exists")
ErrRunnerFileExists means this machine has already registered a runner.
Functions ¶
func EnvSourceAgeIdentity ¶
EnvSourceAgeIdentity names the variable holding a source's age private key.
func EnvSourceGPGKey ¶
EnvSourceGPGKey names the variable holding a source's GPG private key.
func EnvSourceGPGPassphrase ¶
EnvSourceGPGPassphrase names the variable holding the passphrase of a source's GPG key.
func EnvSourceNameSalt ¶
EnvSourceNameSalt names the variable holding the salt for hashing a source's table names.
func EnvSourceS3AccessKey ¶
EnvSourceS3AccessKey names the variable holding a source's bucket access key.
func EnvSourceS3SecretKey ¶
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 ¶
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 ¶
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 (Secret) Format ¶
Format redacts every fmt verb, including %d and %x, which would otherwise bypass String.
func (Secret) MarshalText ¶
MarshalText redacts the secret in JSON and other text encodings.
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.