From 818e5bc444e0d3a747110762d67d085be808de1f Mon Sep 17 00:00:00 2001 From: Alexander Lauster Date: Sun, 23 Jun 2019 13:03:31 +0200 Subject: [PATCH 1/4] Add SSL CA Certificates to the image to allow access to S3 Buckets with active HTTPS --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 822e875..25661aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,7 @@ FROM scratch AS final LABEL maintainer="Andrea Spacca " COPY --from=build /go/bin/transfersh /go/bin/transfersh +COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt ENTRYPOINT ["/go/bin/transfersh", "--listener", ":8080"] From 47d4907a0651bca6e775000e7934595fb24a0823 Mon Sep 17 00:00:00 2001 From: Alexander Lauster Date: Sun, 23 Jun 2019 13:04:37 +0200 Subject: [PATCH 2/4] Add option to set the S3 region to support other regions as eu-west-1 --- cmd/cmd.go | 8 +++++++- server/storage.go | 4 ++-- server/utils.go | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 59ab981..1d42e00 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -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)) diff --git a/server/storage.go b/server/storage.go index 4527279..684f956 100644 --- a/server/storage.go +++ b/server/storage.go @@ -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 } diff --git a/server/utils.go b/server/utils.go index a01b423..86758e9 100644 --- a/server/utils.go +++ b/server/utils.go @@ -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, ""), })) From cb17b4a1ccc5c521b540b5ba1912c86239558d66 Mon Sep 17 00:00:00 2001 From: Alexander Lauster Date: Sun, 23 Jun 2019 20:40:18 +0200 Subject: [PATCH 3/4] Remove default endpoint because S3 SDK is automatically set the correct one based on the region --- cmd/cmd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 1d42e00..5950a39 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -99,7 +99,7 @@ var globalFlags = []cli.Flag{ cli.StringFlag{ Name: "s3-endpoint", Usage: "", - Value: "http://s3-eu-west-1.amazonaws.com", + Value: "", EnvVar: "S3_ENDPOINT", }, cli.StringFlag{ From e5e411cdaace0094827abce9797d2916c8c86aee Mon Sep 17 00:00:00 2001 From: Alexander Lauster Date: Sun, 23 Jun 2019 20:48:52 +0200 Subject: [PATCH 4/4] Add new options to Readme --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 89509ca..dc151ed 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,7 @@ provider | which storage provider to use | (s3, grdrive or local) | aws-access-key | aws access key | | AWS_ACCESS_KEY aws-secret-key | aws access key | | AWS_SECRET_KEY bucket | aws bucket | | BUCKET +s3-region | region of the s3 bucket | eu-west-1 | S3_REGION s3-no-multipart | disables s3 multipart upload | false | | basedir | path storage for local/gdrive provider| | gdrive-client-json-filepath | path to oauth client json config for gdrive provider| | @@ -202,6 +203,21 @@ For easy deployment, we've created a Docker container. docker run --publish 8080:8080 dutchcoders/transfer.sh:latest --provider local --basedir /tmp/ ``` +## S3 Usage + +For the usage with a AWS S3 Bucket, you just need to specify the following options: +- provider +- aws-access-key +- aws-secret-key +- bucket +- s3-region + +If you specify the s3-region, you don't need to set the endpoint URL since the correct endpoint will used automatically. + +### Custom S3 providers + +To use a custom non-AWS S3 provider, you need to specify the endpoint as definied from your cloud provider. + ## Contributions Contributions are welcome.