Simple library for parsing OpenStack microversion headers.
Go to file
Chris Dent b1f7162324 Fix folded header checks for WebOb
WebOb uses a Mapping class for headers which behaves like a dict
but does not inherit from dict, so the isinstance check in
fold_headers was not working as expected. This is now replaced
with a check for dict-like behaviors. It's a bit of a tossup
between doing a hasattr and simply trying to access a key. I chose
the former for readability and because we don't actually want to
do anything with the value we would retrieve were access by a key
legit.

Tests are added to specfically cover the use of a
webob.headers.EnvironHeaders object, which is what headers in
Nova and Nova derivations look like.

Change-Id: I31de49bcfd8822c53d3293b106de96138eaf4464
2016-03-31 14:03:13 +01:00
doc/source Enable gerrit, gitreview and gate testing 2016-03-31 12:31:20 +01:00
microversion_parse Fix folded header checks for WebOb 2016-03-31 14:03:13 +01:00
.gitignore Initial commit 2016-03-22 15:29:38 +00:00
.gitreview Enable gerrit, gitreview and gate testing 2016-03-31 12:31:20 +01:00
.testr.conf Initial proof of concept of microversion_parse 2016-03-22 17:48:42 +00:00
LICENSE Initial commit 2016-03-22 15:29:38 +00:00
Makefile allow tox to skip missing interpreters 2016-03-24 13:28:08 +00:00
README.rst Cleanup README 2016-03-24 13:35:42 +00:00
requirements.txt Initial proof of concept of microversion_parse 2016-03-22 17:48:42 +00:00
setup.cfg Enable gerrit, gitreview and gate testing 2016-03-31 12:31:20 +01:00
setup.py Initial proof of concept of microversion_parse 2016-03-22 17:48:42 +00:00
test-requirements.txt Fix folded header checks for WebOb 2016-03-31 14:03:13 +01:00
tox.ini Enable gerrit, gitreview and gate testing 2016-03-31 12:31:20 +01:00

README.rst

microversion_parse

A simple parser for OpenStack microversion headers:

import microversion_parse

# headers is a dict of headers with folded (comma-separated
# values) or a list of header, value tuples
version = microversion_parse.get_version(
    headers, service_type='compute',
    legacy_headers=['x-openstack-nova-api-version'])

It processes microversion headers with the standard form:

OpenStack-API-Version: compute 2.1

If provided with a legacy_headers argument, this is treated as a list of headers to check for microversions. Some examples of headers include:

OpenStack-telemetry-api-version: 2.1
OpenStack-nova-api-version: 2.1
X-OpenStack-nova-api-version: 2.1

If a version string cannot be found, None will be returned. If the input is incorrect usual Python exceptions (ValueError, TypeError) are allowed to raise to the caller.