本文整理汇总了Python中oslo_policy.policy.DocumentedRuleDefault方法的典型用法代码示例。如果您正苦于以下问题:Python policy.DocumentedRuleDefault方法的具体用法?Python policy.DocumentedRuleDefault怎么用?Python policy.DocumentedRuleDefault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_policy.policy
的用法示例。
在下文中一共展示了policy.DocumentedRuleDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_with_operations
# 需要导入模块: from oslo_policy import policy [as 别名]
# 或者: from oslo_policy.policy import DocumentedRuleDefault [as 别名]
def test_with_operations(self):
results = '\n'.join(list(sphinxext._format_policy_section(
'foo', [policy.DocumentedRuleDefault(
'rule_a', '@', 'My sample rule', [
{'method': 'GET', 'path': '/foo'},
{'method': 'POST', 'path': '/some'}])]
)))
self.assertEqual(textwrap.dedent("""
foo
===
``rule_a``
:Default: ``@``
:Operations:
- **GET** ``/foo``
- **POST** ``/some``
My sample rule
""").lstrip(), results)
示例2: test_deprecate_a_policy_for_removal_logs_warning_when_overridden
# 需要导入模块: from oslo_policy import policy [as 别名]
# 或者: from oslo_policy.policy import DocumentedRuleDefault [as 别名]
def test_deprecate_a_policy_for_removal_logs_warning_when_overridden(self):
rule_list = [policy.DocumentedRuleDefault(
name='foo:bar',
check_str='role:baz',
description='Create a foo.',
operations=[{'path': '/v1/foos/', 'method': 'POST'}],
deprecated_for_removal=True,
deprecated_reason=(
'"foo:bar" is no longer a policy used by the service'
),
deprecated_since='N'
)]
expected_msg = (
'Policy "foo:bar":"role:baz" was deprecated for removal in N. '
'Reason: "foo:bar" is no longer a policy used by the service. Its '
'value may be silently ignored in the future.'
)
rules = jsonutils.dumps({'foo:bar': 'role:bang'})
self.create_config_file('policy.json', rules)
enforcer = policy.Enforcer(self.conf)
enforcer.register_defaults(rule_list)
with mock.patch('warnings.warn') as mock_warn:
enforcer.load_rules()
mock_warn.assert_called_once_with(expected_msg)
示例3: test_deprecate_a_policy_for_removal_does_not_log_warning
# 需要导入模块: from oslo_policy import policy [as 别名]
# 或者: from oslo_policy.policy import DocumentedRuleDefault [as 别名]
def test_deprecate_a_policy_for_removal_does_not_log_warning(self):
# We should only log a warning for operators if they are supplying an
# override for a policy that is deprecated for removal.
rule_list = [policy.DocumentedRuleDefault(
name='foo:bar',
check_str='role:baz',
description='Create a foo.',
operations=[{'path': '/v1/foos/', 'method': 'POST'}],
deprecated_for_removal=True,
deprecated_reason=(
'"foo:bar" is no longer a policy used by the service'
),
deprecated_since='N'
)]
enforcer = policy.Enforcer(self.conf)
enforcer.register_defaults(rule_list)
with mock.patch('warnings.warn') as mock_warn:
enforcer.load_rules()
mock_warn.assert_not_called()
示例4: test_deprecate_check_str_suppress_does_not_log_warning
# 需要导入模块: from oslo_policy import policy [as 别名]
# 或者: from oslo_policy.policy import DocumentedRuleDefault [as 别名]
def test_deprecate_check_str_suppress_does_not_log_warning(self):
deprecated_rule = policy.DeprecatedRule(
name='foo:create_bar',
check_str='role:fizz'
)
rule_list = [policy.DocumentedRuleDefault(
name='foo:create_bar',
check_str='role:bang',
description='Create a bar.',
operations=[{'path': '/v1/bars', 'method': 'POST'}],
deprecated_rule=deprecated_rule,
deprecated_reason='"role:bang" is a better default',
deprecated_since='N'
)]
enforcer = policy.Enforcer(self.conf)
enforcer.suppress_deprecation_warnings = True
enforcer.register_defaults(rule_list)
with mock.patch('warnings.warn') as mock_warn:
enforcer.load_rules()
mock_warn.assert_not_called()
示例5: test_deprecate_name_suppress_does_not_log_warning
# 需要导入模块: from oslo_policy import policy [as 别名]
# 或者: from oslo_policy.policy import DocumentedRuleDefault [as 别名]
def test_deprecate_name_suppress_does_not_log_warning(self):
deprecated_rule = policy.DeprecatedRule(
name='foo:bar',
check_str='role:baz'
)
rule_list = [policy.DocumentedRuleDefault(
name='foo:create_bar',
check_str='role:baz',
description='Create a bar.',
operations=[{'path': '/v1/bars/', 'method': 'POST'}],
deprecated_rule=deprecated_rule,
deprecated_reason='"foo:bar" is not granular enough.',
deprecated_since='N'
)]
rules = jsonutils.dumps({'foo:bar': 'role:bang'})
self.create_config_file('policy.json', rules)
enforcer = policy.Enforcer(self.conf)
enforcer.suppress_deprecation_warnings = True
enforcer.register_defaults(rule_list)
with mock.patch('warnings.warn') as mock_warn:
enforcer.load_rules()
mock_warn.assert_not_called()
示例6: test_suppress_default_change_warnings_flag_not_log_warning
# 需要导入模块: from oslo_policy import policy [as 别名]
# 或者: from oslo_policy.policy import DocumentedRuleDefault [as 别名]
def test_suppress_default_change_warnings_flag_not_log_warning(self):
deprecated_rule = policy.DeprecatedRule(
name='foo:create_bar',
check_str='role:fizz'
)
rule_list = [policy.DocumentedRuleDefault(
name='foo:create_bar',
check_str='role:bang',
description='Create a bar.',
operations=[{'path': '/v1/bars', 'method': 'POST'}],
deprecated_rule=deprecated_rule,
deprecated_reason='"role:bang" is a better default',
deprecated_since='N'
)]
enforcer = policy.Enforcer(self.conf)
enforcer.suppress_default_change_warnings = True
enforcer.register_defaults(rule_list)
with mock.patch('warnings.warn') as mock_warn:
enforcer.load_rules()
mock_warn.assert_not_called()
示例7: test_deprecated_policy_must_include_deprecated_since
# 需要导入模块: from oslo_policy import policy [as 别名]
# 或者: from oslo_policy.policy import DocumentedRuleDefault [as 别名]
def test_deprecated_policy_must_include_deprecated_since(self):
deprecated_rule = policy.DeprecatedRule(
name='foo:bar',
check_str='rule:baz'
)
self.assertRaises(
ValueError,
policy.DocumentedRuleDefault,
name='foo:bar',
check_str='rule:baz',
description='Create a foo.',
operations=[{'path': '/v1/foos/', 'method': 'POST'}],
deprecated_rule=deprecated_rule,
deprecated_reason='Some reason.'
)
示例8: __init__
# 需要导入模块: from oslo_policy import policy [as 别名]
# 或者: from oslo_policy.policy import DocumentedRuleDefault [as 别名]
def __init__(self, name, check_str, description, operations,
deprecated_rule=None, deprecated_for_removal=False,
deprecated_reason=None, deprecated_since=None,
scope_types=None):
super(DocumentedRuleDefault, self).__init__(
name, check_str, description,
deprecated_rule=deprecated_rule,
deprecated_for_removal=deprecated_for_removal,
deprecated_reason=deprecated_reason,
deprecated_since=deprecated_since,
scope_types=scope_types
)
self.operations = operations
示例9: test_with_scope_types
# 需要导入模块: from oslo_policy import policy [as 别名]
# 或者: from oslo_policy.policy import DocumentedRuleDefault [as 别名]
def test_with_scope_types(self):
operations = [
{'method': 'GET', 'path': '/foo'},
{'method': 'POST', 'path': '/some'}
]
scope_types = ['bar']
rule = policy.DocumentedRuleDefault(
'rule_a', '@', 'My sample rule', operations,
scope_types=scope_types
)
results = '\n'.join(list(sphinxext._format_policy_section(
'foo', [rule]
)))
self.assertEqual(textwrap.dedent("""
foo
===
``rule_a``
:Default: ``@``
:Operations:
- **GET** ``/foo``
- **POST** ``/some``
:Scope Types:
- **bar**
My sample rule
""").lstrip(), results)
示例10: test_deprecate_a_policy_check_string
# 需要导入模块: from oslo_policy import policy [as 别名]
# 或者: from oslo_policy.policy import DocumentedRuleDefault [as 别名]
def test_deprecate_a_policy_check_string(self):
deprecated_rule = policy.DeprecatedRule(
name='foo:create_bar',
check_str='role:fizz'
)
rule_list = [policy.DocumentedRuleDefault(
name='foo:create_bar',
check_str='role:bang',
description='Create a bar.',
operations=[{'path': '/v1/bars', 'method': 'POST'}],
deprecated_rule=deprecated_rule,
deprecated_reason='"role:bang" is a better default',
deprecated_since='N'
)]
enforcer = policy.Enforcer(self.conf)
enforcer.register_defaults(rule_list)
expected_msg = (
'Policy "foo:create_bar":"role:fizz" was deprecated in N in favor '
'of "foo:create_bar":"role:bang". Reason: "role:bang" is a better '
'default. Either ensure your deployment is ready for the new '
'default or copy/paste the deprecated policy into your policy '
'file and maintain it manually.'
)
with mock.patch('warnings.warn') as mock_warn:
enforcer.load_rules()
mock_warn.assert_called_once_with(expected_msg)
self.assertTrue(
enforcer.enforce('foo:create_bar', {}, {'roles': ['bang']})
)
self.assertTrue(
enforcer.enforce('foo:create_bar', {}, {'roles': ['fizz']})
)
self.assertFalse(
enforcer.enforce('foo:create_bar', {}, {'roles': ['baz']})
)
示例11: test_deprecate_an_empty_policy_check_string
# 需要导入模块: from oslo_policy import policy [as 别名]
# 或者: from oslo_policy.policy import DocumentedRuleDefault [as 别名]
def test_deprecate_an_empty_policy_check_string(self):
deprecated_rule = policy.DeprecatedRule(
name='foo:create_bar',
check_str=''
)
rule_list = [policy.DocumentedRuleDefault(
name='foo:create_bar',
check_str='role:bang',
description='Create a bar.',
operations=[{'path': '/v1/bars', 'method': 'POST'}],
deprecated_rule=deprecated_rule,
deprecated_reason='because of reasons',
deprecated_since='N'
)]
enforcer = policy.Enforcer(self.conf)
enforcer.register_defaults(rule_list)
with mock.patch('warnings.warn') as mock_warn:
enforcer.load_rules()
mock_warn.assert_called_once()
enforcer.enforce('foo:create_bar', {}, {'roles': ['bang']},
do_raise=True)
enforcer.enforce('foo:create_bar', {}, {'roles': ['fizz']},
do_raise=True)
示例12: test_deprecated_policy_for_removal_must_include_deprecated_since
# 需要导入模块: from oslo_policy import policy [as 别名]
# 或者: from oslo_policy.policy import DocumentedRuleDefault [as 别名]
def test_deprecated_policy_for_removal_must_include_deprecated_since(self):
self.assertRaises(
ValueError,
policy.DocumentedRuleDefault,
name='foo:bar',
check_str='rule:baz',
description='Create a foo.',
operations=[{'path': '/v1/foos/', 'method': 'POST'}],
deprecated_for_removal=True,
deprecated_reason='Some reason.'
)
示例13: test_deprecated_rule_requires_deprecated_rule_object
# 需要导入模块: from oslo_policy import policy [as 别名]
# 或者: from oslo_policy.policy import DocumentedRuleDefault [as 别名]
def test_deprecated_rule_requires_deprecated_rule_object(self):
self.assertRaises(
ValueError,
policy.DocumentedRuleDefault,
name='foo:bar',
check_str='rule:baz',
description='Create a foo.',
operations=[{'path': '/v1/foos/', 'method': 'POST'}],
deprecated_rule='foo:bar',
deprecated_reason='Some reason.'
)
示例14: test_deprecated_policy_must_include_deprecated_reason
# 需要导入模块: from oslo_policy import policy [as 别名]
# 或者: from oslo_policy.policy import DocumentedRuleDefault [as 别名]
def test_deprecated_policy_must_include_deprecated_reason(self):
self.assertRaises(
ValueError,
policy.DocumentedRuleDefault,
name='foo:bar',
check_str='rule:baz',
description='Create a foo.',
operations=[{'path': '/v1/foos/', 'method': 'POST'}],
deprecated_for_removal=True,
deprecated_since='N'
)
示例15: test_override_deprecated_policy_with_new_name
# 需要导入模块: from oslo_policy import policy [as 别名]
# 或者: from oslo_policy.policy import DocumentedRuleDefault [as 别名]
def test_override_deprecated_policy_with_new_name(self):
# Simulate an operator overriding a policy using the new policy name
rules = jsonutils.dumps({'foo:create_bar': 'role:bazz'})
self.create_config_file('policy.json', rules)
# Deprecate the policy name and check string in favor of something
# better.
deprecated_rule = policy.DeprecatedRule(
name='foo:bar',
check_str='role:fizz'
)
rule_list = [policy.DocumentedRuleDefault(
name='foo:create_bar',
check_str='role:bang',
description='Create a bar.',
operations=[{'path': '/v1/bars', 'method': 'POST'}],
deprecated_rule=deprecated_rule,
deprecated_reason='"role:bang" is a better default',
deprecated_since='N'
)]
self.enforcer.register_defaults(rule_list)
# Make sure the override supplied by the operator is being used in
# place of either default value.
self.assertFalse(
self.enforcer.enforce('foo:create_bar', {}, {'roles': ['fizz']})
)
self.assertFalse(
self.enforcer.enforce('foo:create_bar', {}, {'roles': ['bang']})
)
self.assertTrue(
self.enforcer.enforce('foo:create_bar', {}, {'roles': ['bazz']})
)