Skip to content

Commit ce043ef

Browse files
authored
Merge pull request #249 from n8225/addS3PathStyle
Add support for S3 path style URLS.
2 parents 58edf68 + 6cb2de3 commit ce043ef

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ aws-secret-key | aws access key | | AWS_SECRET_KEY
165165
bucket | aws bucket | | BUCKET
166166
s3-region | region of the s3 bucket | eu-west-1 | S3_REGION
167167
s3-no-multipart | disables s3 multipart upload | false | |
168+
s3-path-style | Forces path style URLs, required for Minio. | false | |
168169
basedir | path storage for local/gdrive provider| |
169170
gdrive-client-json-filepath | path to oauth client json config for gdrive provider| |
170171
gdrive-local-config-path | path to store local transfer.sh config cache for gdrive provider| |

Diff for: cmd/cmd.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ var globalFlags = []cli.Flag{
130130
Name: "s3-no-multipart",
131131
Usage: "Disables S3 Multipart Puts",
132132
},
133+
cli.BoolFlag{
134+
Name: "s3-path-style",
135+
Usage: "Forces path style URLs, required for Minio.",
136+
},
133137
cli.StringFlag{
134138
Name: "gdrive-client-json-filepath",
135139
Usage: "",
@@ -339,7 +343,7 @@ func New() *Cmd {
339343
panic("secret-key not set.")
340344
} else if bucket := c.String("bucket"); bucket == "" {
341345
panic("bucket not set.")
342-
} else if storage, err := server.NewS3Storage(accessKey, secretKey, bucket, c.String("s3-region"), c.String("s3-endpoint"), logger, c.Bool("s3-no-multipart")); err != nil {
346+
} else if storage, err := server.NewS3Storage(accessKey, secretKey, bucket, c.String("s3-region"), c.String("s3-endpoint"), logger, c.Bool("s3-no-multipart"), c.Bool("s3-path-style")); err != nil {
343347
panic(err)
344348
} else {
345349
options = append(options, server.UseStorage(storage))

Diff for: server/storage.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ package server
33
import (
44
"encoding/json"
55
"fmt"
6-
"github.com/aws/aws-sdk-go/aws"
7-
"github.com/aws/aws-sdk-go/aws/awserr"
8-
"github.com/aws/aws-sdk-go/aws/session"
9-
"github.com/aws/aws-sdk-go/service/s3/s3manager"
106
"io"
117
"io/ioutil"
128
"log"
@@ -16,7 +12,11 @@ import (
1612
"path/filepath"
1713
"strings"
1814

15+
"github.com/aws/aws-sdk-go/aws"
16+
"github.com/aws/aws-sdk-go/aws/awserr"
17+
"github.com/aws/aws-sdk-go/aws/session"
1918
"github.com/aws/aws-sdk-go/service/s3"
19+
"github.com/aws/aws-sdk-go/service/s3/s3manager"
2020
"golang.org/x/net/context"
2121
"golang.org/x/oauth2"
2222
"golang.org/x/oauth2/google"
@@ -132,8 +132,8 @@ type S3Storage struct {
132132
noMultipart bool
133133
}
134134

135-
func NewS3Storage(accessKey, secretKey, bucketName, region, endpoint string, logger *log.Logger, disableMultipart bool) (*S3Storage, error) {
136-
sess := getAwsSession(accessKey, secretKey, region, endpoint)
135+
func NewS3Storage(accessKey, secretKey, bucketName, region, endpoint string, logger *log.Logger, disableMultipart bool, forcePathStyle bool) (*S3Storage, error) {
136+
sess := getAwsSession(accessKey, secretKey, region, endpoint, forcePathStyle)
137137

138138
return &S3Storage{bucket: bucketName, s3: s3.New(sess), session: sess, logger: logger, noMultipart: disableMultipart}, nil
139139
}

Diff for: server/utils.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,24 @@ THE SOFTWARE.
2525
package server
2626

2727
import (
28-
"github.com/aws/aws-sdk-go/aws/credentials"
2928
"math"
3029
"net/http"
3130
"net/mail"
3231
"strconv"
3332
"strings"
3433

3534
"github.com/aws/aws-sdk-go/aws"
35+
"github.com/aws/aws-sdk-go/aws/credentials"
3636
"github.com/aws/aws-sdk-go/aws/session"
3737
"github.com/golang/gddo/httputil/header"
3838
)
3939

40-
func getAwsSession(accessKey, secretKey, region, endpoint string) *session.Session {
40+
func getAwsSession(accessKey, secretKey, region, endpoint string, forcePathStyle bool) *session.Session {
4141
return session.Must(session.NewSession(&aws.Config{
42-
Region: aws.String(region),
43-
Endpoint: aws.String(endpoint),
44-
Credentials: credentials.NewStaticCredentials(accessKey, secretKey, ""),
42+
Region: aws.String(region),
43+
Endpoint: aws.String(endpoint),
44+
Credentials: credentials.NewStaticCredentials(accessKey, secretKey, ""),
45+
S3ForcePathStyle: aws.Bool(forcePathStyle),
4546
}))
4647
}
4748

0 commit comments

Comments
 (0)