Implement policy in code - session (4)

This commit migrate all session 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: I5d45029deaf34d9627b9ac66a90af13ad305a8a4
This commit is contained in:
Hieu LE 2017-10-16 10:19:54 +07:00
parent 22c9c648ad
commit 5222c58007
3 changed files with 127 additions and 11 deletions

View File

@ -1,14 +1,4 @@
{
"sessions:get_all": "",
"sessions:create": "",
"sessions:get": "",
"sessions:delete": "",
"sessions:update": "",
"sessions:replace": "",
"sessions:action:create": "",
"sessions:job:add": "",
"sessions:job:remove": "",
"backups:get_all": "",
"backups:create": "",
"backups:get": "",

View File

@ -20,11 +20,13 @@ import itertools
from freezer_api.common.policies import action
from freezer_api.common.policies import base
from freezer_api.common.policies import job
from freezer_api.common.policies import session
def list_rules():
return itertools.chain(
action.list_rules(),
base.list_rules(),
job.list_rules()
job.list_rules(),
session.list_rules()
)

View File

@ -0,0 +1,124 @@
# 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 freezer_api.common.policies import base
SESSIONS = 'sessions:%s'
rules = [
policy.DocumentedRuleDefault(
name=SESSIONS % 'create',
check_str=base.UNPROTECTED,
description='Creates session.',
operations=[
{
'path': '/v1/sessions',
'method': 'POST'
}
]
),
policy.DocumentedRuleDefault(
name=SESSIONS % 'delete',
check_str=base.UNPROTECTED,
description='Delete session.',
operations=[
{
'path': '/v1/sessions/{session_id}',
'method': 'DELETE'
}
]
),
policy.DocumentedRuleDefault(
name=SESSIONS % 'get',
check_str=base.UNPROTECTED,
description='Show sessions.',
operations=[
{
'path': '/v1/sessions/{session_id}',
'method': 'GET'
}
]
),
policy.DocumentedRuleDefault(
name=SESSIONS % 'get_all',
check_str=base.UNPROTECTED,
description='Lists sessions.',
operations=[
{
'path': '/v1/sessions',
'method': 'GET'
}
]
),
policy.DocumentedRuleDefault(
name=SESSIONS % 'update',
check_str=base.UNPROTECTED,
description='Updates sessions.',
operations=[
{
'path': '/v1/sessions/{session_id}',
'method': 'PATCH'
}
]
),
policy.DocumentedRuleDefault(
name=SESSIONS % 'replace',
check_str=base.UNPROTECTED,
description='Creates/replaces the specified session.',
operations=[
{
'path': '/v1/sessions/{session_id}',
'method': 'PUT'
}
]
),
policy.DocumentedRuleDefault(
name=SESSIONS % 'action:create',
check_str=base.UNPROTECTED,
description='Executes an action on the specified session.',
operations=[
{
'path': '/v1/sessions/{session_id}/action',
'method': 'POST'
}
]
),
policy.DocumentedRuleDefault(
name=SESSIONS % 'job:add',
check_str=base.UNPROTECTED,
description='Adds a certain job to a session.',
operations=[
{
'path': '/v1/sessions/{session_id}/jobs/{job_id}',
'method': 'PUT'
}
]
),
policy.DocumentedRuleDefault(
name=SESSIONS % 'job:remove',
check_str=base.UNPROTECTED,
description='Remove a job from a session.',
operations=[
{
'path': '/v1/sessions/{session_id}',
'method': 'DELETE'
}
]
)
]
def list_rules():
return rules