Skip to content

Commit

Permalink
s3: add bucket-lookup parameter to select path or dns style bucket lo…
Browse files Browse the repository at this point in the history
…okup

This is to enable restic working with Alibaba cloud

Fixes restic#2528
  • Loading branch information
ncw committed Jan 3, 2020
1 parent 6ec5dc8 commit de049ff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
7 changes: 4 additions & 3 deletions internal/backend/s3/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ type Config struct {
Layout string `option:"layout" help:"use this backend layout (default: auto-detect)"`
StorageClass string `option:"storage-class" help:"set S3 storage class (STANDARD, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING or REDUCED_REDUNDANCY)"`

Connections uint `option:"connections" help:"set a limit for the number of concurrent connections (default: 5)"`
MaxRetries uint `option:"retries" help:"set the number of retries attempted"`
Region string `option:"region" help:"set region"`
Connections uint `option:"connections" help:"set a limit for the number of concurrent connections (default: 5)"`
MaxRetries uint `option:"retries" help:"set the number of retries attempted"`
Region string `option:"region" help:"set region"`
BucketLookup string `option:"bucket-lookup" help:"bucket lookup style: 'auto', 'dns', or 'path'."`
}

// NewConfig returns a new Config with the default values filled in.
Expand Down
20 changes: 18 additions & 2 deletions internal/backend/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package s3

import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -66,9 +67,24 @@ func open(cfg Config, rt http.RoundTripper) (*Backend, error) {
},
},
})
client, err := minio.NewWithCredentials(cfg.Endpoint, creds, !cfg.UseHTTP, cfg.Region)
options := minio.Options{
Creds: creds,
Secure: !cfg.UseHTTP,
Region: cfg.Region,
}
switch strings.ToLower(cfg.BucketLookup) {
case "", "auto":
options.BucketLookup = minio.BucketLookupAuto
case "dns":
options.BucketLookup = minio.BucketLookupDNS
case "path":
options.BucketLookup = minio.BucketLookupPath
default:
return nil, fmt.Errorf(`bad bucket-lookup style %q must be "auto", "path" or "dns"`, cfg.BucketLookup)
}
client, err := minio.NewWithOptions(cfg.Endpoint, &options)
if err != nil {
return nil, errors.Wrap(err, "minio.NewWithCredentials")
return nil, errors.Wrap(err, "minio.NewWithOptions")
}

sem, err := backend.NewSemaphore(cfg.Connections)
Expand Down

0 comments on commit de049ff

Please sign in to comment.