Use the new microversion-parse library to parse the version headers

Partial-Bug: #354432
Change-Id: Ibc451536b7e5dcb3923d3a851686932e0a0c4490
This commit is contained in:
cid 2024-03-20 16:04:43 +01:00
parent 04595529d3
commit d63353b9f2
2 changed files with 6 additions and 3 deletions

View File

@ -21,6 +21,8 @@ from oslo_utils import strutils
from oslo_utils import uuidutils
from werkzeug.middleware import proxy_fix
from microversion_parse import parse_version_string
from ironic_inspector import api_tools
from ironic_inspector.common import context
from ironic_inspector.common import coordination
@ -35,6 +37,7 @@ from ironic_inspector import process
from ironic_inspector import rules
from ironic_inspector import utils
CONF = ironic_inspector.conf.CONF
@ -118,10 +121,9 @@ def _get_version():
ver = flask.request.headers.get(conf_opts.VERSION_HEADER,
_DEFAULT_API_VERSION)
try:
if ver.lower() == 'latest':
requested = parse_version_string(ver) or _DEFAULT_API_VERSION
if 'latest' in ver.lower():
requested = CURRENT_API_VERSION
else:
requested = tuple(int(x) for x in ver.split('.'))
except (ValueError, TypeError):
return error_response(_('Malformed API version: expected string '
'in form of X.Y or latest'), code=400)

View File

@ -38,3 +38,4 @@ tenacity>=6.2.0 # Apache-2.0
stevedore>=1.20.0 # Apache-2.0
SQLAlchemy>=1.4.0 # MIT
tooz>=2.5.1 # Apache-2.0
microversion_parse>=0.1.4