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