From 769eb59428989bec0a040b52232c67f063f00d16 Mon Sep 17 00:00:00 2001 From: Antonin Kral Date: Thu, 11 Feb 2021 21:35:53 +0100 Subject: [PATCH] Hack in MinIO support --- cmd/litestream/main.go | 32 ++++++++++++++++++++++++-------- s3/s3.go | 10 +++++++--- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/cmd/litestream/main.go b/cmd/litestream/main.go index c8a7850..9930225 100644 --- a/cmd/litestream/main.go +++ b/cmd/litestream/main.go @@ -106,10 +106,12 @@ type Config struct { DBs []*DBConfig `yaml:"dbs"` // Global S3 settings - AccessKeyID string `yaml:"access-key-id"` - SecretAccessKey string `yaml:"secret-access-key"` - Region string `yaml:"region"` - Bucket string `yaml:"bucket"` + AccessKeyID string `yaml:"access-key-id"` + SecretAccessKey string `yaml:"secret-access-key"` + Region string `yaml:"region"` + Bucket string `yaml:"bucket"` + Endpoint string `yaml:"endpoint"` + S3ForcePathStyle bool `yaml:"force-path-style"` } // DefaultConfig returns a new instance of Config with defaults set. @@ -174,10 +176,12 @@ type ReplicaConfig struct { ValidationInterval time.Duration `yaml:"validation-interval"` // S3 settings - AccessKeyID string `yaml:"access-key-id"` - SecretAccessKey string `yaml:"secret-access-key"` - Region string `yaml:"region"` - Bucket string `yaml:"bucket"` + AccessKeyID string `yaml:"access-key-id"` + SecretAccessKey string `yaml:"secret-access-key"` + Region string `yaml:"region"` + Bucket string `yaml:"bucket"` + Endpoint string `yaml:"endpoint"` + S3ForcePathStyle bool `yaml:"force-path-style"` } // NewReplicaFromURL returns a new Replica instance configured from a URL. @@ -347,6 +351,16 @@ func newS3ReplicaFromConfig(db *litestream.DB, c *Config, dbc *DBConfig, rc *Rep if v := rc.Region; v != "" { region = v } + endpoint := c.Endpoint + if v := rc.Endpoint; v != "" { + endpoint = v + } + forcePathStyle := c.S3ForcePathStyle + if v := rc.S3ForcePathStyle; v { + // This is not really correct as will not allow for disabling path style + // per replica, if enabled globally + forcePathStyle = v + } // Ensure required settings are set. if bucket == "" { @@ -358,6 +372,8 @@ func newS3ReplicaFromConfig(db *litestream.DB, c *Config, dbc *DBConfig, rc *Rep r.AccessKeyID = accessKeyID r.SecretAccessKey = secretAccessKey r.Region = region + r.Endpoint = endpoint + r.S3ForcePathStyle = forcePathStyle r.Bucket = bucket r.Path = path diff --git a/s3/s3.go b/s3/s3.go index 5897320..9d34a02 100644 --- a/s3/s3.go +++ b/s3/s3.go @@ -69,9 +69,11 @@ type Replica struct { SecretAccessKey string // S3 bucket information - Region string - Bucket string - Path string + Endpoint string + Region string + Bucket string + Path string + S3ForcePathStyle bool // Time between syncs with the shadow WAL. SyncInterval time.Duration @@ -657,6 +659,8 @@ func (r *Replica) Init(ctx context.Context) (err error) { // Create new AWS session. config := r.config() config.Region = aws.String(region) + config.Endpoint = aws.String(r.Endpoint) + config.S3ForcePathStyle = aws.Bool(r.S3ForcePathStyle) sess, err := session.NewSession(config) if err != nil { return fmt.Errorf("cannot create aws session: %w", err) -- 2.30.0