@@ -12,6 +12,7 @@ from oauth2client.service_account import ServiceAccountCredentials
1212from gcloud .storage .client import Client
1313from gcloud import exceptions
1414from azure .storage .blob import BlobService
15+ from urllib .parse import urlparse
1516
1617def bucket_exists (conn , name ):
1718 bucket = conn .lookup (name )
@@ -23,25 +24,22 @@ bucket_name = os.getenv('BUCKET_NAME')
2324region = os .getenv ('S3_REGION' )
2425
2526if 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+
2737 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 )
4543
4644elif os .getenv ('DATABASE_STORAGE' ) == "gcs" :
4745 scopes = ['https://www.googleapis.com/auth/devstorage.full_control' ]
0 commit comments