From 7e450c5c4b4d4269ab0fe2d9b52cb9bdbea2a4eb Mon Sep 17 00:00:00 2001 From: MORITA Kazutaka Date: Mon, 11 Aug 2014 23:41:21 +0900 Subject: [PATCH] Unfold add_canonical_user() The helper hides the output XML structure. Unfolding it makes the code a bit easier to read. Change-Id: I028f17d469c4d21e8ba52924dcc1be06108c0dd9 --- swift3/controllers/acl.py | 20 ++++++-------------- swift3/controllers/bucket.py | 6 ++++-- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/swift3/controllers/acl.py b/swift3/controllers/acl.py index 603a58a4..0940ce95 100644 --- a/swift3/controllers/acl.py +++ b/swift3/controllers/acl.py @@ -26,31 +26,23 @@ XMLNS_XSI = 'http://www.w3.org/2001/XMLSchema-instance' MAX_ACL_BODY_SIZE = 200 * 1024 -def add_canonical_user(parent, tag, user, nsmap=None): - """ - Create an element for cannonical user. - """ - elem = SubElement(parent, tag, nsmap=nsmap) - SubElement(elem, 'ID').text = user - SubElement(elem, 'DisplayName').text = user - - return elem - - def get_acl(account_name, headers): """ Attempts to construct an S3 ACL based on what is found in the swift headers """ elem = Element('AccessControlPolicy') - add_canonical_user(elem, 'Owner', account_name) + owner = SubElement(elem, 'Owner') + SubElement(owner, 'ID').text = account_name + SubElement(owner, 'DisplayName').text = account_name access_control_list = SubElement(elem, 'AccessControlList') # grant FULL_CONTROL to myself by default grant = SubElement(access_control_list, 'Grant') - grantee = add_canonical_user(grant, 'Grantee', account_name, - nsmap={'xsi': XMLNS_XSI}) + grantee = SubElement(grant, 'Grantee', nsmap={'xsi': XMLNS_XSI}) grantee.set('{%s}type' % XMLNS_XSI, 'CanonicalUser') + SubElement(grantee, 'ID').text = account_name + SubElement(grantee, 'DisplayName').text = account_name SubElement(grant, 'Permission').text = 'FULL_CONTROL' referrers, _ = parse_acl(headers.get('x-container-read')) diff --git a/swift3/controllers/bucket.py b/swift3/controllers/bucket.py index 4a606040..5d0f44be 100644 --- a/swift3/controllers/bucket.py +++ b/swift3/controllers/bucket.py @@ -18,7 +18,7 @@ from simplejson import loads from swift.common.http import HTTP_OK from swift3.controllers.base import Controller -from swift3.controllers.acl import add_canonical_user, swift_acl_translate +from swift3.controllers.acl import swift_acl_translate from swift3.etree import Element, SubElement, tostring, fromstring, \ XMLSyntaxError, DocumentInvalid from swift3.response import HTTPOk, S3NotImplemented, InvalidArgument, \ @@ -87,7 +87,9 @@ class BucketController(Controller): o['last_modified'] + 'Z' SubElement(contents, 'ETag').text = o['hash'] SubElement(contents, 'Size').text = str(o['bytes']) - add_canonical_user(contents, 'Owner', req.user_id) + owner = SubElement(contents, 'Owner') + SubElement(owner, 'ID').text = req.user_id + SubElement(owner, 'DisplayName').text = req.user_id SubElement(contents, 'StorageClass').text = 'STANDARD' for o in objects[:max_keys]: