From 132200244f741aee5a887c084456f8b9c637c9cd Mon Sep 17 00:00:00 2001 From: Sungjin Yook Date: Thu, 12 Nov 2015 12:33:26 -0600 Subject: [PATCH] Can not set auth_endpoint in runtime In rumtime castellan should be able to set auth_endpoint using options.set_defaults() which is critical for application to be able to adjust endpoint in runtime. https://bugs.launchpad.net/castellan/+bug/1515388 Change-Id: Ie918dcc4d28ec3507559e1b0c218995f6809c364 Closes-Bug: 1515388 --- castellan/options.py | 20 +++++++++++++++++++- castellan/tests/unit/test_options.py | 15 +++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/castellan/options.py b/castellan/options.py index 6d450300..4a1b3653 100644 --- a/castellan/options.py +++ b/castellan/options.py @@ -21,7 +21,8 @@ except ImportError: def set_defaults(conf, api_class=None, barbican_endpoint=None, - barbican_api_version=None): + barbican_api_version=None, auth_endpoint=None, + retry_delay=None, number_of_retries=None): '''Set defaults for configuration values. Overrides the default options values. @@ -33,6 +34,12 @@ def set_defaults(conf, api_class=None, barbican_endpoint=None, :param barbican_endpoint: Use this endpoint to connect to Barbican. :param barbican_api_version: Version of the Barbican API. + + :param auth_endpoint: Use this endpoint to connect to Keystone. + + :param retry_delay: Use this attribute to set retry delay. + + :param number_of_retries: Use this attribute to set number of retries. ''' conf.register_opts(km.key_manager_opts, group='key_manager') if bkm: @@ -46,6 +53,17 @@ def set_defaults(conf, api_class=None, barbican_endpoint=None, if bkm is not None and barbican_api_version is not None: conf.set_default('barbican_api_version', barbican_api_version, group=bkm.BARBICAN_OPT_GROUP) + if bkm is not None and auth_endpoint is not None: + conf.set_default('auth_endpoint', auth_endpoint, + group=bkm.BARBICAN_OPT_GROUP) + + if bkm is not None and retry_delay is not None: + conf.set_default('retry_delay', retry_delay, + group=bkm.BARBICAN_OPT_GROUP) + + if bkm is not None and number_of_retries is not None: + conf.set_default('number_of_retries', number_of_retries, + group=bkm.BARBICAN_OPT_GROUP) def list_opts(): diff --git a/castellan/tests/unit/test_options.py b/castellan/tests/unit/test_options.py index f0acb26d..2e445b11 100644 --- a/castellan/tests/unit/test_options.py +++ b/castellan/tests/unit/test_options.py @@ -38,3 +38,18 @@ class TestOptions(base.TestCase): options.set_defaults(conf, barbican_api_version=barbican_api_version) self.assertEqual(barbican_api_version, conf.get(bkm.BARBICAN_OPT_GROUP).barbican_api_version) + + auth_endpoint = 'http://test-server.org:5000/' + options.set_defaults(conf, auth_endpoint=auth_endpoint) + self.assertEqual(auth_endpoint, + conf.get(bkm.BARBICAN_OPT_GROUP).auth_endpoint) + + retry_delay = 3 + options.set_defaults(conf, retry_delay=retry_delay) + self.assertEqual(retry_delay, + conf.get(bkm.BARBICAN_OPT_GROUP).retry_delay) + + number_of_retries = 10 + options.set_defaults(conf, number_of_retries=number_of_retries) + self.assertEqual(number_of_retries, + conf.get(bkm.BARBICAN_OPT_GROUP).number_of_retries)