summaryrefslogtreecommitdiff
path: root/oslo_policy/policy.py
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-02-07 12:31:22 +0000
committerGerrit Code Review <review@openstack.org>2017-02-07 12:31:22 +0000
commit9e3d46b1707152094cc2c2bdd45e22898d79140c (patch)
tree9425928983a1b8d411cee43eb9fc82d87a787e49 /oslo_policy/policy.py
parent3b86352dd2cab84145c37440296dd867ee3b596a (diff)
parent74c2a42a92721d343b27f3b776e40d1ee38d146e (diff)
downloadoslo-policy-9e3d46b1707152094cc2c2bdd45e22898d79140c.tar.gz
Merge "Add optional exception for check_rules"
Diffstat (limited to 'oslo_policy/policy.py')
-rw-r--r--oslo_policy/policy.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/oslo_policy/policy.py b/oslo_policy/policy.py
index 4d5d6ff..1a3781c 100644
--- a/oslo_policy/policy.py
+++ b/oslo_policy/policy.py
@@ -314,6 +314,13 @@ class PolicyNotRegistered(Exception):
super(PolicyNotRegistered, self).__init__(msg)
+class InvalidDefinitionError(Exception):
+ def __init__(self, names):
+ msg = _('Policies %(names)s are not well defined. Check logs for '
+ 'more details.') % {'names': names}
+ super(InvalidDefinitionError, self).__init__(msg)
+
+
def parse_file_contents(data):
"""Parse the raw contents of a policy file.
@@ -541,7 +548,7 @@ class Enforcer(object):
# Detect and log obvious incorrect rule definitions
self.check_rules()
- def check_rules(self):
+ def check_rules(self, raise_on_violation=False):
"""Look for rule definitions that are obviously incorrect."""
undefined_checks = []
cyclic_checks = []
@@ -561,6 +568,9 @@ class Enforcer(object):
LOG.warning(_LW('Policies %(names)s are part of a cyclical '
'reference.'), {'names': cyclic_checks})
+ if raise_on_violation and violation:
+ raise InvalidDefinitionError(undefined_checks + cyclic_checks)
+
return not violation
def _undefined_check(self, check):