diff options
author | Ghanshyam Mann <gmann@ghanshyammann.com> | 2020-11-24 12:46:56 -0600 |
---|---|---|
committer | Ghanshyam Mann <gmann@ghanshyammann.com> | 2020-11-24 13:27:25 -0600 |
commit | 0a228dea2ee96ec3eabed3361ca22502d0bbd4a1 (patch) | |
tree | cfbea82c7dc41dabf1ab4411c28b9412f54424ff | |
parent | 5180e9674f30a44a530deeabbc02804bec66351d (diff) | |
download | oslo-policy-0a228dea2ee96ec3eabed3361ca22502d0bbd4a1.tar.gz |
Fix oslopolicy-j2y-convertor tool for RuleDefault3.6.0
Description and operators are mandatory parameter for
DocumentedRuleDefault but few services still using the
RuleDefault for exmaple glance
- https://github.com/openstack/glance/blob/1344c45772c1a77107f621632642cf1488e431db/glance/policies/image.py#L16
To make work on oslopolicy-j2y-convertor tool to covert
the JSON file for such services we need to pass description
in preparing DocumentedRuleDefault for this tool to generate
the yaml file with rule description. For such cases, it add
rule name as description.
Also for 'operations', do not write it in generate file
for RuleDefault as that end up with blank space.
Change-Id: I910291a152402051b1eac96c3ec16c3f0bb8bbb7
-rw-r--r-- | oslo_policy/generator.py | 12 | ||||
-rw-r--r-- | oslo_policy/tests/test_generator.py | 16 |
2 files changed, 10 insertions, 18 deletions
diff --git a/oslo_policy/generator.py b/oslo_policy/generator.py index d701d37..ac1a992 100644 --- a/oslo_policy/generator.py +++ b/oslo_policy/generator.py @@ -177,9 +177,10 @@ def _format_rule_default_yaml(default, include_help=True, comment_rule=True, op = "" if hasattr(default, 'operations'): for operation in default.operations: - op += ('# %(method)s %(path)s\n' % - {'method': operation['method'], - 'path': operation['path']}) + if operation['method'] and operation['path']: + op += ('# %(method)s %(path)s\n' % + {'method': operation['method'], + 'path': operation['path']}) intended_scope = "" if getattr(default, 'scope_types', None) is not None: intended_scope = ( @@ -427,7 +428,8 @@ def _convert_policy_json_to_yaml(namespace, policy_file, output_file=None): continue file_rule_check_str = file_policies.pop(default_rule.name) # Some rules might be still RuleDefault object so let's prepare - # empty 'operations' list for those. + # empty 'operations' list and rule name as description for + # those. operations = [{ 'method': '', 'path': '' @@ -441,7 +443,7 @@ def _convert_policy_json_to_yaml(namespace, policy_file, output_file=None): file_rule = policy.DocumentedRuleDefault( default_rule.name, file_rule_check_str, - default_rule.description, + default_rule.description or default_rule.name, operations, default_rule.deprecated_rule, default_rule.deprecated_for_removal, diff --git a/oslo_policy/tests/test_generator.py b/oslo_policy/tests/test_generator.py index 2835536..8df0ec8 100644 --- a/oslo_policy/tests/test_generator.py +++ b/oslo_policy/tests/test_generator.py @@ -861,15 +861,9 @@ class ConvertJsonToYamlTestCase(base.PolicyBaseTestCase): deprecated_since='ussuri', scope_types=['system'] ), - policy.DocumentedRuleDefault( + policy.RuleDefault( name='rule2_name', check_str='rule:admin', - description='test_rule2', - operations=[{'path': '/test', 'method': 'PUT'}], - deprecated_rule=deprecated_policy, - deprecated_reason='testing2', - deprecated_since='ussuri', - scope_types=['system', 'project'] ) ] self.extensions = [] @@ -886,9 +880,7 @@ class ConvertJsonToYamlTestCase(base.PolicyBaseTestCase): # Intended scope(s): system #"rule1_name": "rule:admin" -# test_rule2 -# PUT /test -# Intended scope(s): system, project +# rule2_name "rule2_name": "rule:overridden" # WARNING: Below rules are either deprecated rules @@ -959,9 +951,7 @@ class ConvertJsonToYamlTestCase(base.PolicyBaseTestCase): def test_overridden_rules_uncommented_in_yaml_file(self): converted_policy_data = self._test_convert_json_to_yaml_file() - uncommented_overridden_rule = '''# test_rule2 -# PUT /test -# Intended scope(s): system, project + uncommented_overridden_rule = '''# rule2_name "rule2_name": "rule:overridden" ''' |