##// END OF EJS Templates
auth-plugins: fixed problem with cache of settings in multi-worker mode....
marcink -
r2681:c2a00a0d default
parent child Browse files
Show More
@@ -171,11 +171,6 b' class RhodeCodeAuthPluginBase(object):'
171 db_type = '{}.encrypted'.format(db_type)
171 db_type = '{}.encrypted'.format(db_type)
172 return db_type
172 return db_type
173
173
174 @LazyProperty
175 def plugin_settings(self):
176 settings = SettingsModel().get_all_settings()
177 return settings
178
179 def is_enabled(self):
174 def is_enabled(self):
180 """
175 """
181 Returns true if this plugin is enabled. An enabled plugin can be
176 Returns true if this plugin is enabled. An enabled plugin can be
@@ -185,12 +180,13 b' class RhodeCodeAuthPluginBase(object):'
185 auth_plugins = SettingsModel().get_auth_plugins()
180 auth_plugins = SettingsModel().get_auth_plugins()
186 return self.get_id() in auth_plugins
181 return self.get_id() in auth_plugins
187
182
188 def is_active(self):
183 def is_active(self, plugin_cached_settings=None):
189 """
184 """
190 Returns true if the plugin is activated. An activated plugin is
185 Returns true if the plugin is activated. An activated plugin is
191 consulted during authentication, assumed it is also enabled.
186 consulted during authentication, assumed it is also enabled.
192 """
187 """
193 return self.get_setting_by_name('enabled')
188 return self.get_setting_by_name(
189 'enabled', plugin_cached_settings=plugin_cached_settings)
194
190
195 def get_id(self):
191 def get_id(self):
196 """
192 """
@@ -210,13 +206,24 b' class RhodeCodeAuthPluginBase(object):'
210 """
206 """
211 return AuthnPluginSettingsSchemaBase()
207 return AuthnPluginSettingsSchemaBase()
212
208
213 def get_setting_by_name(self, name, default=None, cache=True):
209 def get_settings(self):
210 """
211 Returns the plugin settings as dictionary.
212 """
213 settings = {}
214 raw_settings = SettingsModel().get_all_settings()
215 for node in self.get_settings_schema():
216 settings[node.name] = self.get_setting_by_name(
217 node.name, plugin_cached_settings=raw_settings)
218 return settings
219
220 def get_setting_by_name(self, name, default=None, plugin_cached_settings=None):
214 """
221 """
215 Returns a plugin setting by name.
222 Returns a plugin setting by name.
216 """
223 """
217 full_name = 'rhodecode_{}'.format(self._get_setting_full_name(name))
224 full_name = 'rhodecode_{}'.format(self._get_setting_full_name(name))
218 if cache:
225 if plugin_cached_settings:
219 plugin_settings = self.plugin_settings
226 plugin_settings = plugin_cached_settings
220 else:
227 else:
221 plugin_settings = SettingsModel().get_all_settings()
228 plugin_settings = SettingsModel().get_all_settings()
222
229
@@ -235,15 +242,6 b' class RhodeCodeAuthPluginBase(object):'
235 full_name, value, type_)
242 full_name, value, type_)
236 return db_setting.app_settings_value
243 return db_setting.app_settings_value
237
244
238 def get_settings(self):
239 """
240 Returns the plugin settings as dictionary.
241 """
242 settings = {}
243 for node in self.get_settings_schema():
244 settings[node.name] = self.get_setting_by_name(node.name)
245 return settings
246
247 def log_safe_settings(self, settings):
245 def log_safe_settings(self, settings):
248 """
246 """
249 returns a log safe representation of settings, without any secrets
247 returns a log safe representation of settings, without any secrets
@@ -685,7 +683,8 b' def authenticate(username, password, env'
685 environ=environ or {})
683 environ=environ or {})
686
684
687 if plugin_cache_active:
685 if plugin_cache_active:
688 log.debug('Trying to fetch cached auth by `...%s`', _password_hash[:6])
686 log.debug('Trying to fetch cached auth by pwd hash `...%s`',
687 _password_hash[:6])
689 plugin_user = cache_manager.get(
688 plugin_user = cache_manager.get(
690 _password_hash, createfunc=auth_func)
689 _password_hash, createfunc=auth_func)
691 else:
690 else:
@@ -70,9 +70,11 b' class AuthenticationPluginRegistry(objec'
70 # Add all enabled and active plugins to the list. We iterate over the
70 # Add all enabled and active plugins to the list. We iterate over the
71 # auth_plugins setting from DB because it also represents the ordering.
71 # auth_plugins setting from DB because it also represents the ordering.
72 enabled_plugins = SettingsModel().get_auth_plugins()
72 enabled_plugins = SettingsModel().get_auth_plugins()
73 raw_settings = SettingsModel().get_all_settings()
73 for plugin_id in enabled_plugins:
74 for plugin_id in enabled_plugins:
74 plugin = self.get_plugin(plugin_id)
75 plugin = self.get_plugin(plugin_id)
75 if plugin is not None and plugin.is_active():
76 if plugin is not None and plugin.is_active(
77 plugin_cached_settings=raw_settings):
76 plugins.append(plugin)
78 plugins.append(plugin)
77
79
78 # Add the fallback plugin from ini file.
80 # Add the fallback plugin from ini file.
@@ -63,7 +63,7 b' class AuthnPluginViewBase(BaseAppView):'
63 for node in schema:
63 for node in schema:
64 if node.name not in defaults:
64 if node.name not in defaults:
65 defaults[node.name] = self.plugin.get_setting_by_name(
65 defaults[node.name] = self.plugin.get_setting_by_name(
66 node.name, node.default, cache=False)
66 node.name, node.default)
67
67
68 template_context = {
68 template_context = {
69 'defaults': defaults,
69 'defaults': defaults,
General Comments 0
You need to be logged in to leave comments. Login now