From 69dacec7ad596324c3c1599268fbfb3f3bc89311 Mon Sep 17 00:00:00 2001 From: Kamal Nasser Date: Sun, 16 Jul 2017 16:19:41 +0300 Subject: [PATCH] implement support for custom s3 endpoints --- 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 5f6287b..9d9828b 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -77,6 +77,12 @@ var globalFlags = []cli.Flag{ Usage: "s3|local", Value: "", }, + cli.StringFlag{ + Name: "s3-endpoint", + Usage: "", + Value: "http://s3-eu-west-1.amazonaws.com", + EnvVar: "S3_ENDPOINT", + }, cli.StringFlag{ Name: "aws-access-key", Usage: "", @@ -222,7 +228,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); err != nil { + } else if storage, err := server.NewS3Storage(accessKey, secretKey, bucket, c.String("s3-endpoint")); err != nil { panic(err) } else { options = append(options, server.UseStorage(storage)) diff --git a/server/storage.go b/server/storage.go index 1c92771..b2813f1 100644 --- a/server/storage.go +++ b/server/storage.go @@ -108,8 +108,8 @@ type S3Storage struct { bucket *s3.Bucket } -func NewS3Storage(accessKey, secretKey, bucketName string) (*S3Storage, error) { - bucket, err := getBucket(accessKey, secretKey, bucketName) +func NewS3Storage(accessKey, secretKey, bucketName, endpoint string) (*S3Storage, error) { + bucket, err := getBucket(accessKey, secretKey, bucketName, endpoint) if err != nil { return nil, err } diff --git a/server/utils.go b/server/utils.go index 522b46c..d65b401 100644 --- a/server/utils.go +++ b/server/utils.go @@ -37,7 +37,7 @@ import ( "github.com/golang/gddo/httputil/header" ) -func getBucket(accessKey, secretKey, bucket string) (*s3.Bucket, error) { +func getBucket(accessKey, secretKey, bucket, endpoint string) (*s3.Bucket, error) { auth, err := aws.GetAuth(accessKey, secretKey, "", time.Time{}) if err != nil { return nil, err @@ -46,7 +46,7 @@ func getBucket(accessKey, secretKey, bucket string) (*s3.Bucket, error) { var EUWestWithoutHTTPS = aws.Region{ Name: "eu-west-1", EC2Endpoint: "https://ec2.eu-west-1.amazonaws.com", - S3Endpoint: "http://s3-eu-west-1.amazonaws.com", + S3Endpoint: endpoint, S3BucketEndpoint: "", S3LocationConstraint: true, S3LowercaseBucket: true,