summaryrefslogtreecommitdiffstats
path: root/swift/1.4.8/plugins/constraints.py
diff options
context:
space:
mode:
authorPeter Portante <peter.portante@redhat.com>2012-10-16 23:27:21 -0400
committerAnand Avati <avati@redhat.com>2012-10-17 11:04:05 -0700
commitdbe793bcde5d0ba936eceb19bcb8a6f376a0dbc4 (patch)
treeff281eec3636f11366bc89ee2b82f865d54814b5 /swift/1.4.8/plugins/constraints.py
parent59dfcf15578e08731f80c1f0c88cd4b7cd79d23d (diff)
object-storage: Refactor code to reduce Swift diffs carried
The upstream Swift code base contains the following commit which adds the ability to modify constraint values using the swift.conf file: https://github.com/openstack/swift/commit/a2ac5efaa64f57fbbe059066c6c4636dfd0715c2 These changes rely on the above commit being back-ported to Swift 1.4.8 (see https://github.com/portante/swift/commit/fc2421b04022ac6bbe9d5014362ec5f99f94c5e0). As a result, a good number of differences we carry can be removed, since the provided swift.conf file now contains the values we need. Along with these changes, we add middleware to get constraints loaded properly (via monkey patching) until subclassing is implemented in a future commit. We further simplify the diffs to a minimal set by storing the timestamp in file system metadata and moving new files to the plugins/middleware directory. Note that the original "gluster" middleware was in the swift.diff file, and has been renamed to "glusterfs" and moved to the new plugins/middleware directory. The "gluster" middleware is now a temporary way to get the constraints properly loaded (both of these middleware pieces should disappear in future commits when we refactor further to subclass the Swift objects instead of patching them). Change-Id: I9dc00d6b6cdd64e277896d75c2fb06431c3e69cb BUG: 862052 Signed-off-by: Peter Portante <peter.portante@redhat.com> Reviewed-on: http://review.gluster.org/4093 Tested-by: Peter Portante <pportant@redhat.com> Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'swift/1.4.8/plugins/constraints.py')
-rw-r--r--swift/1.4.8/plugins/constraints.py98
1 files changed, 30 insertions, 68 deletions
diff --git a/swift/1.4.8/plugins/constraints.py b/swift/1.4.8/plugins/constraints.py
index 26640717684..d522090829f 100644
--- a/swift/1.4.8/plugins/constraints.py
+++ b/swift/1.4.8/plugins/constraints.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2011 Red Hat, Inc.
+# Copyright (c) 2012 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -13,46 +13,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import os
-import logging
-from swift.common.constraints import check_utf8, check_metadata
+import swift.common.constraints
-from webob.exc import HTTPBadRequest, HTTPLengthRequired, \
- HTTPRequestEntityTooLarge
+MAX_OBJECT_NAME_COMPONENT_LENGTH = swift.common.constraints.constraints_conf_int(
+ 'max_object_name_component_length', 255)
-
-#: Max file size allowed for objects
-MAX_FILE_SIZE = 0xffffffffffffffff
-#: Max length of the name of a key for metadata
-MAX_META_NAME_LENGTH = 128
-#: Max length of the value of a key for metadata
-MAX_META_VALUE_LENGTH = 256
-#: Max number of metadata items
-MAX_META_COUNT = 90
-#: Max overall size of metadata
-MAX_META_OVERALL_SIZE = 4096
-#: Max object name length
-MAX_OBJECT_NAME_LENGTH = 255
-#: Max object list length of a get request for a container
-CONTAINER_LISTING_LIMIT = 10000
-#: Max container list length of a get request for an account
-ACCOUNT_LISTING_LIMIT = 10000
-MAX_ACCOUNT_NAME_LENGTH = 255
-MAX_CONTAINER_NAME_LENGTH = 255
-
-def validate_obj_name(obj):
- if len(obj) > MAX_OBJECT_NAME_LENGTH:
- logging.error('Object name too long %s' % obj)
- return False
+def validate_obj_name_component(obj):
+ if len(obj) > MAX_OBJECT_NAME_COMPONENT_LENGTH:
+ return 'too long (%d)' % len(obj)
if obj == '.' or obj == '..':
- logging.error('Object name cannot be . or .. %s' % obj)
- return False
+ return 'cannot be . or ..'
+ return ''
- return True
+# Save the original
+__check_object_creation = swift.common.constraints.check_object_creation
-def check_object_creation(req, object_name):
+# Define our new one which invokes the original
+def gluster_check_object_creation(req, object_name):
"""
Check to ensure that everything is alright about an object to be created.
+ Monkey patches swift.common.constraints.check_object_creation, invoking
+ the original, and then adding an additional check for individual object
+ name components.
:param req: HTTP request object
:param object_name: name of object to be created
@@ -62,38 +44,18 @@ def check_object_creation(req, object_name):
:raises HTTPBadRequest: missing or bad content-type header, or
bad metadata
"""
- if req.content_length and req.content_length > MAX_FILE_SIZE:
- return HTTPRequestEntityTooLarge(body='Your request is too large.',
- request=req,
- content_type='text/plain')
- if req.content_length is None and \
- req.headers.get('transfer-encoding') != 'chunked':
- return HTTPLengthRequired(request=req)
- if 'X-Copy-From' in req.headers and req.content_length:
- return HTTPBadRequest(body='Copy requests require a zero byte body',
- request=req, content_type='text/plain')
- for obj in object_name.split('/'):
- if not validate_obj_name(obj):
- return HTTPBadRequest(body='Invalid object name %s' %
- (obj), request=req,
- content_type='text/plain')
- if 'Content-Type' not in req.headers:
- return HTTPBadRequest(request=req, content_type='text/plain',
- body='No content type')
- if not check_utf8(req.headers['Content-Type']):
- return HTTPBadRequest(request=req, body='Invalid Content-Type',
- content_type='text/plain')
- if 'x-object-manifest' in req.headers:
- value = req.headers['x-object-manifest']
- container = prefix = None
- try:
- container, prefix = value.split('/', 1)
- except ValueError:
- pass
- if not container or not prefix or '?' in value or '&' in value or \
- prefix[0] == '/':
- return HTTPBadRequest(
- request=req,
- body='X-Object-Manifest must in the format container/prefix')
- return check_metadata(req, 'object')
+ ret = __check_object_creation(req, object_name)
+
+ if ret is None:
+ for obj in object_name.split('/'):
+ reason = validate_obj_name(obj)
+ if reason:
+ bdy = 'Invalid object name "%s", component "%s" %s' \
+ % (object_name, obj, reason)
+ ret = HTTPBadRequest(body=bdy,
+ request=req,
+ content_type='text/plain')
+
+ return ret
+swift.common.constraints.check_object_creation = gluster_check_object_creation