Commit Graph

7 Commits

Author SHA1 Message Date
Chris Dent f816e324b8 Allow passing a json_error_formatter to the middleware
This is so error responses can be formatted according to the rules
of the application.

Change-Id: Ie44399447a349ebc49251dc63c23f56c6423fca6
2018-03-20 17:24:56 +00:00
Chris Dent b5359fcd80 Add MicroversionMiddleware
This change imports (with slight modification) the
MicroversionMiddleware created for the placement service.

For the time being the middleware relies on WebOb as that is
what it originally relied on. If there are requirements to do
otherwise, later, we can make adjustments then.

The README is updated with limited usage instructions.

Gabbi tests are added, requiring adjustments to the test configuration,
so the opportunity was taken to switch to using stestr instead of testr.

Though arguably "functional" tests because they are not strictly unit
tests, no distinction is made in the tests directory, for now, as it
is all nice and fast and we'd like to keep it that way.

Change-Id: I9d27b6fad35f7aea0085f08c0353f8e8acdb8b73
2018-03-20 17:24:56 +00:00
Chris Dent da0b4d66c9 Import functions from placement
This change imports two functions and a class from the microversion
handling implementation in the placement service. This code should be
generally useful for other implementations.

The added code provides functions for not just extracting the
microversion from HTTP headers, but for validating that the found
information is actually a properly formed microversion value.

'latest' is translated to whatever latest is in an ordered list of
versions and any found version is confirmed to be within the bounds of
and a member of that list of versions.

The README.rst has been updated to reflect the newly available methods.
This is a start at documentation, but we'll probably want more.

Change-Id: I267586c78308cc5520a88598c350a7e055783f3e
2018-03-15 18:15:25 +00:00
Chris Dent bd003b52a5 Provide a helper method to get headers from environ
The get_version method accepts a dict or list of tuples that
represent HTTP request headers that will be processed to find a
microversion header. Sometimes, for example in some middlewares,
direct access to a headers dict will not be available and only the
WSGI environ will be present.

This change provides a utility method which creates a new dict of
headers: headers_from_wsgi_environ. This mode was chosen to make it
clear that a copy of the environ is being made, not the environ
itself as we really don't want to be passing that as some values in
it will not be simple objects (strings and numbers) and we do not
know what other middleware might have done or want to do with it.

Internal to get_version any attempt to get a header named 'FOO' will
fall back to looking for the WSGI equivalent of 'HTTP_FOO'.

README.rst has been updated to indicate the new style.

This change is backwards compatible, existing clients will not
notice.

Change-Id: I5262031d9cde0378eabe342c1913091658c3bf9b
Closes-Bug: #1579772
2018-03-15 18:15:20 +00:00
Chris Dent 45916f2af1 Cleanup README
Some formatting errors.
2016-03-24 13:35:42 +00:00
Chris Dent d2c4bb7605 Change interface to explicitly pass legacy_headers
Based on suggestion from @sdague

TODO: more tests, positive and negative
2016-03-22 19:44:18 +00:00
Chris Dent 49b44934b9 Initial proof of concept of microversion_parse
See README.rst for details.

The basic gist is that a get_version method is provided. It takes a
dict or list of headers and returned a version for a service_type if
it can find it.
2016-03-22 17:48:42 +00:00