From 8a22ddd449dc2f2e3cd6b6a3fc335fe4981023f3 Mon Sep 17 00:00:00 2001 From: Akash Gangil Date: Mon, 10 Aug 2015 01:54:23 -0700 Subject: [PATCH] Remove XML parsing code from magnum. Openstack no longer supports XML interface for API requests. This patch removes any stale code for handling xml api. Change-Id: I7f6cdfdde95d757dfab91fc0c18bb606986e5058 Closes-bug: 1474494 --- magnum/api/middleware/auth_token.py | 4 +--- magnum/api/middleware/parsable_error.py | 22 ++-------------------- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/magnum/api/middleware/auth_token.py b/magnum/api/middleware/auth_token.py index 0354c54112..13726eb5b3 100644 --- a/magnum/api/middleware/auth_token.py +++ b/magnum/api/middleware/auth_token.py @@ -32,9 +32,7 @@ class AuthTokenMiddleware(auth_token.AuthProtocol): def __init__(self, app, conf, public_api_routes=None): if public_api_routes is None: public_api_routes = [] - # TODO(?): Remove .xml and ensure it doesn't result in a - # 401 Authentication Required instead of 404 Not Found - route_pattern_tpl = '%s(\.json|\.xml)?$' + route_pattern_tpl = '%s\.json?$' try: self.public_api_routes = [re.compile(route_pattern_tpl % route_tpl) diff --git a/magnum/api/middleware/parsable_error.py b/magnum/api/middleware/parsable_error.py index d6f0144cd8..9255ad0511 100644 --- a/magnum/api/middleware/parsable_error.py +++ b/magnum/api/middleware/parsable_error.py @@ -19,13 +19,10 @@ Based on pecan.middleware.errordocument """ import json -from xml import etree as et from oslo_log import log -import webob from magnum.i18n import _ -from magnum.i18n import _LE LOG = log.getLogger(__name__) @@ -64,23 +61,8 @@ class ParsableErrorMiddleware(object): app_iter = self.app(environ, replacement_start_response) if (state['status_code'] // 100) not in (2, 3): - req = webob.Request(environ) - if (req.accept.best_match(['application/json', 'application/xml']) - == 'application/xml'): - try: - # simple check xml is valid - body = [et.ElementTree.tostring( - et.ElementTree.fromstring('' - + '\n'.join(app_iter) - + ''))] - except et.ElementTree.ParseError as err: - LOG.error(_LE('Error parsing HTTP response: %s'), err) - body = ['%s' % state['status_code'] - + ''] - state['headers'].append(('Content-Type', 'application/xml')) - else: - body = [json.dumps({'error_message': '\n'.join(app_iter)})] - state['headers'].append(('Content-Type', 'application/json')) + body = [json.dumps({'error_message': '\n'.join(app_iter)})] + state['headers'].append(('Content-Type', 'application/json')) state['headers'].append(('Content-Length', str(len(body[0])))) else: body = app_iter