791dbf3a6e9853f9ec3d3a4f44c5aba68152aeb5
[invirt/packages/invirt-base.git] / python / invirt / authz.py
1 """Invirt authorization.
2
3 This module acts as a loader for the pluggable authorization system.
4
5 Any Python module which wishes to provide an authorization scheme for
6 Invirt should advertise an entry point in the invirt.authz group with
7 a unique name. That name can then be configured in
8 /etc/invirt/master.yaml as the authz mechanism.
9 """
10
11
12 from __future__ import absolute_import
13 import pkg_resources
14
15 from invirt.config import structs as cfg
16
17
18 def expandOwner(name):
19     """Expand an "owner" to a list of authorized users."""
20     for ep in pkg_resources.iter_entry_points('invirt.authz', cfg.authz.name):
21         return ep.load().expandOwner(name)
22
23
24 def expandAdmin(name):
25     """Expand an "administrator" to a list of authorized users."""
26     for ep in pkg_resources.iter_entry_points('invirt.authz', cfg.authz.name):
27         return ep.load().expandAdmin(name)
28
29
30 __all__ = ['expandOwner',
31            'expandAdmin',
32            ]