summaryrefslogtreecommitdiff
path: root/oslo_policy/opts.py
diff options
context:
space:
mode:
authorDoug Hellmann <doug@doughellmann.com>2015-02-18 10:59:02 -0500
committerDoug Hellmann <doug@doughellmann.com>2015-02-18 12:45:04 -0500
commit41d8bf1c07c84808ebd50313755cf77721c03e58 (patch)
treebba1d1324a5c3c5552d8e3956e6f883da6c669fd /oslo_policy/opts.py
parentb475cd53daa44d2d0387fe2f891c06ccc76135c8 (diff)
downloadoslo-policy-41d8bf1c07c84808ebd50313755cf77721c03e58.tar.gz
Clean up configuration option management0.1.0
Move the option definitions into the opts module with the other functions related to options. Add set_defaults() to override the default settings for options and make it part of the public API of the library by including it in the documentation. Add opts._register() so the options can be registered consistently from multiple places. Change-Id: Ib74beac58a07bf5ee0f92c2b7eda8281ef7d7c33
Diffstat (limited to 'oslo_policy/opts.py')
-rw-r--r--oslo_policy/opts.py61
1 files changed, 58 insertions, 3 deletions
diff --git a/oslo_policy/opts.py b/oslo_policy/opts.py
index 0880fdf..d836f57 100644
--- a/oslo_policy/opts.py
+++ b/oslo_policy/opts.py
@@ -11,12 +11,40 @@
# under the License.
__all__ = [
- 'list_opts'
+ 'list_opts',
+ 'set_defaults',
]
import copy
-from oslo_policy import policy
+from oslo_config import cfg
+
+from oslo_policy._i18n import _
+
+
+_option_group = 'oslo_policy'
+
+_options = [
+ cfg.StrOpt('policy_file',
+ default='policy.json',
+ help=_('The JSON file that defines policies.'),
+ deprecated_group='DEFAULT'),
+ cfg.StrOpt('policy_default_rule',
+ default='default',
+ help=_('Default rule. Enforced when a requested rule is not '
+ 'found.'),
+ deprecated_group='DEFAULT'),
+ cfg.MultiStrOpt('policy_dirs',
+ default=['policy.d'],
+ help=_('Directories where policy configuration files are '
+ 'stored. They can be relative to any directory '
+ 'in the search path defined by the config_dir '
+ 'option, or absolute paths. The file defined by '
+ 'policy_file must exist for these directories to '
+ 'be searched. Missing or empty directories are'
+ 'ignored.'),
+ deprecated_group='DEFAULT'),
+]
def list_opts():
@@ -36,4 +64,31 @@ def list_opts():
:returns: a list of (group_name, opts) tuples
"""
- return [('oslo_policy', copy.deepcopy(policy._opts))]
+ return [(_option_group, copy.deepcopy(_options))]
+
+
+def _register(conf):
+ """Register the policy options.
+
+ We do this in a few places, so use a function to ensure it is done
+ consistently.
+ """
+ conf.register_opts(_options, group=_option_group)
+
+
+def set_defaults(conf, policy_file=None):
+ """Set defaults for configuration variables.
+
+ Overrides default options values.
+
+ :param conf: Configuration object, managed by the caller.
+ :type conf: oslo.config.cfg.ConfigOpts
+
+ :param policy_file: The base filename for the JSON file that
+ defines policies.
+ :type policy_file: unicode
+ """
+ _register(conf)
+
+ if policy_file is not None:
+ conf.set_default('policy_file', policy_file, group=_option_group)