Merge pull request #1512 from kmala/master

Added support to specifiy custom endpoint
This commit is contained in:
Brian Bland 2016-03-10 13:48:59 -08:00
commit 1d1d92469d
2 changed files with 45 additions and 21 deletions

View file

@ -60,6 +60,7 @@ type DriverParameters struct {
SecretKey string SecretKey string
Bucket string Bucket string
Region string Region string
RegionEndpoint string
Encrypt bool Encrypt bool
Secure bool Secure bool
ChunkSize int64 ChunkSize int64
@ -153,6 +154,11 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
return nil, fmt.Errorf("No bucket parameter provided") return nil, fmt.Errorf("No bucket parameter provided")
} }
regionEndpoint := parameters["regionendpoint"]
if regionEndpoint == nil {
regionEndpoint = ""
}
encryptBool := false encryptBool := false
encrypt := parameters["encrypt"] encrypt := parameters["encrypt"]
switch encrypt := encrypt.(type) { switch encrypt := encrypt.(type) {
@ -240,6 +246,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
fmt.Sprint(secretKey), fmt.Sprint(secretKey),
fmt.Sprint(bucket), fmt.Sprint(bucket),
region, region,
fmt.Sprint(regionEndpoint),
encryptBool, encryptBool,
secureBool, secureBool,
chunkSize, chunkSize,
@ -255,7 +262,9 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
// bucketName // bucketName
func New(params DriverParameters) (*Driver, error) { func New(params DriverParameters) (*Driver, error) {
awsConfig := aws.NewConfig() awsConfig := aws.NewConfig()
creds := credentials.NewChainCredentials([]credentials.Provider{ var creds *credentials.Credentials
if params.RegionEndpoint == "" {
creds = credentials.NewChainCredentials([]credentials.Provider{
&credentials.StaticProvider{ &credentials.StaticProvider{
Value: credentials.Value{ Value: credentials.Value{
AccessKeyID: params.AccessKey, AccessKeyID: params.AccessKey,
@ -267,10 +276,23 @@ func New(params DriverParameters) (*Driver, error) {
&ec2rolecreds.EC2RoleProvider{Client: ec2metadata.New(session.New())}, &ec2rolecreds.EC2RoleProvider{Client: ec2metadata.New(session.New())},
}) })
} else {
creds = credentials.NewChainCredentials([]credentials.Provider{
&credentials.StaticProvider{
Value: credentials.Value{
AccessKeyID: params.AccessKey,
SecretAccessKey: params.SecretKey,
},
},
&credentials.EnvProvider{},
})
awsConfig.WithS3ForcePathStyle(true)
awsConfig.WithEndpoint(params.RegionEndpoint)
}
awsConfig.WithCredentials(creds) awsConfig.WithCredentials(creds)
awsConfig.WithRegion(params.Region) awsConfig.WithRegion(params.Region)
awsConfig.WithDisableSSL(!params.Secure) awsConfig.WithDisableSSL(!params.Secure)
// awsConfig.WithMaxRetries(10)
if params.UserAgent != "" { if params.UserAgent != "" {
awsConfig.WithHTTPClient(&http.Client{ awsConfig.WithHTTPClient(&http.Client{

View file

@ -30,6 +30,7 @@ func init() {
secure := os.Getenv("S3_SECURE") secure := os.Getenv("S3_SECURE")
region := os.Getenv("AWS_REGION") region := os.Getenv("AWS_REGION")
root, err := ioutil.TempDir("", "driver-") root, err := ioutil.TempDir("", "driver-")
regionEndpoint := os.Getenv("REGION_ENDPOINT")
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -57,6 +58,7 @@ func init() {
secretKey, secretKey,
bucket, bucket,
region, region,
regionEndpoint,
encryptBool, encryptBool,
secureBool, secureBool,
minChunkSize, minChunkSize,