blob: e4e35b1d448b45f9f82db2e97d38fc5692892198 [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
Felipe Monteiro322c5b62017-02-26 02:44:21 +000018from patrole_tempest_plugin import rbac_policy_parser
DavidPurcell029d8c32017-01-06 15:27:41 -050019
20LOG = logging.getLogger(__name__)
21
22
23class RbacAuthority(object):
Felipe Monteiro889264e2017-03-01 17:19:35 -050024 def __init__(self, tenant_id, user_id, service=None):
25 self.converter = rbac_policy_parser.RbacPolicyParser(
26 tenant_id, user_id, 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