mirror of
https://github.com/dutchcoders/transfer.sh.git
synced 2020-11-18 19:53:40 -08:00
Add option to set the S3 region to support other regions as eu-west-1
This commit is contained in:
parent
818e5bc444
commit
47d4907a06
@ -102,6 +102,12 @@ var globalFlags = []cli.Flag{
|
||||
Value: "http://s3-eu-west-1.amazonaws.com",
|
||||
EnvVar: "S3_ENDPOINT",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "s3-region",
|
||||
Usage: "",
|
||||
Value: "eu-west-1",
|
||||
EnvVar: "S3_REGION",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "aws-access-key",
|
||||
Usage: "",
|
||||
@ -332,7 +338,7 @@ func New() *Cmd {
|
||||
panic("secret-key not set.")
|
||||
} else if bucket := c.String("bucket"); bucket == "" {
|
||||
panic("bucket not set.")
|
||||
} else if storage, err := server.NewS3Storage(accessKey, secretKey, bucket, c.String("s3-endpoint"), logger, c.Bool("s3-no-multipart")); err != nil {
|
||||
} else if storage, err := server.NewS3Storage(accessKey, secretKey, bucket, c.String("s3-endpoint"), logger, c.Bool("s3-no-multipart"), c.String("s3-region")); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
options = append(options, server.UseStorage(storage))
|
||||
|
@ -132,8 +132,8 @@ type S3Storage struct {
|
||||
noMultipart bool
|
||||
}
|
||||
|
||||
func NewS3Storage(accessKey, secretKey, bucketName, endpoint string, logger *log.Logger, disableMultipart bool) (*S3Storage, error) {
|
||||
sess := getAwsSession(accessKey, secretKey, endpoint)
|
||||
func NewS3Storage(accessKey, secretKey, bucketName, endpoint string, logger *log.Logger, disableMultipart bool, region string) (*S3Storage, error) {
|
||||
sess := getAwsSession(accessKey, secretKey, endpoint, region)
|
||||
|
||||
return &S3Storage{bucket: bucketName, s3: s3.New(sess), session: sess, logger: logger, noMultipart: disableMultipart}, nil
|
||||
}
|
||||
|
@ -37,9 +37,9 @@ import (
|
||||
"github.com/golang/gddo/httputil/header"
|
||||
)
|
||||
|
||||
func getAwsSession(accessKey, secretKey, endpoint string) *session.Session {
|
||||
func getAwsSession(accessKey, secretKey, endpoint string, region string) *session.Session {
|
||||
return session.Must(session.NewSession(&aws.Config{
|
||||
Region: aws.String("eu-west-1"),
|
||||
Region: aws.String(region),
|
||||
Endpoint: aws.String(endpoint),
|
||||
Credentials: credentials.NewStaticCredentials(accessKey, secretKey, ""),
|
||||
}))
|
||||
|
Loading…
x
Reference in New Issue
Block a user