Implement policy in code - member (7)

This commit migrate all member policies into code [1].

Like oslo.config, with oslo.policy, we can define all of
default rules in code base and only change some rules
via policy file. Another thing that we should use yaml
format instead of json format.

[1] https://governance.openstack.org/tc/goals/queens/policy-in-code.html
Co-authored-By: Dai Dang-Van <daidv@vn.fujitsu.com>

Change-Id: I166d0d62489fa8230a2ba34ef09f9366ac321633
This commit is contained in:
Hieu LE 2017-10-13 11:23:45 +07:00 committed by Dai Dang Van
parent d2274af9a2
commit 3c999d01b2
4 changed files with 86 additions and 13 deletions

View File

@ -1,12 +1,6 @@
{
"default": "rule:admin_or_owner",
"members:create": "rule:admin_or_owner",
"members:delete": "rule:admin_or_owner",
"members:get": "rule:admin_or_owner",
"members:list": "rule:admin_or_owner",
"members:update": "rule:admin_or_owner",
"services:list": "rule:admin_or_owner",
"tasks:get": "rule:admin_or_owner",

View File

@ -20,6 +20,7 @@ from mistral.policies import base
from mistral.policies import cron_trigger
from mistral.policies import environment
from mistral.policies import execution
from mistral.policies import member
def list_rules():
@ -29,5 +30,6 @@ def list_rules():
base.list_rules(),
cron_trigger.list_rules(),
environment.list_rules(),
execution.list_rules()
execution.list_rules(),
member.list_rules()
)

View File

@ -0,0 +1,83 @@
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_policy import policy
from mistral.policies import base
MEMBERS = 'members:%s'
# NOTE(hieulq): all API operations of below rules are not documented in API
# reference docs yet.
rules = [
policy.DocumentedRuleDefault(
name=MEMBERS % 'create',
check_str=base.RULE_ADMIN_OR_OWNER,
description='Shares the resource to a new member.',
operations=[
{
'path': '/v2/members',
'method': 'POST'
}
]
),
policy.DocumentedRuleDefault(
name=MEMBERS % 'delete',
check_str=base.RULE_ADMIN_OR_OWNER,
description='Deletes a member from the member list of a resource.',
operations=[
{
'path': '/v2/members',
'method': 'DELETE'
}
]
),
policy.DocumentedRuleDefault(
name=MEMBERS % 'get',
check_str=base.RULE_ADMIN_OR_OWNER,
description='Shows resource member details.',
operations=[
{
'path': '/v2/members/{member_id}',
'method': 'GET'
}
]
),
policy.DocumentedRuleDefault(
name=MEMBERS % 'list',
check_str=base.RULE_ADMIN_OR_OWNER,
description='Return all members with whom the resource has been '
'shared.',
operations=[
{
'path': '/v2/members',
'method': 'GET'
}
]
),
policy.DocumentedRuleDefault(
name=MEMBERS % 'update',
check_str=base.RULE_ADMIN_OR_OWNER,
description='Sets the status for a resource member.',
operations=[
{
'path': '/v2/members',
'method': 'PUT'
}
]
)
]
def list_rules():
return rules

View File

@ -15,12 +15,6 @@
policy_data = """{
"default": "rule:admin_or_owner",
"members:create": "rule:admin_or_owner",
"members:delete": "rule:admin_or_owner",
"members:get": "rule:admin_or_owner",
"members:list": "rule:admin_or_owner",
"members:update": "rule:admin_or_owner",
"services:list": "rule:admin_or_owner",
"tasks:get": "rule:admin_or_owner",