From 5447c1528005cb1b1d5e725fd27fd48e2be302c4 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 25 Jan 2016 02:12:13 -0800 Subject: [PATCH] make_bucket: Make bucket should be done only as path style. --- minio/api.py | 9 +++++++-- tests/functional/tests.py | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/minio/api.py b/minio/api.py index d54b1145e..38127cb8a 100644 --- a/minio/api.py +++ b/minio/api.py @@ -209,9 +209,14 @@ def make_bucket(self, bucket_name, location='us-east-1', acl=None): content_md5_base64 = encode_to_base64(get_md5(content)) headers['Content-MD5'] = content_md5_base64 + # In case of Amazon S3. The make bucket issued on already + # existing bucket would fail with 'AuthorizationMalformed' + # error if virtual style is used. So we default to 'path + # style' as that is the preferred method here. The final + # location of the 'bucket' is provided through XML + # LocationConstraint data with the request. # Construct target url. - url = get_target_url(self._endpoint_url, - bucket_name=bucket_name) + url = self._endpoint_url + '/' + bucket_name + '/' # Get signature headers if any. headers = sign_v4(method, url, 'us-east-1', diff --git a/tests/functional/tests.py b/tests/functional/tests.py index 192429133..dcaac2ec1 100644 --- a/tests/functional/tests.py +++ b/tests/functional/tests.py @@ -56,6 +56,16 @@ def main(): print(client.make_bucket(bucket_name+'.unique', location='us-west-1')) + ## Check if return codes a valid from server. + try: + client.make_bucket(bucket_name+'.unique', + location='us-west-1') + except ResponseError as err: + if str(err.code) in ['BucketAlreadyOwnedByYou', 'BucketAlreadyExists']: + pass + else: + raise + # Check if bucket was created properly. print(client.bucket_exists(bucket_name)) print(client.bucket_exists(bucket_name+'.unique'))