Merge "Move x-amz-acl header handling into acl.py"
This commit is contained in:
@@ -17,7 +17,8 @@ from swift.common.http import HTTP_OK
|
|||||||
from swift.common.middleware.acl import parse_acl, referrer_allowed
|
from swift.common.middleware.acl import parse_acl, referrer_allowed
|
||||||
|
|
||||||
from swift3.controllers.base import Controller
|
from swift3.controllers.base import Controller
|
||||||
from swift3.response import HTTPOk, S3NotImplemented, MalformedACLError
|
from swift3.response import HTTPOk, S3NotImplemented, MalformedACLError, \
|
||||||
|
InvalidArgument
|
||||||
from swift3.etree import Element, SubElement, fromstring, tostring, \
|
from swift3.etree import Element, SubElement, fromstring, tostring, \
|
||||||
XMLSyntaxError, DocumentInvalid
|
XMLSyntaxError, DocumentInvalid
|
||||||
|
|
||||||
@@ -120,6 +121,28 @@ def swift_acl_translate(acl, group='', user='', xml=False):
|
|||||||
return swift_acl[acl]
|
return swift_acl[acl]
|
||||||
|
|
||||||
|
|
||||||
|
def handle_acl_header(req):
|
||||||
|
"""
|
||||||
|
Handle the x-amz-acl header.
|
||||||
|
"""
|
||||||
|
amz_acl = req.environ['HTTP_X_AMZ_ACL']
|
||||||
|
# Translate the Amazon ACL to something that can be
|
||||||
|
# implemented in Swift, 501 otherwise. Swift uses POST
|
||||||
|
# for ACLs, whereas S3 uses PUT.
|
||||||
|
del req.environ['HTTP_X_AMZ_ACL']
|
||||||
|
if req.query_string:
|
||||||
|
req.query_string = ''
|
||||||
|
|
||||||
|
translated_acl = swift_acl_translate(amz_acl)
|
||||||
|
if translated_acl == 'NotImplemented':
|
||||||
|
raise S3NotImplemented()
|
||||||
|
elif translated_acl == 'InvalidArgument':
|
||||||
|
raise InvalidArgument('x-amz-acl', amz_acl)
|
||||||
|
|
||||||
|
for header, acl in translated_acl:
|
||||||
|
req.headers[header] = acl
|
||||||
|
|
||||||
|
|
||||||
class AclController(Controller):
|
class AclController(Controller):
|
||||||
"""
|
"""
|
||||||
Handles the following APIs:
|
Handles the following APIs:
|
||||||
@@ -148,6 +171,8 @@ class AclController(Controller):
|
|||||||
raise S3NotImplemented()
|
raise S3NotImplemented()
|
||||||
else:
|
else:
|
||||||
# Handle Bucket ACL
|
# Handle Bucket ACL
|
||||||
|
if 'HTTP_X_AMZ_ACL' in req.environ:
|
||||||
|
handle_acl_header(req)
|
||||||
|
|
||||||
# We very likely have an XML-based ACL request.
|
# We very likely have an XML-based ACL request.
|
||||||
translated_acl = swift_acl_translate(req.xml(MAX_ACL_BODY_SIZE),
|
translated_acl = swift_acl_translate(req.xml(MAX_ACL_BODY_SIZE),
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from simplejson import loads
|
|||||||
from swift.common.http import HTTP_OK
|
from swift.common.http import HTTP_OK
|
||||||
|
|
||||||
from swift3.controllers.base import Controller
|
from swift3.controllers.base import Controller
|
||||||
from swift3.controllers.acl import swift_acl_translate
|
from swift3.controllers.acl import handle_acl_header
|
||||||
from swift3.etree import Element, SubElement, tostring, fromstring, \
|
from swift3.etree import Element, SubElement, tostring, fromstring, \
|
||||||
XMLSyntaxError, DocumentInvalid
|
XMLSyntaxError, DocumentInvalid
|
||||||
from swift3.response import HTTPOk, S3NotImplemented, InvalidArgument, \
|
from swift3.response import HTTPOk, S3NotImplemented, InvalidArgument, \
|
||||||
@@ -106,22 +106,7 @@ class BucketController(Controller):
|
|||||||
Handle PUT Bucket request
|
Handle PUT Bucket request
|
||||||
"""
|
"""
|
||||||
if 'HTTP_X_AMZ_ACL' in req.environ:
|
if 'HTTP_X_AMZ_ACL' in req.environ:
|
||||||
amz_acl = req.environ['HTTP_X_AMZ_ACL']
|
handle_acl_header(req)
|
||||||
# Translate the Amazon ACL to something that can be
|
|
||||||
# implemented in Swift, 501 otherwise. Swift uses POST
|
|
||||||
# for ACLs, whereas S3 uses PUT.
|
|
||||||
del req.environ['HTTP_X_AMZ_ACL']
|
|
||||||
if req.query_string:
|
|
||||||
req.query_string = ''
|
|
||||||
|
|
||||||
translated_acl = swift_acl_translate(amz_acl)
|
|
||||||
if translated_acl == 'NotImplemented':
|
|
||||||
raise S3NotImplemented()
|
|
||||||
elif translated_acl == 'InvalidArgument':
|
|
||||||
raise InvalidArgument('x-amz-acl', amz_acl)
|
|
||||||
|
|
||||||
for header, acl in translated_acl:
|
|
||||||
req.headers[header] = acl
|
|
||||||
|
|
||||||
xml = req.xml(MAX_PUT_BUCKET_BODY_SIZE)
|
xml = req.xml(MAX_PUT_BUCKET_BODY_SIZE)
|
||||||
if xml:
|
if xml:
|
||||||
|
|||||||
Reference in New Issue
Block a user