mirror of
https://github.com/dutchcoders/transfer.sh.git
synced 2024-11-23 04:30:19 +01:00
Merge pull request #89 from kamaln7/master
Implement support for custom s3 endpoints
This commit is contained in:
commit
6a6cce7c28
3 changed files with 11 additions and 5 deletions
|
@ -77,6 +77,12 @@ var globalFlags = []cli.Flag{
|
||||||
Usage: "s3|local",
|
Usage: "s3|local",
|
||||||
Value: "",
|
Value: "",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "s3-endpoint",
|
||||||
|
Usage: "",
|
||||||
|
Value: "http://s3-eu-west-1.amazonaws.com",
|
||||||
|
EnvVar: "S3_ENDPOINT",
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "aws-access-key",
|
Name: "aws-access-key",
|
||||||
Usage: "",
|
Usage: "",
|
||||||
|
@ -222,7 +228,7 @@ func New() *Cmd {
|
||||||
panic("secret-key not set.")
|
panic("secret-key not set.")
|
||||||
} else if bucket := c.String("bucket"); bucket == "" {
|
} else if bucket := c.String("bucket"); bucket == "" {
|
||||||
panic("bucket not set.")
|
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)
|
panic(err)
|
||||||
} else {
|
} else {
|
||||||
options = append(options, server.UseStorage(storage))
|
options = append(options, server.UseStorage(storage))
|
||||||
|
|
|
@ -108,8 +108,8 @@ type S3Storage struct {
|
||||||
bucket *s3.Bucket
|
bucket *s3.Bucket
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewS3Storage(accessKey, secretKey, bucketName string) (*S3Storage, error) {
|
func NewS3Storage(accessKey, secretKey, bucketName, endpoint string) (*S3Storage, error) {
|
||||||
bucket, err := getBucket(accessKey, secretKey, bucketName)
|
bucket, err := getBucket(accessKey, secretKey, bucketName, endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ import (
|
||||||
"github.com/golang/gddo/httputil/header"
|
"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{})
|
auth, err := aws.GetAuth(accessKey, secretKey, "", time.Time{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -46,7 +46,7 @@ func getBucket(accessKey, secretKey, bucket string) (*s3.Bucket, error) {
|
||||||
var EUWestWithoutHTTPS = aws.Region{
|
var EUWestWithoutHTTPS = aws.Region{
|
||||||
Name: "eu-west-1",
|
Name: "eu-west-1",
|
||||||
EC2Endpoint: "https://ec2.eu-west-1.amazonaws.com",
|
EC2Endpoint: "https://ec2.eu-west-1.amazonaws.com",
|
||||||
S3Endpoint: "http://s3-eu-west-1.amazonaws.com",
|
S3Endpoint: endpoint,
|
||||||
S3BucketEndpoint: "",
|
S3BucketEndpoint: "",
|
||||||
S3LocationConstraint: true,
|
S3LocationConstraint: true,
|
||||||
S3LowercaseBucket: true,
|
S3LowercaseBucket: true,
|
||||||
|
|
Loading…
Reference in a new issue