diff options
author | Davanum Srinivas <dims@linux.vnet.ibm.com> | 2014-09-30 17:48:42 -0400 |
---|---|---|
committer | Davanum Srinivas <dims@linux.vnet.ibm.com> | 2014-10-01 08:16:10 -0400 |
commit | 7ee3b0f459760e2d80422b0a35024b0b5a85509b (patch) | |
tree | 5e289551af6871c8dcd1f19654ea70e24f50ad7c | |
parent | 78460398eaca80b9ce147e96d424ce9687f87f1b (diff) | |
download | oslo-middleware-7ee3b0f459760e2d80422b0a35024b0b5a85509b.tar.gz |
Expose sizelimit option to config generator
* Adding a group name to prevent collision with keystone
middleware library option
* Adds an opts module for the config generator to use.
* Makes the option in sizelimit private since we don't want consumers
using them directly.
* Moves the options to an oslo_middleware group with appropriate
deprecated_opts settings to keep existing configs working.
Closes-Bug: #1368490
Change-Id: I72263bd363a79275a314de727a04277276866565
-rw-r--r-- | oslo/middleware/opts.py | 45 | ||||
-rw-r--r-- | oslo/middleware/sizelimit.py | 30 | ||||
-rw-r--r-- | setup.cfg | 4 | ||||
-rw-r--r-- | tests/test_sizelimit.py | 3 |
4 files changed, 70 insertions, 12 deletions
diff --git a/oslo/middleware/opts.py b/oslo/middleware/opts.py new file mode 100644 index 0000000..3cc035f --- /dev/null +++ b/oslo/middleware/opts.py @@ -0,0 +1,45 @@ +# Copyright 2014 IBM Corp. +# +# 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. + + +__all__ = [ + 'list_opts', +] + + +import copy + +from oslo.middleware import sizelimit + + +def list_opts(): + """Return a list of oslo.config options available in the library. + + 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))]
\ No newline at end of file diff --git a/oslo/middleware/sizelimit.py b/oslo/middleware/sizelimit.py index 3108c72..3caa8b1 100644 --- a/oslo/middleware/sizelimit.py +++ b/oslo/middleware/sizelimit.py @@ -18,6 +18,7 @@ Request Body limiting middleware. """ from oslo.config import cfg +from oslo.config import cfgfilter import webob.dec import webob.exc @@ -25,15 +26,22 @@ from oslo.middleware import base from oslo.middleware.i18n import _ -# default request size is 112k -max_req_body_size = cfg.IntOpt('max_request_body_size', - deprecated_name='osapi_max_request_body_size', - default=114688, - help='The maximum body size for each ' - ' request, in bytes.') +_oldopts = [cfg.DeprecatedOpt('osapi_max_request_body_size', + group='DEFAULT'), + cfg.DeprecatedOpt('max_request_body_size', + group='DEFAULT')] -CONF = cfg.CONF -CONF.register_opt(max_req_body_size) +_opts = [ + # default request size is 112k + cfg.IntOpt('max_request_body_size', + default=114688, + help='The maximum body size for each ' + ' request, in bytes.', + deprecated_opts=_oldopts) +] + +CONF = cfgfilter.ConfigFilter(cfg.CONF) +CONF.register_opts(_opts, group='oslo_middleware') class LimitingReader(object): @@ -71,12 +79,12 @@ class RequestBodySizeLimiter(base.Middleware): @webob.dec.wsgify def __call__(self, req): + max_size = CONF.oslo_middleware.max_request_body_size if (req.content_length is not None and - req.content_length > CONF.max_request_body_size): + req.content_length > max_size): msg = _("Request is too large.") raise webob.exc.HTTPRequestEntityTooLarge(explanation=msg) if req.content_length is None and req.is_body_readable: - limiter = LimitingReader(req.body_file, - CONF.max_request_body_size) + limiter = LimitingReader(req.body_file, max_size) req.body_file = limiter return self.application @@ -25,6 +25,10 @@ packages = namespace_packages = oslo +[entry_points] +oslo.config.opts = + oslo.middleware = oslo.middleware.opts:list_opts + [build_sphinx] source-dir = doc/source build-dir = doc/build diff --git a/tests/test_sizelimit.py b/tests/test_sizelimit.py index 0f813d8..89f655a 100644 --- a/tests/test_sizelimit.py +++ b/tests/test_sizelimit.py @@ -70,8 +70,9 @@ class TestRequestBodySizeLimiter(test_base.BaseTestCase): def setUp(self): super(TestRequestBodySizeLimiter, self).setUp() + fixture = self.useFixture(config.Config(sizelimit.CONF)) self.MAX_REQUEST_BODY_SIZE = \ - self.useFixture(config.Config()).conf.max_request_body_size + fixture.conf.oslo_middleware.max_request_body_size @webob.dec.wsgify() def fake_app(req): |