diff --git a/zaqar/common/transport/wsgi/helpers.py b/zaqar/common/transport/wsgi/helpers.py index 4eaf9fa40..e4376ebde 100644 --- a/zaqar/common/transport/wsgi/helpers.py +++ b/zaqar/common/transport/wsgi/helpers.py @@ -15,18 +15,36 @@ """wsgi transport helpers.""" +import uuid + import falcon import six from zaqar.i18n import _ import zaqar.openstack.common.log as logging from zaqar.queues.transport import validation -from zaqar.queues.transport.wsgi import utils LOG = logging.getLogger(__name__) +def get_client_uuid(req): + """Read a required Client-ID from a request. + + :param req: A falcon.Request object + :raises: HTTPBadRequest if the Client-ID header is missing or + does not represent a valid UUID + :returns: A UUID object + """ + + try: + return uuid.UUID(req.get_header('Client-ID', required=True)) + + except ValueError: + description = _(u'Malformed hexadecimal UUID.') + raise falcon.HTTPBadRequest('Wrong UUID value', description) + + def extract_project_id(req, resp, params): """Adds `project_id` to the list of params for all responders @@ -69,7 +87,7 @@ def require_client_id(req, resp, params): if 'v1.1' in req.path: # NOTE(flaper87): `get_client_uuid` already raises 400 # it the header is missing. - utils.get_client_uuid(req) + get_client_uuid(req) def validate_queue_identification(validate, req, resp, params): diff --git a/zaqar/queues/transport/wsgi/utils.py b/zaqar/queues/transport/wsgi/utils.py index aca1189a2..1b1c8b024 100644 --- a/zaqar/queues/transport/wsgi/utils.py +++ b/zaqar/queues/transport/wsgi/utils.py @@ -12,8 +12,6 @@ # License for the specific language governing permissions and limitations under # the License. -import uuid - import falcon import jsonschema @@ -180,23 +178,6 @@ def get_checked_field(document, name, value_type, default_value): raise errors.HTTPBadRequestBody(description) -def get_client_uuid(req): - """Read a required Client-ID from a request. - - :param req: A falcon.Request object - :raises: HTTPBadRequest if the Client-ID header is missing or - does not represent a valid UUID - :returns: A UUID object - """ - - try: - return uuid.UUID(req.get_header('Client-ID', required=True)) - - except ValueError: - description = _(u'Malformed hexadecimal UUID.') - raise errors.HTTPBadRequestAPI(description) - - def load(req): """Reads request body, raising an exception if it is not JSON. diff --git a/zaqar/queues/transport/wsgi/v1_0/messages.py b/zaqar/queues/transport/wsgi/v1_0/messages.py index e10b074a4..f6a3a8f2f 100644 --- a/zaqar/queues/transport/wsgi/v1_0/messages.py +++ b/zaqar/queues/transport/wsgi/v1_0/messages.py @@ -16,6 +16,7 @@ import falcon import six +from zaqar.common.transport.wsgi import helpers as wsgi_helpers from zaqar.i18n import _ import zaqar.openstack.common.log as logging from zaqar.queues.storage import errors as storage_errors @@ -68,7 +69,7 @@ class CollectionResource(object): return [_format_message(m, base_path) for m in messages] def _get(self, req, project_id, queue_name): - client_uuid = wsgi_utils.get_client_uuid(req) + client_uuid = wsgi_helpers.get_client_uuid(req) kwargs = {} # NOTE(kgriffs): This syntax ensures that @@ -130,7 +131,7 @@ class CollectionResource(object): u'project: %(project)s', {'queue': queue_name, 'project': project_id}) - client_uuid = wsgi_utils.get_client_uuid(req) + client_uuid = wsgi_helpers.get_client_uuid(req) try: # Place JSON size restriction before parsing diff --git a/zaqar/queues/transport/wsgi/v1_1/messages.py b/zaqar/queues/transport/wsgi/v1_1/messages.py index a3596d824..ca6a6fa50 100644 --- a/zaqar/queues/transport/wsgi/v1_1/messages.py +++ b/zaqar/queues/transport/wsgi/v1_1/messages.py @@ -16,6 +16,7 @@ import falcon import six +from zaqar.common.transport.wsgi import helpers as wsgi_helpers from zaqar.i18n import _ import zaqar.openstack.common.log as logging from zaqar.queues.storage import errors as storage_errors @@ -83,7 +84,7 @@ class CollectionResource(object): return {'messages': messages} def _get(self, req, project_id, queue_name): - client_uuid = wsgi_utils.get_client_uuid(req) + client_uuid = wsgi_helpers.get_client_uuid(req) kwargs = {} # NOTE(kgriffs): This syntax ensures that @@ -146,7 +147,7 @@ class CollectionResource(object): u'project: %(project)s', {'queue': queue_name, 'project': project_id}) - client_uuid = wsgi_utils.get_client_uuid(req) + client_uuid = wsgi_helpers.get_client_uuid(req) try: # Place JSON size restriction before parsing