Akron | ca9bd98 | 2016-12-06 16:59:57 +0100 | [diff] [blame^] | 1 | import logging |
| 2 | |
| 3 | from APIFactory import URIBuilder |
| 4 | |
| 5 | from types import * |
| 6 | from notifications import * |
| 7 | from utils import * |
| 8 | |
| 9 | |
| 10 | __author__ = 'hanl' |
| 11 | |
| 12 | # instance reference for authentication provider |
| 13 | # must be set before usage! |
| 14 | PROVIDER = None |
| 15 | |
| 16 | |
| 17 | def init_app(config): |
| 18 | provider_name = config.get('AUTH_PROVIDER', 'providers.CustomProvider') |
| 19 | split = provider_name.split('.') |
| 20 | # get last element, so you have the class name |
| 21 | _class = split[len(split) - 1] |
| 22 | |
| 23 | provider_name = provider_name.replace("." + _class, "") |
| 24 | module = __import__(provider_name) |
| 25 | obj = getattr(module, _class, None) |
| 26 | if obj is None: |
| 27 | raise KeyError("the provider class '%s.%s' is undefined or could not be found!" % (provider_name, _class)) |
| 28 | instance = obj(config) |
| 29 | logging.info("successfully loaded provider '%s.%s'" % (provider_name, _class)) |
| 30 | global PROVIDER |
| 31 | PROVIDER = instance |
| 32 | |