@@ -12,6 +12,7 @@ from oauth2client.service_account import ServiceAccountCredentials
12
12
from gcloud .storage .client import Client
13
13
from gcloud import exceptions
14
14
from azure .storage .blob import BlobService
15
+ from urllib .parse import urlparse
15
16
16
17
def bucket_exists (conn , name ):
17
18
bucket = conn .lookup (name )
@@ -23,25 +24,22 @@ bucket_name = os.getenv('BUCKET_NAME')
23
24
region = os .getenv ('S3_REGION' )
24
25
25
26
if os .getenv ('DATABASE_STORAGE' ) == "s3" :
26
- conn = boto .s3 .connect_to_region (region )
27
+ if os .getenv ('S3_ENDPOINT' ):
28
+ endpoint = urlparse (os .getenv ('S3_ENDPOINT' ))
29
+ conn = boto .s3 .connect_to_region (region ,
30
+ host = endpoint .hostname ,
31
+ port = endpoint .port ,
32
+ path = endpoint .path ,
33
+ calling_format = boto .s3 .connection .OrdinaryCallingFormat ())
34
+ else :
35
+ conn = boto .s3 .connect_to_region (region )
36
+
27
37
if not bucket_exists (conn , bucket_name ):
28
- try :
29
- if region == "us-east-1" :
30
- # use "US Standard" region. workaround for https://github.com/boto/boto3/issues/125
31
- conn .create_bucket (bucket_name )
32
- else :
33
- conn .create_bucket (bucket_name , location = region )
34
- # NOTE(bacongobbler): for versions prior to v2.9.0, the bucket is created in the default region.
35
- # if we got here, we need to propagate "us-east-1" into WALE_S3_ENDPOINT because the bucket
36
- # exists in a different region and we cannot find it.
37
- # TODO(bacongobbler): deprecate this once we drop support for v2.8.0 and lower
38
- except S3CreateError as err :
39
- if region != 'us-east-1' :
40
- print ('Failed to create bucket in {}. We are now assuming that the bucket was created in us-east-1.' .format (region ))
41
- with open (os .path .join (os .environ ['WALE_ENVDIR' ], "WALE_S3_ENDPOINT" ), "w+" ) as file :
42
- file .write ('https+path://s3.amazonaws.com:443' )
43
- else :
44
- raise
38
+ if region == "us-east-1" :
39
+ # use "US Standard" region. workaround for https://github.com/boto/boto3/issues/125
40
+ conn .create_bucket (bucket_name )
41
+ else :
42
+ conn .create_bucket (bucket_name , location = region )
45
43
46
44
elif os .getenv ('DATABASE_STORAGE' ) == "gcs" :
47
45
scopes = ['https://www.googleapis.com/auth/devstorage.full_control' ]
0 commit comments