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
This commit is contained in:
parent
d5d1d88286
commit
8a22ddd449
|
@ -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)
|
||||
|
|
|
@ -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('<error_message>'
|
||||
+ '\n'.join(app_iter)
|
||||
+ '</error_message>'))]
|
||||
except et.ElementTree.ParseError as err:
|
||||
LOG.error(_LE('Error parsing HTTP response: %s'), err)
|
||||
body = ['<error_message>%s' % state['status_code']
|
||||
+ '</error_message>']
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue