Use the new microversion-parse library to parse the version headers
Closes-Bug: #1584718 Change-Id: Ibc451536b7e5dcb3923d3a851686932e0a0c4490
This commit is contained in:
parent
04595529d3
commit
6cb28114fc
|
@ -17,6 +17,7 @@ import random
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
|
import microversion_parse as mvp
|
||||||
from oslo_utils import strutils
|
from oslo_utils import strutils
|
||||||
from oslo_utils import uuidutils
|
from oslo_utils import uuidutils
|
||||||
from werkzeug.middleware import proxy_fix
|
from werkzeug.middleware import proxy_fix
|
||||||
|
@ -35,6 +36,7 @@ from ironic_inspector import process
|
||||||
from ironic_inspector import rules
|
from ironic_inspector import rules
|
||||||
from ironic_inspector import utils
|
from ironic_inspector import utils
|
||||||
|
|
||||||
|
|
||||||
CONF = ironic_inspector.conf.CONF
|
CONF = ironic_inspector.conf.CONF
|
||||||
|
|
||||||
|
|
||||||
|
@ -118,11 +120,16 @@ def _get_version():
|
||||||
ver = flask.request.headers.get(conf_opts.VERSION_HEADER,
|
ver = flask.request.headers.get(conf_opts.VERSION_HEADER,
|
||||||
_DEFAULT_API_VERSION)
|
_DEFAULT_API_VERSION)
|
||||||
try:
|
try:
|
||||||
if ver.lower() == 'latest':
|
requested = _DEFAULT_API_VERSION
|
||||||
requested = CURRENT_API_VERSION
|
if ver:
|
||||||
else:
|
if ver.lower() == 'latest':
|
||||||
requested = tuple(int(x) for x in ver.split('.'))
|
requested = CURRENT_API_VERSION
|
||||||
except (ValueError, TypeError):
|
else:
|
||||||
|
requested = mvp.parse_version_string(ver)
|
||||||
|
|
||||||
|
if len(requested) != 2:
|
||||||
|
raise ValueError
|
||||||
|
except (ValueError, TypeError, AttributeError):
|
||||||
return error_response(_('Malformed API version: expected string '
|
return error_response(_('Malformed API version: expected string '
|
||||||
'in form of X.Y or latest'), code=400)
|
'in form of X.Y or latest'), code=400)
|
||||||
return requested
|
return requested
|
||||||
|
|
|
@ -38,3 +38,4 @@ tenacity>=6.2.0 # Apache-2.0
|
||||||
stevedore>=1.20.0 # Apache-2.0
|
stevedore>=1.20.0 # Apache-2.0
|
||||||
SQLAlchemy>=1.4.0 # MIT
|
SQLAlchemy>=1.4.0 # MIT
|
||||||
tooz>=2.5.1 # Apache-2.0
|
tooz>=2.5.1 # Apache-2.0
|
||||||
|
microversion_parse>=1.0.1
|
||||||
|
|
Loading…
Reference in New Issue