2022-02-13 10:52:19 +01:00
|
|
|
// Copyright 2022 - Offen Authors <hioffen@posteo.de>
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
2022-05-08 11:20:38 +02:00
|
|
|
import (
|
2022-12-22 14:37:51 +01:00
|
|
|
"crypto/x509"
|
|
|
|
"encoding/pem"
|
2022-05-08 11:20:38 +02:00
|
|
|
"fmt"
|
2022-10-12 21:15:17 +02:00
|
|
|
"os"
|
2022-05-08 11:20:38 +02:00
|
|
|
"regexp"
|
2023-08-24 19:33:47 +02:00
|
|
|
"strconv"
|
2022-05-08 11:20:38 +02:00
|
|
|
"time"
|
|
|
|
)
|
2022-02-13 10:52:19 +01:00
|
|
|
|
|
|
|
// Config holds all configuration values that are expected to be set
|
|
|
|
// by users.
|
|
|
|
type Config struct {
|
2023-08-27 22:29:44 +02:00
|
|
|
AwsS3BucketName string
|
|
|
|
AwsS3Path string
|
|
|
|
AwsEndpoint string `default:"s3.amazonaws.com"`
|
|
|
|
AwsEndpointProto string
|
2023-08-27 20:14:59 +02:00
|
|
|
AwsEndpointInsecure bool
|
2023-08-27 22:29:44 +02:00
|
|
|
AwsEndpointCACert CertDecoder
|
2023-08-27 20:14:59 +02:00
|
|
|
AwsStorageClass string
|
2023-08-27 22:29:44 +02:00
|
|
|
AwsAccessKeyID string
|
|
|
|
AwsSecretAccessKey string
|
2023-08-27 20:14:59 +02:00
|
|
|
AwsIamRoleEndpoint string
|
|
|
|
AwsPartSize int64
|
2023-08-27 22:29:44 +02:00
|
|
|
BackupCompression CompressionType `default:"gz"`
|
|
|
|
BackupSources string `default:"/backup"`
|
|
|
|
BackupFilename string `default:"backup-%Y-%m-%dT%H-%M-%S.{{ .Extension }}"`
|
2023-08-27 20:14:59 +02:00
|
|
|
BackupFilenameExpand bool
|
|
|
|
BackupLatestSymlink string
|
2023-08-27 22:29:44 +02:00
|
|
|
BackupArchive string `default:"/archive"`
|
|
|
|
BackupRetentionDays int32 `default:"-1"`
|
|
|
|
BackupPruningLeeway time.Duration `default:"1m"`
|
2023-08-27 20:14:59 +02:00
|
|
|
BackupPruningPrefix string
|
2023-08-27 22:29:44 +02:00
|
|
|
BackupStopContainerLabel string `default:"true"`
|
2023-08-27 20:14:59 +02:00
|
|
|
BackupFromSnapshot bool
|
|
|
|
BackupExcludeRegexp RegexpDecoder
|
|
|
|
BackupSkipBackendsFromPrune []string
|
2023-08-27 22:29:44 +02:00
|
|
|
GpgPassphrase string
|
|
|
|
NotificationURLs []string
|
|
|
|
NotificationLevel string `default:"error"`
|
2023-08-27 20:14:59 +02:00
|
|
|
EmailNotificationRecipient string
|
2023-08-27 22:29:44 +02:00
|
|
|
EmailNotificationSender string `default:"noreply@nohost"`
|
|
|
|
EmailSMTPHost string
|
|
|
|
EmailSMTPPort int `default:"587"`
|
|
|
|
EmailSMTPUsername string
|
|
|
|
EmailSMTPPassword string
|
2023-08-27 20:14:59 +02:00
|
|
|
WebdavUrl string
|
|
|
|
WebdavUrlInsecure bool
|
2023-08-27 22:29:44 +02:00
|
|
|
WebdavPath string `default:"/"`
|
2023-08-27 20:14:59 +02:00
|
|
|
WebdavUsername string
|
2023-08-27 22:29:44 +02:00
|
|
|
WebdavPassword string
|
|
|
|
SSHHostName string
|
|
|
|
SSHPort string `default:"22"`
|
|
|
|
SSHUser string
|
|
|
|
SSHPassword string
|
|
|
|
SSHIdentityFile string `default:"/root/.ssh/id_rsa"`
|
|
|
|
SSHIdentityPassphrase string
|
|
|
|
SSHRemotePath string
|
2023-08-27 20:14:59 +02:00
|
|
|
ExecLabel string
|
|
|
|
ExecForwardOutput bool
|
2023-08-27 22:29:44 +02:00
|
|
|
LockTimeout time.Duration `default:"60m"`
|
2023-08-27 20:14:59 +02:00
|
|
|
AzureStorageAccountName string
|
|
|
|
AzureStoragePrimaryAccountKey string
|
|
|
|
AzureStorageContainerName string
|
|
|
|
AzureStoragePath string
|
2023-08-27 22:29:44 +02:00
|
|
|
AzureStorageEndpoint string `default:"https://{{ .AccountName }}.blob.core.windows.net/"`
|
|
|
|
DropboxEndpoint string `default:"https://api.dropbox.com/"`
|
|
|
|
DropboxOAuth2Endpoint string `default:"https://api.dropbox.com/"`
|
|
|
|
DropboxRefreshToken string
|
|
|
|
DropboxAppKey string
|
|
|
|
DropboxAppSecret string
|
2023-08-27 20:14:59 +02:00
|
|
|
DropboxRemotePath string
|
2023-08-27 22:29:44 +02:00
|
|
|
DropboxConcurrencyLevel NaturalNumber `default:"6"`
|
2023-08-27 21:02:06 +02:00
|
|
|
}
|
|
|
|
|
2023-08-19 19:20:13 +02:00
|
|
|
type CompressionType string
|
|
|
|
|
2023-08-27 20:14:59 +02:00
|
|
|
func (c *CompressionType) UnmarshalText(text []byte) error {
|
|
|
|
v := string(text)
|
2023-08-19 19:20:13 +02:00
|
|
|
switch v {
|
|
|
|
case "gz", "zst":
|
|
|
|
*c = CompressionType(v)
|
|
|
|
return nil
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("config: error decoding compression type %s", v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CompressionType) String() string {
|
|
|
|
return string(*c)
|
|
|
|
}
|
|
|
|
|
2022-12-22 14:37:51 +01:00
|
|
|
type CertDecoder struct {
|
|
|
|
Cert *x509.Certificate
|
|
|
|
}
|
|
|
|
|
2023-08-27 20:14:59 +02:00
|
|
|
func (c *CertDecoder) UnmarshalText(text []byte) error {
|
|
|
|
v := string(text)
|
2022-12-22 14:37:51 +01:00
|
|
|
if v == "" {
|
|
|
|
return nil
|
|
|
|
}
|
2023-08-27 18:14:55 +02:00
|
|
|
content, err := os.ReadFile(v)
|
2022-12-22 14:37:51 +01:00
|
|
|
if err != nil {
|
|
|
|
content = []byte(v)
|
|
|
|
}
|
|
|
|
block, _ := pem.Decode(content)
|
|
|
|
cert, err := x509.ParseCertificate(block.Bytes)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("config: error parsing certificate: %w", err)
|
|
|
|
}
|
|
|
|
*c = CertDecoder{Cert: cert}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-05-08 11:20:38 +02:00
|
|
|
type RegexpDecoder struct {
|
|
|
|
Re *regexp.Regexp
|
|
|
|
}
|
|
|
|
|
2023-08-27 20:14:59 +02:00
|
|
|
func (r *RegexpDecoder) UnmarshalText(text []byte) error {
|
|
|
|
v := string(text)
|
2022-05-08 11:20:38 +02:00
|
|
|
if v == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
re, err := regexp.Compile(v)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("config: error compiling given regexp `%s`: %w", v, err)
|
|
|
|
}
|
|
|
|
*r = RegexpDecoder{Re: re}
|
|
|
|
return nil
|
|
|
|
}
|
2023-08-24 19:33:47 +02:00
|
|
|
|
|
|
|
type NaturalNumber int
|
|
|
|
|
2023-08-27 20:14:59 +02:00
|
|
|
func (n *NaturalNumber) UnmarshalText(text []byte) error {
|
|
|
|
v := string(text)
|
2023-08-24 19:33:47 +02:00
|
|
|
asInt, err := strconv.Atoi(v)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("config: error converting %s to int", v)
|
|
|
|
}
|
|
|
|
if asInt <= 0 {
|
|
|
|
return fmt.Errorf("config: expected a natural number, got %d", asInt)
|
|
|
|
}
|
|
|
|
*n = NaturalNumber(asInt)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *NaturalNumber) Int() int {
|
|
|
|
return int(*n)
|
|
|
|
}
|