##// END OF EJS Templates
authn: Small refactoring of plugin discovery.
johbo -
r135:006df1d7 default
parent child Browse files
Show More
@@ -33,7 +33,8 b' from rhodecode.model.settings import Set'
33 33
34 34 log = logging.getLogger(__name__)
35 35
36 # Legacy plugins are stored with this prefix in 'auth_plugins'.
36 # Plugin ID prefixes to distinct between normal and legacy plugins.
37 plugin_prefix = 'egg:'
37 38 legacy_plugin_prefix = 'py:'
38 39
39 40
@@ -44,16 +45,24 b" legacy_plugin_prefix = 'py:'"
44 45 # TODO: When refactoring this think about splitting it up into distinct
45 46 # discover, load and include phases.
46 47 def _discover_plugins(config, entry_point='enterprise.plugins1'):
47 _discovered_plugins = {}
48
49 48 for ep in iter_entry_points(entry_point):
50 plugin_id = 'egg:{}#{}'.format(ep.dist.project_name, ep.name)
49 plugin_id = '{}:{}#{}'.format(
50 plugin_prefix, ep.dist.project_name, ep.name)
51 51 log.debug('Plugin discovered: "%s"', plugin_id)
52 try:
52 53 module = ep.load()
53 54 plugin = module(plugin_id=plugin_id)
54 55 config.include(plugin.includeme)
56 except Exception as e:
57 log.exception(
58 'Exception while loading authentication plugin '
59 '"{}": {}'.format(plugin_id, e.message))
55 60
56 return _discovered_plugins
61
62 def _import_legacy_plugin(plugin_id):
63 module_name = plugin_id.split(legacy_plugin_prefix, 1)[-1]
64 module = importlib.import_module(module_name)
65 return module.plugin_factory(plugin_id=plugin_id)
57 66
58 67
59 68 def _discover_legacy_plugins(config, prefix=legacy_plugin_prefix):
@@ -66,22 +75,14 b' def _discover_legacy_plugins(config, pre'
66 75 enabled_plugins = auth_plugins.app_settings_value
67 76 legacy_plugins = [id_ for id_ in enabled_plugins if id_.startswith(prefix)]
68 77
69 log.debug('Importing these legacy authentication plugins {}'.format(
70 legacy_plugins))
71
72 78 for plugin_id in legacy_plugins:
73 module_name = plugin_id.split(prefix, 1)[-1]
79 log.debug('Legacy plugin discovered: "%s"', plugin_id)
74 80 try:
75 module = importlib.import_module(module_name)
76 plugin = module.plugin_factory(plugin_id=plugin_id)
81 plugin = _import_legacy_plugin(plugin_id)
77 82 config.include(plugin.includeme)
78 except ImportError as e:
79 log.error(
80 'ImportError while importing legacy authentication plugin '
81 '"{}": {}'.format(plugin_id, e.message))
82 83 except Exception as e:
83 log.error(
84 'Exception while importing legacy authentication plugin '
84 log.exception(
85 'Exception while loading legacy authentication plugin '
85 86 '"{}": {}'.format(plugin_id, e.message))
86 87
87 88
General Comments 0
You need to be logged in to leave comments. Login now