##// END OF EJS Templates
authn: Don't use setting value to compute the setting type.
johbo -
r232:299ebd92 default
parent child Browse files
Show More
@@ -22,6 +22,7 b''
22 Authentication modules
22 Authentication modules
23 """
23 """
24
24
25 import colander
25 import logging
26 import logging
26 import time
27 import time
27 import traceback
28 import traceback
@@ -97,11 +98,10 b' class RhodeCodeAuthPluginBase(object):'
97 # Mapping of python to DB settings model types. Plugins may override or
98 # Mapping of python to DB settings model types. Plugins may override or
98 # extend this mapping.
99 # extend this mapping.
99 _settings_type_map = {
100 _settings_type_map = {
100 str: 'str',
101 colander.String: 'unicode',
101 int: 'int',
102 colander.Integer: 'int',
102 unicode: 'unicode',
103 colander.Boolean: 'bool',
103 bool: 'bool',
104 colander.List: 'list',
104 list: 'list',
105 }
105 }
106
106
107 def __init__(self, plugin_id):
107 def __init__(self, plugin_id):
@@ -119,16 +119,19 b' class RhodeCodeAuthPluginBase(object):'
119 # PluginSetting or to use the plugin id here.
119 # PluginSetting or to use the plugin id here.
120 return 'auth_{}_{}'.format(self.name, name)
120 return 'auth_{}_{}'.format(self.name, name)
121
121
122 def _get_setting_type(self, name, value):
122 def _get_setting_type(self, name):
123 """
124 Return the type of a setting. This type is defined by the SettingsModel
125 and determines how the setting is stored in DB. Optionally the suffix
126 `.encrypted` is appended to instruct SettingsModel to store it
127 encrypted.
123 """
128 """
124 Get the type as used by the SettingsModel accordingly to type of passed
129 schema_node = self.get_settings_schema().get(name)
125 value. Optionally the suffix `.encrypted` is appended to instruct
130 db_type = self._settings_type_map.get(
126 SettingsModel to store it encrypted.
131 schema_node.typ.__class__, 'unicode')
127 """
128 type_ = self._settings_type_map.get(type(value), 'unicode')
129 if name in self._settings_encrypted:
132 if name in self._settings_encrypted:
130 type_ = '{}.encrypted'.format(type_)
133 db_type = '{}.encrypted'.format(db_type)
131 return type_
134 return db_type
132
135
133 def is_enabled(self):
136 def is_enabled(self):
134 """
137 """
@@ -177,7 +180,7 b' class RhodeCodeAuthPluginBase(object):'
177 Create or update a setting for this plugin in the persistent storage.
180 Create or update a setting for this plugin in the persistent storage.
178 """
181 """
179 full_name = self._get_setting_full_name(name)
182 full_name = self._get_setting_full_name(name)
180 type_ = self._get_setting_type(name, value)
183 type_ = self._get_setting_type(name)
181 db_setting = SettingsModel().create_or_update_setting(
184 db_setting = SettingsModel().create_or_update_setting(
182 full_name, value, type_)
185 full_name, value, type_)
183 return db_setting.app_settings_value
186 return db_setting.app_settings_value
General Comments 0
You need to be logged in to leave comments. Login now