Skip to content

Commit

Permalink
Merge "quotas: Move account-level handling to a separate function"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and openstack-gerrit committed Mar 8, 2023
2 parents a295296 + 21b3f1a commit 28cb0c3
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions swift/common/middleware/account_quotas.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ class AccountQuotaMiddleware(object):
def __init__(self, app, *args, **kwargs):
self.app = app

def handle_account(self, request):
# account request, so we pay attention to the quotas
new_quota = request.headers.get(
'X-Account-Meta-Quota-Bytes')
if request.headers.get(
'X-Remove-Account-Meta-Quota-Bytes'):
new_quota = 0 # X-Remove dominates if both are present

if request.environ.get('reseller_request') is True:
if new_quota and not new_quota.isdigit():
return HTTPBadRequest()
return self.app

# deny quota set for non-reseller
if new_quota is not None:
return HTTPForbidden()
return self.app

@wsgify
def __call__(self, request):

Expand All @@ -80,29 +98,16 @@ def __call__(self, request):
return self.app

if not container:
# account request, so we pay attention to the quotas
new_quota = request.headers.get(
'X-Account-Meta-Quota-Bytes')
remove_quota = request.headers.get(
'X-Remove-Account-Meta-Quota-Bytes')
else:
# container or object request; even if the quota headers are set
# in the request, they're meaningless
new_quota = remove_quota = None

if remove_quota:
new_quota = 0 # X-Remove dominates if both are present
return self.handle_account(request)
# container or object request; even if the quota headers are set
# in the request, they're meaningless

if request.environ.get('reseller_request') is True:
if new_quota and not new_quota.isdigit():
return HTTPBadRequest()
if request.method == "POST" or not obj:
return self.app
# OK, object PUT

# deny quota set for non-reseller
if new_quota is not None:
return HTTPForbidden()

if request.method == "POST" or not obj:
if request.environ.get('reseller_request') is True:
# but resellers aren't constrained by quotas :-)
return self.app

content_length = (request.content_length or 0)
Expand Down

0 comments on commit 28cb0c3

Please sign in to comment.