diff options
author | Lance Bragstad <lbragstad@gmail.com> | 2018-01-03 20:37:22 +0000 |
---|---|---|
committer | Lance Bragstad <lbragstad@gmail.com> | 2018-04-27 15:42:28 +0000 |
commit | 6244a4427842490822fd38ce986c54d6db2c4afe (patch) | |
tree | 7e9785b76cf1a71953230fb6ac835312a247f9da /nova/policy.py | |
parent | f95f165b49fbc0efe29450b0e858a3ccadecedea (diff) | |
download | nova-6244a4427842490822fd38ce986c54d6db2c4afe.tar.gz |
Simplify logic in get_enforcer
The get_enforcer method is used by oslopolicy CLI scripts to generate
policy files. The scripts will use configuration files to find policy
files so that overrides can be generated with default values
registered in code. The get_enforcer method used to parse the
arguments passed in from the system and remove the `namespace` and
`output-file` arguments because they wouldn't be recognized while
processing configuration values.
This commit simplifies the logic of get_enforcer. A related
discussion was held in review:
https://review.openstack.org/#/c/530828/3
Proposing this to nova since I attempted to use similar logic to
fix a problem in keystone, but figured the simplified logic might be
useful here, too.
Change-Id: I7cd27fe8c39ddfc6ec20f4cfe4d62912d4cebaa4
Diffstat (limited to 'nova/policy.py')
-rw-r--r-- | nova/policy.py | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/nova/policy.py b/nova/policy.py index 4324fbc61c..cfdb1097a3 100644 --- a/nova/policy.py +++ b/nova/policy.py @@ -16,7 +16,6 @@ """Policy Engine For Nova.""" import copy import re -import sys from oslo_config import cfg from oslo_log import log as logging @@ -208,21 +207,9 @@ def register_rules(enforcer): def get_enforcer(): - # This method is for use by oslopolicy CLI scripts. Those scripts need the - # 'output-file' and 'namespace' options, but having those in sys.argv means - # loading the Nova config options will fail as those are not expected to - # be present. So we pass in an arg list with those stripped out. - conf_args = [] - # Start at 1 because cfg.CONF expects the equivalent of sys.argv[1:] - i = 1 - while i < len(sys.argv): - if sys.argv[i].strip('-') in ['namespace', 'output-file']: - i += 2 - continue - conf_args.append(sys.argv[i]) - i += 1 - - cfg.CONF(conf_args, project='nova') + # This method is used by oslopolicy CLI scripts in order to generate policy + # files from overrides on disk and defaults in code. + cfg.CONF([], project='nova') init() return _ENFORCER |