lemur/lemur/auth/permissions.py

58 lines
2.0 KiB
Python
Raw Normal View History

2015-06-22 22:47:27 +02:00
"""
2015-08-04 06:07:28 +02:00
.. module: lemur.auth.permissions
2015-06-22 22:47:27 +02:00
:platform: Unix
:synopsis: This module defines all the permission used within Lemur
:copyright: (c) 2015 by Netflix Inc., see AUTHORS for more
:license: Apache, see LICENSE for more details.
.. moduleauthor:: Kevin Glisson <kglisson@netflix.com>
"""
from functools import partial
from collections import namedtuple
from flask.ext.principal import Permission, RoleNeed
# Permissions
operator_permission = Permission(RoleNeed('operator'))
2015-06-26 03:06:47 +02:00
admin_permission = Permission(RoleNeed('admin'))
2015-06-22 22:47:27 +02:00
CertificateCreator = namedtuple('certificate', ['method', 'value'])
2015-08-20 03:05:18 +02:00
CertificateCreatorNeed = partial(CertificateCreator, 'key')
2015-06-22 22:47:27 +02:00
class ViewKeyPermission(Permission):
2015-08-20 03:05:18 +02:00
def __init__(self, certificate_id, owner):
c_need = CertificateCreatorNeed(certificate_id)
2015-08-20 03:05:18 +02:00
super(ViewKeyPermission, self).__init__(c_need, RoleNeed(owner), RoleNeed('admin'))
2015-06-22 22:47:27 +02:00
class UpdateCertificatePermission(Permission):
2015-08-20 03:05:18 +02:00
def __init__(self, certificate_id, owner):
c_need = CertificateCreatorNeed(certificate_id)
2015-08-20 03:05:18 +02:00
super(UpdateCertificatePermission, self).__init__(c_need, RoleNeed(owner), RoleNeed('admin'))
2015-06-22 22:47:27 +02:00
RoleUser = namedtuple('role', ['method', 'value'])
ViewRoleCredentialsNeed = partial(RoleUser, 'roleView')
class ViewRoleCredentialsPermission(Permission):
def __init__(self, role_id):
2015-08-04 06:07:28 +02:00
need = ViewRoleCredentialsNeed(str(role_id))
2015-06-22 22:47:27 +02:00
super(ViewRoleCredentialsPermission, self).__init__(need, RoleNeed('admin'))
AuthorityCreator = namedtuple('authority', ['method', 'value'])
AuthorityCreatorNeed = partial(AuthorityCreator, 'authorityUse')
AuthorityOwner = namedtuple('authority', ['method', 'value'])
AuthorityOwnerNeed = partial(AuthorityOwner, 'role')
class AuthorityPermission(Permission):
def __init__(self, authority_id, roles):
2015-08-04 06:07:28 +02:00
needs = [RoleNeed('admin'), AuthorityCreatorNeed(str(authority_id))]
2015-06-22 22:47:27 +02:00
for r in roles:
2015-08-04 06:07:28 +02:00
needs.append(AuthorityOwnerNeed(str(r)))
2015-06-22 22:47:27 +02:00
super(AuthorityPermission, self).__init__(*needs)