Show More
@@ -38,7 +38,9 b' from sqlalchemy.sql.expression import tr' | |||
|
38 | 38 | from sqlalchemy.util import OrderedSet |
|
39 | 39 | from webhelpers.pylonslib.secure_form import authentication_token |
|
40 | 40 | |
|
41 |
from rhodecode.authentication import |
|
|
41 | from rhodecode.authentication import ( | |
|
42 | legacy_plugin_prefix, _import_legacy_plugin) | |
|
43 | from rhodecode.authentication.base import loadplugin | |
|
42 | 44 | from rhodecode.config.routing import ADMIN_PREFIX |
|
43 | 45 | from rhodecode.lib.auth import HasRepoGroupPermissionAny, HasPermissionAny |
|
44 | 46 | from rhodecode.lib.utils import repo_name_slug, make_db_config |
@@ -985,30 +987,71 b' def ValidAuthPlugins():' | |||
|
985 | 987 | 'import_duplicate': _( |
|
986 | 988 | u'Plugins %(loaded)s and %(next_to_load)s ' |
|
987 | 989 | u'both export the same name'), |
|
990 | 'missing_includeme': _( | |
|
991 | u'The plugin "%(plugin_id)s" is missing an includeme ' | |
|
992 | u'function.'), | |
|
993 | 'import_error': _( | |
|
994 | u'Can not load plugin "%(plugin_id)s"'), | |
|
995 | 'no_plugin': _( | |
|
996 | u'No plugin available with ID "%(plugin_id)s"'), | |
|
988 | 997 | } |
|
989 | 998 | |
|
990 | 999 | def _to_python(self, value, state): |
|
991 | 1000 | # filter empty values |
|
992 | 1001 | return filter(lambda s: s not in [None, ''], value) |
|
993 | 1002 | |
|
994 |
def validate_ |
|
|
995 | from rhodecode.authentication.base import loadplugin | |
|
996 | module_list = value | |
|
997 | unique_names = {} | |
|
1003 | def _validate_legacy_plugin_id(self, plugin_id, value, state): | |
|
1004 | """ | |
|
1005 | Validates that the plugin import works. It also checks that the | |
|
1006 | plugin has an includeme attribute. | |
|
1007 | """ | |
|
998 | 1008 | try: |
|
999 | for module in module_list: | |
|
1000 | if module.startswith(legacy_plugin_prefix): | |
|
1001 |
|
|
|
1002 | plugin = loadplugin(module) | |
|
1003 |
|
|
|
1004 | if plugin_name in unique_names: | |
|
1009 | plugin = _import_legacy_plugin(plugin_id) | |
|
1010 | except Exception as e: | |
|
1011 | log.exception( | |
|
1012 | 'Exception during import of auth legacy plugin "{}"' | |
|
1013 | .format(plugin_id)) | |
|
1014 | msg = M(self, 'import_error', plugin_id=plugin_id) | |
|
1015 | raise formencode.Invalid(msg, value, state) | |
|
1016 | ||
|
1017 | if not hasattr(plugin, 'includeme'): | |
|
1018 | msg = M(self, 'missing_includeme', plugin_id=plugin_id) | |
|
1019 | raise formencode.Invalid(msg, value, state) | |
|
1020 | ||
|
1021 | return plugin | |
|
1022 | ||
|
1023 | def _validate_plugin_id(self, plugin_id, value, state): | |
|
1024 | """ | |
|
1025 | Plugins are already imported during app start up. Therefore this | |
|
1026 | validation only retrieves the plugin from the plugin registry and | |
|
1027 | if it returns something not None everything is OK. | |
|
1028 | """ | |
|
1029 | plugin = loadplugin(plugin_id) | |
|
1030 | ||
|
1031 | if plugin is None: | |
|
1032 | msg = M(self, 'no_plugin', plugin_id=plugin_id) | |
|
1033 | raise formencode.Invalid(msg, value, state) | |
|
1034 | ||
|
1035 | return plugin | |
|
1036 | ||
|
1037 | def validate_python(self, value, state): | |
|
1038 | unique_names = {} | |
|
1039 | for plugin_id in value: | |
|
1040 | ||
|
1041 | # Validate legacy or normal plugin. | |
|
1042 | if plugin_id.startswith(legacy_plugin_prefix): | |
|
1043 | plugin = self._validate_legacy_plugin_id( | |
|
1044 | plugin_id, value, state) | |
|
1045 | else: | |
|
1046 | plugin = self._validate_plugin_id(plugin_id, value, state) | |
|
1047 | ||
|
1048 | # Only allow unique plugin names. | |
|
1049 | if plugin.name in unique_names: | |
|
1005 | 1050 |
|
|
1006 |
|
|
|
1007 |
|
|
|
1051 | loaded=unique_names[plugin.name], | |
|
1052 | next_to_load=plugin) | |
|
1008 | 1053 |
|
|
1009 |
|
|
|
1010 | except (KeyError, AttributeError, TypeError) as e: | |
|
1011 | raise formencode.Invalid(str(e), value, state) | |
|
1054 | unique_names[plugin.name] = plugin | |
|
1012 | 1055 | |
|
1013 | 1056 | return _validator |
|
1014 | 1057 |
General Comments 0
You need to be logged in to leave comments.
Login now