##// END OF EJS Templates
core: change from homebrew plugin system into pyramid machinery....
marcink -
r3240:b74ad312 default
parent child Browse files
Show More
@@ -117,10 +117,11 b' class NavigationRegistry(object):'
117 self._registered_entries[entry.key] = entry
117 self._registered_entries[entry.key] = entry
118
118
119 def get_navlist(self, request):
119 def get_navlist(self, request):
120 navlist = [NavListEntry(i.key, i.get_localized_name(request),
120 nav_list = [
121 NavListEntry(i.key, i.get_localized_name(request),
121 i.generate_url(request), i.active_list)
122 i.generate_url(request), i.active_list)
122 for i in self._registered_entries.values()]
123 for i in self._registered_entries.values()]
123 return navlist
124 return nav_list
124
125
125
126
126 def navigation_registry(request, registry=None):
127 def navigation_registry(request, registry=None):
@@ -143,5 +144,5 b' def includeme(config):'
143 # Create admin navigation registry and add it to the pyramid registry.
144 # Create admin navigation registry and add it to the pyramid registry.
144 settings = config.get_settings()
145 settings = config.get_settings()
145 labs_active = str2bool(settings.get('labs_settings_active', False))
146 labs_active = str2bool(settings.get('labs_settings_active', False))
146 navigation_registry = NavigationRegistry(labs_active=labs_active)
147 navigation_registry_instance = NavigationRegistry(labs_active=labs_active)
147 config.registry.registerUtility(navigation_registry) No newline at end of file
148 config.registry.registerUtility(navigation_registry_instance)
@@ -18,11 +18,9 b''
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import os
22 import logging
21 import logging
23 import importlib
22 import importlib
24
23
25 from pkg_resources import iter_entry_points
26 from pyramid.authentication import SessionAuthenticationPolicy
24 from pyramid.authentication import SessionAuthenticationPolicy
27
25
28 from rhodecode.authentication.registry import AuthenticationPluginRegistry
26 from rhodecode.authentication.registry import AuthenticationPluginRegistry
@@ -31,39 +29,12 b' from rhodecode.authentication.routes imp'
31 from rhodecode.apps._base import ADMIN_PREFIX
29 from rhodecode.apps._base import ADMIN_PREFIX
32 from rhodecode.model.settings import SettingsModel
30 from rhodecode.model.settings import SettingsModel
33
31
34
35 log = logging.getLogger(__name__)
32 log = logging.getLogger(__name__)
36
33
37 # Plugin ID prefixes to distinct between normal and legacy plugins.
38 plugin_prefix = 'egg:'
39 legacy_plugin_prefix = 'py:'
34 legacy_plugin_prefix = 'py:'
40 plugin_default_auth_ttl = 30
35 plugin_default_auth_ttl = 30
41
36
42
37
43 # TODO: Currently this is only used to discover the authentication plugins.
44 # Later on this may be used in a generic way to look up and include all kinds
45 # of supported enterprise plugins. Therefore this has to be moved and
46 # refactored to a real 'plugin look up' machinery.
47 # TODO: When refactoring this think about splitting it up into distinct
48 # discover, load and include phases.
49 def _discover_plugins(config, entry_point='enterprise.plugins1'):
50 log.debug('authentication: running plugin discovery for entrypoint %s',
51 entry_point)
52
53 for ep in iter_entry_points(entry_point):
54 plugin_id = '{}{}#{}'.format(
55 plugin_prefix, ep.dist.project_name, ep.name)
56 log.debug('Plugin discovered: "%s"', plugin_id)
57 try:
58 module = ep.load()
59 plugin = module(plugin_id=plugin_id)
60 config.include(plugin.includeme)
61 except Exception as e:
62 log.exception(
63 'Exception while loading authentication plugin '
64 '"{}": {}'.format(plugin_id, e.message))
65
66
67 def _import_legacy_plugin(plugin_id):
38 def _import_legacy_plugin(plugin_id):
68 module_name = plugin_id.split(legacy_plugin_prefix, 1)[-1]
39 module_name = plugin_id.split(legacy_plugin_prefix, 1)[-1]
69 module = importlib.import_module(module_name)
40 module = importlib.import_module(module_name)
@@ -127,11 +98,14 b' def includeme(config):'
127 route_name='auth_home',
98 route_name='auth_home',
128 context=AuthnRootResource)
99 context=AuthnRootResource)
129
100
130 for key in ['RC_CMD_SETUP_RC', 'RC_CMD_UPGRADE_DB', 'RC_CMD_SSH_WRAPPER']:
101 # load CE authentication plugins
131 if os.environ.get(key):
102 config.include('rhodecode.authentication.plugins.auth_crowd')
132 # skip this heavy step below on certain CLI commands
103 config.include('rhodecode.authentication.plugins.auth_headers')
133 return
104 config.include('rhodecode.authentication.plugins.auth_jasig_cas')
105 config.include('rhodecode.authentication.plugins.auth_ldap')
106 config.include('rhodecode.authentication.plugins.auth_pam')
107 config.include('rhodecode.authentication.plugins.auth_rhodecode')
108 config.include('rhodecode.authentication.plugins.auth_token')
134
109
135 # Auto discover authentication plugins and include their configuration.
110 # Auto discover authentication plugins and include their configuration.
136 _discover_plugins(config)
137 _discover_legacy_plugins(config)
111 _discover_legacy_plugins(config)
@@ -287,3 +287,8 b' class RhodeCodeAuthPlugin(RhodeCodeExter'
287 log.debug("Final crowd user object: \n%s", formatted_json(user_attrs))
287 log.debug("Final crowd user object: \n%s", formatted_json(user_attrs))
288 log.info('user `%s` authenticated correctly', user_attrs['username'])
288 log.info('user `%s` authenticated correctly', user_attrs['username'])
289 return user_attrs
289 return user_attrs
290
291
292 def includeme(config):
293 plugin_id = 'egg:rhodecode-enterprise-ce#{}'.format('crowd')
294 plugin_factory(plugin_id).includeme(config)
@@ -223,3 +223,8 b' class RhodeCodeAuthPlugin(RhodeCodeExter'
223
223
224 log.info('user `%s` authenticated correctly', user_attrs['username'])
224 log.info('user `%s` authenticated correctly', user_attrs['username'])
225 return user_attrs
225 return user_attrs
226
227
228 def includeme(config):
229 plugin_id = 'egg:rhodecode-enterprise-ce#{}'.format('headers')
230 plugin_factory(plugin_id).includeme(config)
@@ -165,3 +165,8 b' class RhodeCodeAuthPlugin(RhodeCodeExter'
165
165
166 log.info('user `%s` authenticated correctly', user_attrs['username'])
166 log.info('user `%s` authenticated correctly', user_attrs['username'])
167 return user_attrs
167 return user_attrs
168
169
170 def includeme(config):
171 plugin_id = 'egg:rhodecode-enterprise-ce#{}'.format('jasig_cas')
172 plugin_factory(plugin_id).includeme(config)
@@ -526,3 +526,8 b' class RhodeCodeAuthPlugin(RhodeCodeExter'
526 except (Exception,):
526 except (Exception,):
527 log.exception("Other exception")
527 log.exception("Other exception")
528 return None
528 return None
529
530
531 def includeme(config):
532 plugin_id = 'egg:rhodecode-enterprise-ce#{}'.format('ldap')
533 plugin_factory(plugin_id).includeme(config)
@@ -163,3 +163,8 b' class RhodeCodeAuthPlugin(RhodeCodeExter'
163 log.debug("pamuser: %s", user_attrs)
163 log.debug("pamuser: %s", user_attrs)
164 log.info('user `%s` authenticated correctly', user_attrs['username'])
164 log.info('user `%s` authenticated correctly', user_attrs['username'])
165 return user_attrs
165 return user_attrs
166
167
168 def includeme(config):
169 plugin_id = 'egg:rhodecode-enterprise-ce#{}'.format('pam')
170 plugin_factory(plugin_id).includeme(config)
@@ -141,3 +141,8 b' class RhodeCodeAuthPlugin(RhodeCodeAuthP'
141 'user `%s` failed to authenticate via %s, reason: account not '
141 'user `%s` failed to authenticate via %s, reason: account not '
142 'active.', username, self.name)
142 'active.', username, self.name)
143 return None
143 return None
144
145
146 def includeme(config):
147 plugin_id = 'egg:rhodecode-enterprise-ce#{}'.format('rhodecode')
148 plugin_factory(plugin_id).includeme(config)
@@ -149,3 +149,8 b' class RhodeCodeAuthPlugin(RhodeCodeAuthP'
149 'user `%s` failed to authenticate via %s, reason: account not '
149 'user `%s` failed to authenticate via %s, reason: account not '
150 'active.', username, self.name)
150 'active.', username, self.name)
151 return None
151 return None
152
153
154 def includeme(config):
155 plugin_id = 'egg:rhodecode-enterprise-ce#{}'.format('token')
156 plugin_factory(plugin_id).includeme(config)
@@ -108,7 +108,8 b' def make_pyramid_app(global_config, **se'
108 # creating the app uses a connection - return it after we are done
108 # creating the app uses a connection - return it after we are done
109 meta.Session.remove()
109 meta.Session.remove()
110 total_time = time.time() - start_time
110 total_time = time.time() - start_time
111 log.info('Pyramid app %s created and configured in %.2fs', pyramid_app, total_time)
111 log.info('Pyramid app `%s` created and configured in %.2fs',
112 pyramid_app.func_name, total_time)
112 return pyramid_app
113 return pyramid_app
113
114
114
115
@@ -237,13 +238,13 b' def includeme(config):'
237 config.include('pyramid_beaker')
238 config.include('pyramid_beaker')
238 config.include('rhodecode.lib.rc_cache')
239 config.include('rhodecode.lib.rc_cache')
239
240
240 config.include('rhodecode.authentication')
241 config.include('rhodecode.integrations')
242
243 config.include('rhodecode.apps._base.navigation')
241 config.include('rhodecode.apps._base.navigation')
244 config.include('rhodecode.apps._base.subscribers')
242 config.include('rhodecode.apps._base.subscribers')
245 config.include('rhodecode.tweens')
243 config.include('rhodecode.tweens')
246
244
245 config.include('rhodecode.integrations')
246 config.include('rhodecode.authentication')
247
247 # apps
248 # apps
248 config.include('rhodecode.apps._base')
249 config.include('rhodecode.apps._base')
249 config.include('rhodecode.apps.ops')
250 config.include('rhodecode.apps.ops')
@@ -266,7 +267,6 b' def includeme(config):'
266 config.include('rhodecode.api')
267 config.include('rhodecode.api')
267
268
268 config.add_route('rhodecode_support', 'https://rhodecode.com/help/', static=True)
269 config.add_route('rhodecode_support', 'https://rhodecode.com/help/', static=True)
269
270 config.add_translation_dirs('rhodecode:i18n/')
270 config.add_translation_dirs('rhodecode:i18n/')
271 settings['default_locale_name'] = settings.get('lang', 'en')
271 settings['default_locale_name'] = settings.get('lang', 'en')
272
272
@@ -32,6 +32,6 b' class IntegrationTypeRegistry(collection'
32 if key in self:
32 if key in self:
33 log.debug(
33 log.debug(
34 'Overriding existing integration type %s (%s) with %s',
34 'Overriding existing integration type %s (%s) with %s',
35 self[key], key, IntegrationType)
35 self[key].__class__, key, IntegrationType)
36
36
37 self[key] = IntegrationType
37 self[key] = IntegrationType
@@ -148,15 +148,6 b' setup('
148 },
148 },
149 paster_plugins=['PasteScript'],
149 paster_plugins=['PasteScript'],
150 entry_points={
150 entry_points={
151 'enterprise.plugins1': [
152 'crowd=rhodecode.authentication.plugins.auth_crowd:plugin_factory',
153 'headers=rhodecode.authentication.plugins.auth_headers:plugin_factory',
154 'jasig_cas=rhodecode.authentication.plugins.auth_jasig_cas:plugin_factory',
155 'ldap=rhodecode.authentication.plugins.auth_ldap:plugin_factory',
156 'pam=rhodecode.authentication.plugins.auth_pam:plugin_factory',
157 'rhodecode=rhodecode.authentication.plugins.auth_rhodecode:plugin_factory',
158 'token=rhodecode.authentication.plugins.auth_token:plugin_factory',
159 ],
160 'paste.app_factory': [
151 'paste.app_factory': [
161 'main=rhodecode.config.middleware:make_pyramid_app',
152 'main=rhodecode.config.middleware:make_pyramid_app',
162 ],
153 ],
General Comments 0
You need to be logged in to leave comments. Login now