blob: 1afc7aeef8654090b7f55895f0884541c4b34c73 [file] [log] [blame]
DavidPurcellb25f93d2017-01-27 12:46:27 -05001# Copyright 2017 AT&T Corporation.
DavidPurcell029d8c32017-01-06 15:27:41 -05002# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from oslo_log import log as logging
DavidPurcell029d8c32017-01-06 15:27:41 -050017
18from patrole_tempest_plugin import rbac_role_converter
19
20LOG = logging.getLogger(__name__)
21
22
23class RbacAuthority(object):
Felipe Monteirob0595652017-01-23 16:51:58 -050024 def __init__(self, tenant_id, service=None):
25 self.converter = rbac_role_converter.RbacPolicyConverter(tenant_id,
26 service)
DavidPurcell029d8c32017-01-06 15:27:41 -050027
Felipe Monteirob0595652017-01-23 16:51:58 -050028 def get_permission(self, rule_name, role):
DavidPurcell029d8c32017-01-06 15:27:41 -050029 try:
Felipe Monteirob0595652017-01-23 16:51:58 -050030 is_allowed = self.converter.allowed(rule_name, role)
31 if is_allowed:
32 LOG.debug("[API]: %s, [Role]: %s is allowed!", rule_name, role)
DavidPurcell029d8c32017-01-06 15:27:41 -050033 else:
Felipe Monteirob0595652017-01-23 16:51:58 -050034 LOG.debug("[API]: %s, [Role]: %s is NOT allowed!",
35 rule_name, role)
36 return is_allowed
DavidPurcell029d8c32017-01-06 15:27:41 -050037 except KeyError:
Felipe Monteirob0595652017-01-23 16:51:58 -050038 LOG.debug("[API]: %s, [Role]: %s is NOT allowed!",
39 rule_name, role)
40 return False
DavidPurcell029d8c32017-01-06 15:27:41 -050041 return False