summaryrefslogtreecommitdiff
path: root/oslo_policy/generator.py
diff options
context:
space:
mode:
authorAnthony Washington <anthony.washington@intel.com>2017-03-08 21:34:54 +0000
committerAnthony Washington <anthony.washington@intel.com>2017-03-20 21:17:09 +0000
commitc4ea173b8195bfb238e1c41b76efdc97b7ab0b98 (patch)
tree251f56ca22b3716d96693b35bd089b3384e581bd /oslo_policy/generator.py
parent395177145622a5c37b8cfb53989084e2ff03ad98 (diff)
downloadoslo-policy-c4ea173b8195bfb238e1c41b76efdc97b7ab0b98.tar.gz
oslopolicy-sample-generator description support
With the idea of adding a more descriptive policy rule so operators can understand what a policy rule controls. This patch ensures `oslopolicy-sample-generator` adds the api(s) and method(s) {if given} to policy description. Change-Id: If4ca9bc191ac263f861373c432a1fafc3f7d596e
Diffstat (limited to 'oslo_policy/generator.py')
-rw-r--r--oslo_policy/generator.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/oslo_policy/generator.py b/oslo_policy/generator.py
index 14284ad..45bb4ae 100644
--- a/oslo_policy/generator.py
+++ b/oslo_policy/generator.py
@@ -101,18 +101,25 @@ def _format_help_text(description):
def _format_rule_default_yaml(default, include_help=True):
- """Create a yaml node from the provided policy.RuleDefault.
+ """Create a yaml node from policy.RuleDefault or policy.DocumentedRuleDefault.
- :param default: A policy.RuleDefault object
+ :param default: A policy.RuleDefault or policy.DocumentedRuleDefault object
:returns: A string containing a yaml representation of the RuleDefault
"""
text = ('"%(name)s": "%(check_str)s"\n' %
{'name': default.name,
'check_str': default.check_str})
+ op = ""
+ if hasattr(default, 'operations'):
+ for operation in default.operations:
+ op += ('# %(method)s %(path)s\n' %
+ {'method': operation['method'], 'path': operation['path']})
if include_help:
- text = ('%(help)s\n#%(text)s\n' %
+ text = ('%(help)s\n%(op)s#%(text)s\n' %
{'help': _format_help_text(default.description),
+ 'op': op,
'text': text})
+
return text