def _get(self, req, project_id, queue_name): uuid = req.get_header('Client-ID', required=True) # TODO(kgriffs): Optimize kwargs = helpers.purge({ 'marker': req.get_param('marker'), 'limit': req.get_param_as_int('limit'), 'echo': req.get_param_as_bool('echo'), }) try: results = self.message_controller.list( queue_name, project=project_id, client_uuid=uuid, **kwargs) # Buffer messages cursor = next(results) messages = list(cursor) except storage_exceptions.DoesNotExist: raise falcon.HTTPNotFound() except storage_exceptions.MalformedMarker: title = _('Invalid query string parameter') description = _('The value for the query string ' 'parameter "marker" could not be ' 'parsed. We recommend using the ' '"next" URI from a previous ' 'request directly, rather than ' 'constructing the URI manually. ') raise falcon.HTTPBadRequest(title, description) except Exception as ex: LOG.exception(ex) description = _('Messages could not be listed.') raise wsgi_exceptions.HTTPServiceUnavailable(description) if not messages: return None # Found some messages, so prepare the response kwargs['marker'] = next(results) for each_message in messages: each_message['href'] = req.path + '/' + each_message['id'] del each_message['id'] return { 'messages': messages, 'links': [ { 'rel': 'next', 'href': req.path + falcon.to_query_str(kwargs) } ] }
def on_get(self, req, resp, project_id): # TODO(kgriffs): Optimize kwargs = helpers.purge({ 'marker': req.get_param('marker'), 'limit': req.get_param_as_int('limit'), 'detailed': req.get_param_as_bool('detailed'), }) try: results = self.queue_controller.list(project=project_id, **kwargs) except Exception as ex: LOG.exception(ex) description = _('Queues could not be listed.') raise wsgi_exceptions.HTTPServiceUnavailable(description) # Buffer list of queues queues = list(results.next()) # Check for an empty list if len(queues) == 0: resp.status = falcon.HTTP_204 return # Got some. Prepare the response. kwargs['marker'] = results.next() for each_queue in queues: each_queue['href'] = req.path + '/' + each_queue['name'] response_body = { 'queues': queues, 'links': [ { 'rel': 'next', 'href': req.path + falcon.to_query_str(kwargs) } ] } resp.content_location = req.relative_uri resp.body = helpers.to_json(response_body) resp.status = falcon.HTTP_200