summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Hellmann <doug@doughellmann.com>2015-08-26 17:19:12 +0000
committerDavanum Srinivas <davanum@gmail.com>2015-08-27 06:06:44 -0400
commitea893e8ba417aeb13455acfda30b8337159b8536 (patch)
treeeef50b9ca615b8f7e79d0ec40cbe54cacc41b014
parent95b735d1f009c7339a664364a553a866f40f1039 (diff)
downloadoslo-middleware-ea893e8ba417aeb13455acfda30b8337159b8536.tar.gz
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
-rw-r--r--doc/source/api.rst13
-rwxr-xr-xdoc/source/conf.py5
-rw-r--r--doc/source/cors.rst5
-rw-r--r--oslo_middleware/opts.py83
-rw-r--r--oslo_middleware/tests/test_opts.py31
-rw-r--r--setup.cfg3
6 files changed, 136 insertions, 4 deletions
diff --git a/doc/source/api.rst b/doc/source/api.rst
index 38cd96c..50ad06d 100644
--- a/doc/source/api.rst
+++ b/doc/source/api.rst
@@ -4,3 +4,16 @@
.. automodule:: oslo_middleware
:members:
+
+Configuration Options
+=====================
+
+RequestBodySizeLimiter
+~~~~~~~~~~~~~~~~~~~~~~
+
+.. show-options:: oslo.middleware.sizelimit
+
+SSLMiddleware
+~~~~~~~~~~~~~
+
+.. show-options:: oslo.middleware.ssl
diff --git a/doc/source/conf.py b/doc/source/conf.py
index c5178f1..6265ab6 100755
--- a/doc/source/conf.py
+++ b/doc/source/conf.py
@@ -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} \ No newline at end of file
+#intersphinx_mapping = {'http://docs.python.org/': None}
diff --git a/doc/source/cors.rst b/doc/source/cors.rst
index 09f5d77..890f7fd 100644
--- a/doc/source/cors.rst
+++ b/doc/source/cors.rst
@@ -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
--------------------
diff --git a/oslo_middleware/opts.py b/oslo_middleware/opts.py
index c19f272..883fb90 100644
--- a/oslo_middleware/opts.py
+++ b/oslo_middleware/opts.py
@@ -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))
]
diff --git a/oslo_middleware/tests/test_opts.py b/oslo_middleware/tests/test_opts.py
new file mode 100644
index 0000000..763d550
--- /dev/null
+++ b/oslo_middleware/tests/test_opts.py
@@ -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()
diff --git a/setup.cfg b/setup.cfg
index 71103fe..c0a9bd9 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -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