Split option discovery function by middleware
Create separate option discovery functions for each piece of middleware, so an application that only uses one piece can include only those options in its sample configuration file. Test the results with some unit tests that simply ensure the functions do not raise exceptions, and by adding configuration options to the documentation for the library, using the new integration of oslo.config with sphinx. Change-Id: I4c777cd70c063441f430c48ab1f9c9cac2c1fc75
This commit is contained in:
parent
95b735d1f0
commit
ea893e8ba4
@ -4,3 +4,16 @@
|
||||
|
||||
.. automodule:: oslo_middleware
|
||||
:members:
|
||||
|
||||
Configuration Options
|
||||
=====================
|
||||
|
||||
RequestBodySizeLimiter
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. show-options:: oslo.middleware.sizelimit
|
||||
|
||||
SSLMiddleware
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
.. show-options:: oslo.middleware.ssl
|
||||
|
@ -23,7 +23,8 @@ sys.path.insert(0, os.path.abspath('../..'))
|
||||
extensions = [
|
||||
'sphinx.ext.autodoc',
|
||||
#'sphinx.ext.intersphinx',
|
||||
'oslosphinx'
|
||||
'oslosphinx',
|
||||
'oslo_config.sphinxext',
|
||||
]
|
||||
|
||||
# autodoc generation is a bit aggressive and a nuisance when doing heavy
|
||||
@ -72,4 +73,4 @@ latex_documents = [
|
||||
]
|
||||
|
||||
# Example configuration for intersphinx: refer to the Python standard library.
|
||||
#intersphinx_mapping = {'http://docs.python.org/': None}
|
||||
#intersphinx_mapping = {'http://docs.python.org/': None}
|
||||
|
@ -105,6 +105,11 @@ will add CORS support. To add multiple domains, simply add another filter.::
|
||||
expose_headers=Content-Type,Cache-Control,Content-Language,Expires,Last-Modified,Pragma,X-Custom-Header
|
||||
|
||||
|
||||
Configuration Options
|
||||
---------------------
|
||||
|
||||
.. show-options:: oslo.middleware.cors
|
||||
|
||||
Module Documentation
|
||||
--------------------
|
||||
|
||||
|
@ -15,10 +15,14 @@
|
||||
|
||||
__all__ = [
|
||||
'list_opts',
|
||||
'list_opts_sizelimit',
|
||||
'list_opts_ssl',
|
||||
'list_opts_cors'
|
||||
]
|
||||
|
||||
|
||||
import copy
|
||||
import itertools
|
||||
|
||||
from oslo_middleware import cors
|
||||
from oslo_middleware import sizelimit
|
||||
@ -26,7 +30,83 @@ from oslo_middleware import ssl
|
||||
|
||||
|
||||
def list_opts():
|
||||
"""Return a list of oslo.config options available in the library.
|
||||
"""Return a list of oslo.config options for ALL of the middleware classes.
|
||||
|
||||
The returned list includes all oslo.config options which may be registered
|
||||
at runtime by the library.
|
||||
|
||||
Each element of the list is a tuple. The first element is the name of the
|
||||
group under which the list of elements in the second element will be
|
||||
registered. A group name of None corresponds to the [DEFAULT] group in
|
||||
config files.
|
||||
|
||||
This function is also discoverable via the 'oslo.concurrency' entry point
|
||||
under the 'oslo.config.opts' namespace.
|
||||
|
||||
The purpose of this is to allow tools like the Oslo sample config file
|
||||
generator to discover the options exposed to users by this library.
|
||||
|
||||
:returns: a list of (group_name, opts) tuples
|
||||
"""
|
||||
return list(
|
||||
itertools.chain(
|
||||
list_opts_sizelimit(),
|
||||
list_opts_ssl(),
|
||||
list_opts_cors(),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def list_opts_sizelimit():
|
||||
"""Return a list of oslo.config options for the sizelimit middleware.
|
||||
|
||||
The returned list includes all oslo.config options which may be registered
|
||||
at runtime by the library.
|
||||
|
||||
Each element of the list is a tuple. The first element is the name of the
|
||||
group under which the list of elements in the second element will be
|
||||
registered. A group name of None corresponds to the [DEFAULT] group in
|
||||
config files.
|
||||
|
||||
This function is also discoverable via the 'oslo.concurrency' entry point
|
||||
under the 'oslo.config.opts' namespace.
|
||||
|
||||
The purpose of this is to allow tools like the Oslo sample config file
|
||||
generator to discover the options exposed to users by this library.
|
||||
|
||||
:returns: a list of (group_name, opts) tuples
|
||||
"""
|
||||
return [
|
||||
('oslo_middleware', copy.deepcopy(sizelimit._opts)),
|
||||
]
|
||||
|
||||
|
||||
def list_opts_ssl():
|
||||
"""Return a list of oslo.config options for the sizelimit middleware.
|
||||
|
||||
The returned list includes all oslo.config options which may be registered
|
||||
at runtime by the library.
|
||||
|
||||
Each element of the list is a tuple. The first element is the name of the
|
||||
group under which the list of elements in the second element will be
|
||||
registered. A group name of None corresponds to the [DEFAULT] group in
|
||||
config files.
|
||||
|
||||
This function is also discoverable via the 'oslo.concurrency' entry point
|
||||
under the 'oslo.config.opts' namespace.
|
||||
|
||||
The purpose of this is to allow tools like the Oslo sample config file
|
||||
generator to discover the options exposed to users by this library.
|
||||
|
||||
:returns: a list of (group_name, opts) tuples
|
||||
"""
|
||||
return [
|
||||
('oslo_middleware', copy.deepcopy(ssl.OPTS)),
|
||||
]
|
||||
|
||||
|
||||
def list_opts_cors():
|
||||
"""Return a list of oslo.config options for the cors middleware.
|
||||
|
||||
The returned list includes all oslo.config options which may be registered
|
||||
at runtime by the library.
|
||||
@ -45,7 +125,6 @@ def list_opts():
|
||||
:returns: a list of (group_name, opts) tuples
|
||||
"""
|
||||
return [
|
||||
('oslo_middleware', copy.deepcopy(sizelimit._opts + ssl.OPTS)),
|
||||
('cors', copy.deepcopy(cors.CORS_OPTS)),
|
||||
('cors.subdomain', copy.deepcopy(cors.CORS_OPTS))
|
||||
]
|
||||
|
31
oslo_middleware/tests/test_opts.py
Normal file
31
oslo_middleware/tests/test_opts.py
Normal file
@ -0,0 +1,31 @@
|
||||
# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_middleware import opts
|
||||
from oslotest.base import BaseTestCase
|
||||
|
||||
|
||||
class TestOptionDiscovery(BaseTestCase):
|
||||
|
||||
def test_all(self):
|
||||
opts.list_opts()
|
||||
|
||||
def test_sizelimit(self):
|
||||
opts.list_opts_sizelimit()
|
||||
|
||||
def test_cors(self):
|
||||
opts.list_opts_cors()
|
||||
|
||||
def test_ssl(self):
|
||||
opts.list_opts_ssl()
|
@ -30,6 +30,9 @@ namespace_packages =
|
||||
[entry_points]
|
||||
oslo.config.opts =
|
||||
oslo.middleware = oslo_middleware.opts:list_opts
|
||||
oslo.middleware.cors = oslo_middleware.opts:list_opts_cors
|
||||
oslo.middleware.sizelimit = oslo_middleware.opts:list_opts_sizelimit
|
||||
oslo.middleware.ssl = oslo_middleware.opts:list_opts_ssl
|
||||
|
||||
oslo.middleware.healthcheck =
|
||||
disable_by_file = oslo_middleware.healthcheck.disable_by_file:DisableByFileHealthcheck
|
||||
|
Loading…
Reference in New Issue
Block a user