summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Burke <tim.burke@gmail.com>2022-10-14 15:34:41 -0700
committerTim Burke <tim.burke@gmail.com>2023-02-17 10:09:32 -0800
commit21b3f1af98d34df6e56fcd2320615bdd2c3404bf (patch)
tree57e11b60293c8d08657bdfd3509373a98a76a498
parente76d443e00ae5f504bac4f109317fc489b5f1bc5 (diff)
downloadswift-21b3f1af98d34df6e56fcd2320615bdd2c3404bf.tar.gz
quotas: Move account-level handling to a separate function
Change-Id: I1ab7376b5e68a3deaad5aca113ad55bde00b2238
-rw-r--r--swift/common/middleware/account_quotas.py45
1 files changed, 25 insertions, 20 deletions
diff --git a/swift/common/middleware/account_quotas.py b/swift/common/middleware/account_quotas.py
index cd41e34da..cc2792fd4 100644
--- a/swift/common/middleware/account_quotas.py
+++ b/swift/common/middleware/account_quotas.py
@@ -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):
@@ -80,29 +98,16 @@ class AccountQuotaMiddleware(object):
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)