Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle location constraints inside API methods #992

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions minio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from datetime import datetime, timedelta
from threading import Thread
from urllib.parse import urlunsplit
from xml.etree import ElementTree as ET

import certifi
import dateutil.parser
Expand All @@ -55,8 +56,7 @@
parse_get_bucket_notification, parse_list_buckets,
parse_list_multipart_uploads, parse_list_object_versions,
parse_list_objects, parse_list_objects_v2,
parse_list_parts, parse_location_constraint,
parse_multi_delete_response,
parse_list_parts, parse_multi_delete_response,
parse_multipart_upload_result,
parse_new_multipart_upload, parse_versioning_config)
from .replicationconfig import ReplicationConfig
Expand All @@ -65,11 +65,10 @@
post_presign_v4, presign_v4, sign_v4_s3)
from .sse import SseCustomerKey
from .thread_pool import ThreadPool
from .xml import marshal, unmarshal
from .xml import Element, SubElement, marshal, unmarshal
from .xml_marshal import (marshal_bucket_notifications,
marshal_complete_multipart,
marshal_versioning_config,
xml_marshal_bucket_constraint,
xml_marshal_bucket_encryption,
xml_marshal_delete_objects, xml_marshal_select,
xml_to_dict)
Expand Down Expand Up @@ -464,13 +463,13 @@ def _get_region(self, bucket_name, region):
query_params={"location": ""},
)

location = parse_location_constraint(response.data.decode())
if not location:
element = ET.fromstring(response.data.decode())
if not element.text:
region = "us-east-1"
elif location == "EU":
elif element.text == "EU":
region = "eu-west-1"
else:
region = location
region = element.text

self._region_map[bucket_name] = region
return region
Expand Down Expand Up @@ -587,10 +586,12 @@ def make_bucket(self, bucket_name, location=None, object_lock=False):
{"x-amz-bucket-object-lock-enabled": "true"}
if object_lock else None
)
body = (
None if location == "us-east-1"
else xml_marshal_bucket_constraint(location)
)

body = None
if location != "us-east-1":
element = Element("CreateBucketConfiguration")
SubElement(element, "LocationConstraint", location)
body = marshal(element)
self._url_open(
"PUT",
location,
Expand Down
11 changes: 0 additions & 11 deletions minio/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,17 +386,6 @@ def parse_new_multipart_upload(data):
return root.get_child_text('UploadId')


def parse_location_constraint(data):
"""
Parser for location constraint response.

:param data: Response data for get bucket location.
:return: Returns location of your bucket.
"""
root = S3Element.fromstring('BucketLocationConstraintResult', data)
return root.text()


def parse_get_bucket_notification(data):
"""
Parser for a get_bucket_notification response from S3.
Expand Down
12 changes: 0 additions & 12 deletions minio/xml_marshal.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,6 @@ def xml_marshal_bucket_encryption(rules):
return _get_xml_data(root)


def xml_marshal_bucket_constraint(region):
"""
Marshal's bucket constraint based on *region*.

:param region: Region name of a given bucket.
:return: Marshalled XML data.
"""
root = Element('CreateBucketConfiguration', with_namespace=True)
SubElement(root, 'LocationConstraint', region)
return _get_xml_data(root)


def xml_marshal_select(req):
"""Encode select request to XML."""

Expand Down
9 changes: 0 additions & 9 deletions tests/unit/generate_xml_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,10 @@
OutputSerialization, RequestProgress,
SelectObjectOptions)
from minio.xml_marshal import (marshal_complete_multipart,
xml_marshal_bucket_constraint,
xml_marshal_select)


class GenerateRequestTest(TestCase):
def test_generate_bucket_constraint(self):
expected_string = (b'<CreateBucketConfiguration '
b'xmlns="http://s3.amazonaws.com/doc/2006-03-01/">'
b'<LocationConstraint>region</LocationConstraint>'
b'</CreateBucketConfiguration>')
actual_string = xml_marshal_bucket_constraint('region')
eq_(expected_string, actual_string)

def test_generate_complete_multipart_upload(self):
expected_string = (b'<CompleteMultipartUpload '
b'xmlns="http://s3.amazonaws.com/doc/2006-03-01/">'
Expand Down