Fix oslopolicy-j2y-convertor tool for RuleDefault
Description and operators are mandatory parameter for
DocumentedRuleDefault but few services still using the
RuleDefault for exmaple glance
- 1344c45772/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
This commit is contained in:
parent
5180e9674f
commit
0a228dea2e
@ -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,
|
||||
|
@ -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"
|
||||
|
||||
'''
|
||||
|
Loading…
x
Reference in New Issue
Block a user