Merge pull request #89 from kamaln7/master

Implement support for custom s3 endpoints
This commit is contained in:
Remco Verhoef 2017-09-20 13:14:31 +02:00 committed by GitHub
commit 6a6cce7c28
3 changed files with 11 additions and 5 deletions

View file

@ -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))

View file

@ -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
}

View file

@ -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,