diff options
Diffstat (limited to 'nova/policy.py')
-rw-r--r-- | nova/policy.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/nova/policy.py b/nova/policy.py index 94bbbdd93..acfe830b9 100644 --- a/nova/policy.py +++ b/nova/policy.py @@ -92,3 +92,23 @@ def enforce(context, action, target): policy.enforce(match_list, target, credentials, exception.PolicyNotAuthorized, action=action) + + +def check_admin_role(roles): + """Whether or not roles contains 'admin' role according to policy setting. + + """ + init() + + action = 'admin' + match_list = ('rule:%s' % action,) + target = {} + credentials = {'roles': roles} + + try: + policy.enforce(match_list, target, credentials, + exception.PolicyNotAuthorized, action=action) + except exception.PolicyNotAuthorized: + return False + + return True |