Register default host policies in code

This commit uses the existing policy-in-code module to move all
default policies for hosts 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: Iacfe41ec0f664c2f3dce5efb24ece389b5e60b3f
This commit is contained in:
Lance Bragstad 2017-10-02 20:02:11 +00:00 committed by Hieu LE
parent 5568dfd92b
commit a7a584becb
3 changed files with 49 additions and 3 deletions

View File

@ -1,8 +1,6 @@
{
"default": "rule:admin_or_owner",
"host:get_all": "rule:admin_api",
"host:get": "rule:admin_api",
"capsule:create": "rule:default",
"capsule:delete": "rule:default",
"capsule:delete_all_tenants": "rule:admin_api",

View File

@ -14,6 +14,7 @@ import itertools
from zun.common.policies import base
from zun.common.policies import container
from zun.common.policies import host
from zun.common.policies import image
from zun.common.policies import zun_service
@ -23,5 +24,6 @@ def list_rules():
base.list_rules(),
container.list_rules(),
image.list_rules(),
zun_service.list_rules()
zun_service.list_rules(),
host.list_rules()
)

View File

@ -0,0 +1,46 @@
# 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
HOST = 'host:%s'
rules = [
policy.DocumentedRuleDefault(
name=HOST % 'get_all',
check_str=base.RULE_ADMIN_API,
description='List all compute hosts.',
operations=[
{
'path': '/v1/hosts',
'method': 'GET'
}
]
),
policy.DocumentedRuleDefault(
name=HOST % 'get',
check_str=base.RULE_ADMIN_API,
description='Show the details of a specific compute host.',
operations=[
{
'path': '/v1/hosts/{host_ident}',
'method': 'GET'
}
]
)
]
def list_rules():
return rules