Revert everything so far

This commit is contained in:
MaxJa4 2023-08-28 21:13:07 +02:00
parent 4c806006a4
commit 4a47f7ab69
4 changed files with 92 additions and 80 deletions

View File

@ -16,72 +16,84 @@ import (
// Config holds all configuration values that are expected to be set // Config holds all configuration values that are expected to be set
// by users. // by users.
type Config struct { type Config struct {
AwsS3BucketName string AwsS3BucketName string `split_words:"true"`
AwsS3Path string AwsS3Path string `split_words:"true"`
AwsEndpoint string `default:"s3.amazonaws.com"` AwsEndpoint string `split_words:"true" default:"s3.amazonaws.com"`
AwsEndpointProto string AwsEndpointProto string `split_words:"true" default:"https"`
AwsEndpointInsecure bool AwsEndpointInsecure bool `split_words:"true"`
AwsEndpointCACert CertDecoder AwsEndpointCACert CertDecoder `envconfig:"AWS_ENDPOINT_CA_CERT"`
AwsStorageClass string AwsStorageClass string `split_words:"true"`
AwsAccessKeyID string AwsAccessKeyID string `envconfig:"AWS_ACCESS_KEY_ID"`
AwsSecretAccessKey string AwsAccessKeyIDFile string `envconfig:"AWS_ACCESS_KEY_ID_FILE"`
AwsIamRoleEndpoint string AwsSecretAccessKey string `split_words:"true"`
AwsPartSize int64 AwsSecretAccessKeyFile string `split_words:"true"`
BackupCompression CompressionType `default:"gz"` AwsIamRoleEndpoint string `split_words:"true"`
BackupSources string `default:"/backup"` AwsPartSize int64 `split_words:"true"`
BackupFilename string `default:"backup-%Y-%m-%dT%H-%M-%S.{{ .Extension }}"` BackupCompression CompressionType `split_words:"true" default:"gz"`
BackupFilenameExpand bool BackupSources string `split_words:"true" default:"/backup"`
BackupLatestSymlink string BackupFilename string `split_words:"true" default:"backup-%Y-%m-%dT%H-%M-%S.{{ .Extension }}"`
BackupArchive string `default:"/archive"` BackupFilenameExpand bool `split_words:"true"`
BackupRetentionDays int32 `default:"-1"` BackupLatestSymlink string `split_words:"true"`
BackupPruningLeeway time.Duration `default:"1m"` BackupArchive string `split_words:"true" default:"/archive"`
BackupPruningPrefix string BackupRetentionDays int32 `split_words:"true" default:"-1"`
BackupStopContainerLabel string `default:"true"` BackupPruningLeeway time.Duration `split_words:"true" default:"1m"`
BackupFromSnapshot bool BackupPruningPrefix string `split_words:"true"`
BackupExcludeRegexp RegexpDecoder BackupStopContainerLabel string `split_words:"true" default:"true"`
BackupSkipBackendsFromPrune []string BackupFromSnapshot bool `split_words:"true"`
GpgPassphrase string BackupExcludeRegexp RegexpDecoder `split_words:"true"`
NotificationURLs []string BackupSkipBackendsFromPrune []string `split_words:"true"`
NotificationLevel string `default:"error"` GpgPassphrase string `split_words:"true"`
EmailNotificationRecipient string NotificationURLs []string `envconfig:"NOTIFICATION_URLS"`
EmailNotificationSender string `default:"noreply@nohost"` NotificationLevel string `split_words:"true" default:"error"`
EmailSMTPHost string EmailNotificationRecipient string `split_words:"true"`
EmailSMTPPort int `default:"587"` EmailNotificationSender string `split_words:"true" default:"noreply@nohost"`
EmailSMTPUsername string EmailSMTPHost string `envconfig:"EMAIL_SMTP_HOST"`
EmailSMTPPassword string EmailSMTPPort int `envconfig:"EMAIL_SMTP_PORT" default:"587"`
WebdavUrl string EmailSMTPUsername string `envconfig:"EMAIL_SMTP_USERNAME"`
WebdavUrlInsecure bool EmailSMTPPassword string `envconfig:"EMAIL_SMTP_PASSWORD"`
WebdavPath string `default:"/"` WebdavUrl string `split_words:"true"`
WebdavUsername string WebdavUrlInsecure bool `split_words:"true"`
WebdavPassword string WebdavPath string `split_words:"true" default:"/"`
SSHHostName string WebdavUsername string `split_words:"true"`
SSHPort string `default:"22"` WebdavPassword string `split_words:"true"`
SSHUser string SSHHostName string `split_words:"true"`
SSHPassword string SSHPort string `split_words:"true" default:"22"`
SSHIdentityFile string `default:"/root/.ssh/id_rsa"` SSHUser string `split_words:"true"`
SSHIdentityPassphrase string SSHPassword string `split_words:"true"`
SSHRemotePath string SSHIdentityFile string `split_words:"true" default:"/root/.ssh/id_rsa"`
ExecLabel string SSHIdentityPassphrase string `split_words:"true"`
ExecForwardOutput bool SSHRemotePath string `split_words:"true"`
LockTimeout time.Duration `default:"60m"` ExecLabel string `split_words:"true"`
AzureStorageAccountName string ExecForwardOutput bool `split_words:"true"`
AzureStoragePrimaryAccountKey string LockTimeout time.Duration `split_words:"true" default:"60m"`
AzureStorageContainerName string AzureStorageAccountName string `split_words:"true"`
AzureStoragePath string AzureStoragePrimaryAccountKey string `split_words:"true"`
AzureStorageEndpoint string `default:"https://{{ .AccountName }}.blob.core.windows.net/"` AzureStorageContainerName string `split_words:"true"`
DropboxEndpoint string `default:"https://api.dropbox.com/"` AzureStoragePath string `split_words:"true"`
DropboxOAuth2Endpoint string `default:"https://api.dropbox.com/"` AzureStorageEndpoint string `split_words:"true" default:"https://{{ .AccountName }}.blob.core.windows.net/"`
DropboxRefreshToken string DropboxEndpoint string `split_words:"true" default:"https://api.dropbox.com/"`
DropboxAppKey string DropboxOAuth2Endpoint string `envconfig:"DROPBOX_OAUTH2_ENDPOINT" default:"https://api.dropbox.com/"`
DropboxAppSecret string DropboxRefreshToken string `split_words:"true"`
DropboxRemotePath string DropboxAppKey string `split_words:"true"`
DropboxConcurrencyLevel NaturalNumber `default:"6"` DropboxAppSecret string `split_words:"true"`
DropboxRemotePath string `split_words:"true"`
DropboxConcurrencyLevel NaturalNumber `split_words:"true" default:"6"`
}
func (c *Config) resolveSecret(envVar string, secretPath string) (string, error) {
if secretPath == "" {
return envVar, nil
}
data, err := os.ReadFile(secretPath)
if err != nil {
return "", fmt.Errorf("resolveSecret: error reading secret path: %w", err)
}
return string(data), nil
} }
type CompressionType string type CompressionType string
func (c *CompressionType) UnmarshalText(text []byte) error { func (c *CompressionType) Decode(v string) error {
v := string(text)
switch v { switch v {
case "gz", "zst": case "gz", "zst":
*c = CompressionType(v) *c = CompressionType(v)
@ -99,8 +111,7 @@ type CertDecoder struct {
Cert *x509.Certificate Cert *x509.Certificate
} }
func (c *CertDecoder) UnmarshalText(text []byte) error { func (c *CertDecoder) Decode(v string) error {
v := string(text)
if v == "" { if v == "" {
return nil return nil
} }
@ -121,8 +132,7 @@ type RegexpDecoder struct {
Re *regexp.Regexp Re *regexp.Regexp
} }
func (r *RegexpDecoder) UnmarshalText(text []byte) error { func (r *RegexpDecoder) Decode(v string) error {
v := string(text)
if v == "" { if v == "" {
return nil return nil
} }
@ -136,8 +146,7 @@ func (r *RegexpDecoder) UnmarshalText(text []byte) error {
type NaturalNumber int type NaturalNumber int
func (n *NaturalNumber) UnmarshalText(text []byte) error { func (n *NaturalNumber) Decode(v string) error {
v := string(text)
asInt, err := strconv.Atoi(v) asInt, err := strconv.Atoi(v)
if err != nil { if err != nil {
return fmt.Errorf("config: error converting %s to int", v) return fmt.Errorf("config: error converting %s to int", v)

View File

@ -35,7 +35,7 @@ import (
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/johnstairs/pathenvconfig" "github.com/kelseyhightower/envconfig"
"github.com/leekchan/timeutil" "github.com/leekchan/timeutil"
"github.com/otiai10/copy" "github.com/otiai10/copy"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
@ -89,12 +89,10 @@ func newScript() (*script, error) {
return nil return nil
}) })
if err := pathenvconfig.Process("", s.c); err != nil { if err := envconfig.Process("", s.c); err != nil {
return nil, fmt.Errorf("newScript: failed to process configuration values: %w", err) return nil, fmt.Errorf("newScript: failed to process configuration values: %w", err)
} }
fmt.Printf("Using configuration: %+v\n", s.c) // Debug
s.file = path.Join("/tmp", s.c.BackupFilename) s.file = path.Join("/tmp", s.c.BackupFilename)
tmplFileName, tErr := template.New("extension").Parse(s.file) tmplFileName, tErr := template.New("extension").Parse(s.file)
@ -139,10 +137,18 @@ func newScript() (*script, error) {
} }
if s.c.AwsS3BucketName != "" { if s.c.AwsS3BucketName != "" {
accessKeyID, err := s.c.resolveSecret(s.c.AwsAccessKeyID, s.c.AwsAccessKeyIDFile)
if err != nil {
return nil, fmt.Errorf("newScript: error resolving AwsAccessKeyID: %w", err)
}
secretAccessKey, err := s.c.resolveSecret(s.c.AwsSecretAccessKey, s.c.AwsSecretAccessKeyFile)
if err != nil {
return nil, fmt.Errorf("newScript: error resolving AwsSecretAccessKey: %w", err)
}
s3Config := s3.Config{ s3Config := s3.Config{
Endpoint: s.c.AwsEndpoint, Endpoint: s.c.AwsEndpoint,
AccessKeyID: s.c.AwsAccessKeyID, AccessKeyID: accessKeyID,
SecretAccessKey: s.c.AwsSecretAccessKey, SecretAccessKey: secretAccessKey,
IamRoleEndpoint: s.c.AwsIamRoleEndpoint, IamRoleEndpoint: s.c.AwsIamRoleEndpoint,
EndpointProto: s.c.AwsEndpointProto, EndpointProto: s.c.AwsEndpointProto,
EndpointInsecure: s.c.AwsEndpointInsecure, EndpointInsecure: s.c.AwsEndpointInsecure,

3
go.mod
View File

@ -9,6 +9,7 @@ require (
github.com/cosiner/argv v0.1.0 github.com/cosiner/argv v0.1.0
github.com/docker/docker v24.0.5+incompatible github.com/docker/docker v24.0.5+incompatible
github.com/gofrs/flock v0.8.1 github.com/gofrs/flock v0.8.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/klauspost/compress v1.16.7 github.com/klauspost/compress v1.16.7
github.com/leekchan/timeutil v0.0.0-20150802142658-28917288c48d github.com/leekchan/timeutil v0.0.0-20150802142658-28917288c48d
github.com/minio/minio-go/v7 v7.0.62 github.com/minio/minio-go/v7 v7.0.62
@ -22,7 +23,6 @@ require (
require ( require (
github.com/cloudflare/circl v1.3.3 // indirect github.com/cloudflare/circl v1.3.3 // indirect
github.com/dlclark/regexp2 v1.4.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect github.com/golang/protobuf v1.5.2 // indirect
google.golang.org/appengine v1.6.7 // indirect google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect google.golang.org/protobuf v1.28.1 // indirect
@ -43,7 +43,6 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/google/uuid v1.3.0 // indirect github.com/google/uuid v1.3.0 // indirect
github.com/johnstairs/pathenvconfig v0.2.1
github.com/json-iterator/go v1.1.12 // indirect github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/kr/fs v0.1.0 // indirect github.com/kr/fs v0.1.0 // indirect

6
go.sum
View File

@ -252,8 +252,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E=
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI=
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8= github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8=
@ -442,8 +440,6 @@ github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jarcoal/httpmock v1.2.0 h1:gSvTxxFR/MEMfsGrvRbdfpRUMBStovlSRLw0Ep1bwwc= github.com/jarcoal/httpmock v1.2.0 h1:gSvTxxFR/MEMfsGrvRbdfpRUMBStovlSRLw0Ep1bwwc=
github.com/jarcoal/httpmock v1.2.0/go.mod h1:oCoTsnAz4+UoOUIf5lJOWV2QQIW5UoeUI6aM2YnWAZk= github.com/jarcoal/httpmock v1.2.0/go.mod h1:oCoTsnAz4+UoOUIf5lJOWV2QQIW5UoeUI6aM2YnWAZk=
github.com/johnstairs/pathenvconfig v0.2.1 h1:hay0C2ddNdej569b4GXwjwZyjRagei97ppjRW8XcvMQ=
github.com/johnstairs/pathenvconfig v0.2.1/go.mod h1:XqBReihWnlfmCkHqvJAfsRCfa/JJCYXZds8fwtuz8cM=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
@ -455,6 +451,8 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=