Remove the incorrect hack for Werkzeug 2.2.0

What hit us was a regression in 2.2.0. The hack we landed only fixes one
URL (e.g. /v1/rules/ is still broken) and leaves some redundant code in place
around path handling. Werkzeug 2.2.1 fixes our problems.

Reverts commit 97f4e98d0b.

Story: #2010193
Task: #45904
Depends-On: https://review.opendev.org/c/openstack/requirements/+/851500
Change-Id: Ice7e9499fbb2585d353ece7c5fa30e425e92d362
This commit is contained in:
Dmitry Tantsur 2022-07-29 11:39:20 +02:00
parent 97f4e98d0b
commit 8467209ec1

View File

@ -39,6 +39,7 @@ CONF = ironic_inspector.conf.CONF
_app = flask.Flask(__name__)
_app.url_map.strict_slashes = False
_wsgi_app = _app.wsgi_app
LOG = utils.getProcessingLogger(__name__)
@ -285,20 +286,6 @@ def api(path, is_public_api=False, rule=None, verb_to_rule_map=None,
and strings to format the 'rule' string with
:param kwargs: all the rest kwargs are passed to flask app.route
"""
if (not path.endswith('/')
and path == ''
and 'endpoint' not in flask_kwargs):
# NOTE(TheJulia): With rule matching changes in later
# versions of Werkzeug, we don't need to add slashes
# to the end of every path. Some explicitly don't need
# slashes to properly match. Where as if your using an
# endpoint to support other rules, you explicitly cannot
# add a tailing slash because the rule needs to be able
# to match in both possible ways the URL may be requested.
path = path + '/'
flask_kwargs['strict_slashes'] = False
def outer(func):
@_app.route(path, **flask_kwargs)
@convert_exceptions
@ -318,7 +305,7 @@ def api(path, is_public_api=False, rule=None, verb_to_rule_map=None,
return outer
@api('', rule='introspection', is_public_api=True, methods=['GET'])
@api('/', rule='introspection', is_public_api=True, methods=['GET'])
def api_root():
versions = [
{
@ -334,13 +321,8 @@ def api_root():
return flask.jsonify(versions=versions)
# NOTE(TheJulia): We need routes registered for with, and without
# a slash on this special endpoint because it is used in other
# requests.
@api('/<version>', rule='introspection:version', is_public_api=True,
methods=['GET'], endpoint='/<version>')
@api('/<version>/', rule='introspection:version', is_public_api=True,
methods=['GET'], endpoint='/<version>/')
methods=['GET'])
def version_root(version):
pat = re.compile(r'^\/%s\/[^\/]*?/?$' % version)
resources = []