diff options
author | Simo Sorce <simo@redhat.com> | 2014-10-10 15:52:01 -0400 |
---|---|---|
committer | Patrick Uiterwijk <puiterwijk@redhat.com> | 2014-10-24 18:02:20 +0200 |
commit | cecf9f6c60a048f4f7c947a969f1610695d1d3be (patch) | |
tree | 3f70a3a3aed024a2f5cbca34b39d860b73ef4c7a /ipsilon | |
parent | 19d7bd78989ae6ee603ff4f49517fd25f6bc79d0 (diff) | |
download | ipsilon-cecf9f6c60a048f4f7c947a969f1610695d1d3be.tar.gz ipsilon-cecf9f6c60a048f4f7c947a969f1610695d1d3be.tar.xz ipsilon-cecf9f6c60a048f4f7c947a969f1610695d1d3be.zip |
Do not overwrite default plugin options
Change the admin plugin to not overwrite the plugin default options,
and only use the sanctioned pluginObject interfaces to read/write
config values.
Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Patrick Uiterwijk <puiterwijk@redhat.com>
Diffstat (limited to 'ipsilon')
-rwxr-xr-x | ipsilon/admin/common.py | 49 | ||||
-rwxr-xr-x | ipsilon/util/plugin.py | 14 |
2 files changed, 36 insertions, 27 deletions
diff --git a/ipsilon/admin/common.py b/ipsilon/admin/common.py index 5928763..7f723ac 100755 --- a/ipsilon/admin/common.py +++ b/ipsilon/admin/common.py @@ -36,31 +36,27 @@ class AdminPage(Page): class AdminPluginPage(AdminPage): - def __init__(self, obj, site, parent): + def __init__(self, po, site, parent): super(AdminPluginPage, self).__init__(site, form=True) - self._obj = obj - self.title = '%s plugin' % obj.name - self.url = '%s/%s' % (parent.url, obj.name) + self._po = po + self.title = '%s plugin' % po.name + self.url = '%s/%s' % (parent.url, po.name) self.facility = parent.facility self.menu = [parent] self.back = parent.url # Get the defaults - self.plugin_config = obj.get_config_desc() - if not self.plugin_config: - self.plugin_config = dict() - - # Now overlay the actual config - for option in self.plugin_config: - self.plugin_config[option][2] = obj.get_config_value(option) + options = po.get_config_desc() + if options is None: + options = dict() self.options_order = [] - if hasattr(obj, 'conf_opt_order'): - self.options_order = obj.conf_opt_order + if hasattr(po, 'conf_opt_order'): + self.options_order = po.conf_opt_order # append any undefined options add = [] - for k in self.plugin_config.keys(): + for k in options.keys(): if k not in self.options_order: add.append(k) if len(add): @@ -72,10 +68,10 @@ class AdminPluginPage(AdminPage): def GET(self, *args, **kwargs): return self._template('admin/plugin_config.html', title=self.title, name='admin_%s_%s_form' % (self.facility, - self._obj.name), + self._po.name), menu=self.menu, action=self.url, back=self.back, options_order=self.options_order, - options=self.plugin_config) + plugin=self._po) @admin_protect def POST(self, *args, **kwargs): @@ -84,17 +80,22 @@ class AdminPluginPage(AdminPage): message_type = "info" new_values = dict() + # Get the defaults + options = self._po.get_config_desc() + if options is None: + options = dict() + for key, value in kwargs.iteritems(): - if key in self.plugin_config: - if value != self.plugin_config[key][2]: + if key in options: + if value != self._po.get_config_value(key): cherrypy.log.error("Storing [%s]: %s = %s" % - (self._obj.name, key, value)) + (self._po.name, key, value)) new_values[key] = value if len(new_values) != 0: # First we try to save in the database try: - self._obj.save_plugin_config(self.facility, new_values) + self._po.save_plugin_config(self.facility, new_values) message = "New configuration saved." message_type = "success" except Exception: # pylint: disable=broad-except @@ -102,17 +103,15 @@ class AdminPluginPage(AdminPage): message_type = "error" # And only if it succeeds we change the live object - for name, value in new_values.items(): - self._obj.set_config_value(name, value) - self.plugin_config[name][2] = value + self._po.refresh_plugin_config(self.facility) return self._template('admin/plugin_config.html', title=self.title, message=message, message_type=message_type, name='admin_%s_%s_form' % (self.facility, - self._obj.name), + self._po.name), menu=self.menu, action=self.url, - options=self.plugin_config) + plugin=self._po) class Admin(AdminPage): diff --git a/ipsilon/util/plugin.py b/ipsilon/util/plugin.py index 903f548..48edf0e 100755 --- a/ipsilon/util/plugin.py +++ b/ipsilon/util/plugin.py @@ -115,7 +115,7 @@ class PluginObject(Log): self._options = None self._data = AdminStore() - def get_config_desc(self): + def get_config_desc(self, name=None): """ The configuration description is a dictionary that provides A description of the supported configuration options, as well as the default configuration option values. @@ -124,7 +124,13 @@ class PluginObject(Log): - option type - default value """ - return self._options + if name is None: + return self._options + + opt = self._options.get(name, None) + if opt is None: + return '' + return opt[0] def set_config(self, config): self._config = config @@ -152,6 +158,10 @@ class PluginObject(Log): def get_plugin_config(self, facility): return self._data.load_options(facility, self.name) + def refresh_plugin_config(self, facility): + config = self.get_plugin_config(facility) + self.set_config(config) + def save_plugin_config(self, facility, config=None): if config is None: config = self._config |