Register default capsule policies in code

This commit uses the existing policy-in-code module to move all
default policies for capsules into code. This commit also adds
helpful documetation about each API those policies protect, which
will be generated in sample policy files.

bp policy-and-docs-in-code

Change-Id: I96b287a142100e8064f7b7ef1326ff1490b26969
This commit is contained in:
Lance Bragstad 2017-10-02 20:08:12 +00:00 committed by Hieu LE
parent a7a584becb
commit 813ddb4087
3 changed files with 125 additions and 9 deletions

View File

@ -1,13 +1,5 @@
{
"default": "rule:admin_or_owner",
"capsule:create": "rule:default",
"capsule:delete": "rule:default",
"capsule:delete_all_tenants": "rule:admin_api",
"capsule:get": "rule:default",
"capsule:get_one_all_tenants": "rule:admin_api",
"capsule:get_all": "rule:default",
"capsule:get_all_all_tenants": "rule:admin_api",
"network:attach_external_network": "rule:context_is_admin"
}

View File

@ -13,6 +13,7 @@
import itertools
from zun.common.policies import base
from zun.common.policies import capsule
from zun.common.policies import container
from zun.common.policies import host
from zun.common.policies import image
@ -25,5 +26,6 @@ def list_rules():
container.list_rules(),
image.list_rules(),
zun_service.list_rules(),
host.list_rules()
host.list_rules(),
capsule.list_rules()
)

View File

@ -0,0 +1,122 @@
# 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 zun.common.policies import base
CAPSULE = 'capsule:%s'
rules = [
# FIXME(lbragstad): This API call isn't actually listed in zun's API
# reference:
# https://developer.openstack.org/api-ref/application-container/
policy.DocumentedRuleDefault(
name=CAPSULE % 'create',
check_str=base.RULE_ADMIN_OR_OWNER,
description='Create a capsule',
operations=[
{
'path': '/v1/capsules/',
'method': 'POST'
}
]
),
# FIXME(lbragstad): This API call isn't actually listed in zun's API
# reference:
# https://developer.openstack.org/api-ref/application-container/
policy.DocumentedRuleDefault(
name=CAPSULE % 'delete',
check_str=base.RULE_ADMIN_OR_OWNER,
description='Delete a capsule',
operations=[
{
'path': '/v1/capsules/{capsule_ident}',
'method': 'DELETE'
}
]
),
# FIXME(lbragstad): This API call isn't actually listed in zun's API
# reference:
# https://developer.openstack.org/api-ref/application-container/
policy.DocumentedRuleDefault(
name=CAPSULE % 'delete_all_tenants',
check_str=base.RULE_ADMIN_API,
description='Delete a container in any tenant.',
operations=[
{
'path': '/v1/capsules/{capsule_ident}',
'method': 'DELETE'
}
]
),
# FIXME(lbragstad): This API call isn't actually listed in zun's API
# reference:
# https://developer.openstack.org/api-ref/application-container/
policy.DocumentedRuleDefault(
name=CAPSULE % 'get',
check_str=base.RULE_ADMIN_OR_OWNER,
description='Retrieve the details of a capsule.',
operations=[
{
'path': '/v1/capsules/{capsule_ident}',
'method': 'GET'
}
]
),
# FIXME(lbragstad): This API call isn't actually listed in zun's API
# reference:
# https://developer.openstack.org/api-ref/application-container/
policy.DocumentedRuleDefault(
name=CAPSULE % 'get_one_all_tenants',
check_str=base.RULE_ADMIN_API,
description='Retrieve the details of a capsule in any tenant.',
operations=[
{
'path': '/v1/capsules/{capsule_ident}',
'method': 'GET'
}
]
),
# FIXME(lbragstad): This API call isn't actually listed in zun's API
# reference:
# https://developer.openstack.org/api-ref/application-container/
policy.DocumentedRuleDefault(
name=CAPSULE % 'get_all',
check_str=base.RULE_ADMIN_OR_OWNER,
description='List all capsules.',
operations=[
{
'path': '/v1/capsules/',
'method': 'GET'
}
]
),
# FIXME(lbragstad): This API call isn't actually listed in zun's API
# reference:
# https://developer.openstack.org/api-ref/application-container/
policy.DocumentedRuleDefault(
name=CAPSULE % 'get_all_all_tenants',
check_str=base.RULE_ADMIN_API,
description='List all capsules across tenants.',
operations=[
{
'path': '/v1/capsules/',
'method': 'GET'
}
]
),
]
def list_rules():
return rules