# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+from ipsilon.util.log import Log
from ipsilon.util.plugin import PluginLoader, PluginObject
from ipsilon.util.plugin import PluginInstaller
from ipsilon.util.page import Page
import cherrypy
-class ProviderException(Exception):
+class ProviderException(Exception, Log):
def __init__(self, message):
super(ProviderException, self).__init__(message)
def __str__(self):
return repr(self.message)
- def _debug(self, fact):
- if cherrypy.config.get('debug', False):
- cherrypy.log('%s: %s' % (self.__class__.__name__, fact))
-
class ProviderBase(PluginObject):
super(ProviderBase, self).__init__()
self.name = name
self.path = path
-
- def _debug(self, fact):
- if cherrypy.config.get('debug', False):
- cherrypy.log(fact)
+ self.tree = None
def get_tree(self, site):
raise NotImplementedError
- def enable(self, site):
- plugins = site[FACILITY]
- if self in plugins['enabled']:
+ def register(self, site):
+ if self.tree:
+ # already registered
return
# configure self
+ plugins = site[FACILITY]
if self.name in plugins['config']:
self.set_config(plugins['config'][self.name])
+ # init pages and admin interfaces
+ self.tree = self.get_tree(site)
+
+ self._debug('IdP Provider registered: %s' % self.name)
+
+ if self.get_config_value('enabled') == '1':
+ # and add self to the root
+ root = site[FACILITY]['root']
+ root.add_subtree(self.name, self.tree)
+ self._debug('IdP Provider enabled: %s' % self.name)
+
+ @property
+ def is_enabled(self):
+ if self.get_config_value('enabled') == '1':
+ return True
+ return False
+
+ def enable(self, site):
+ if self.is_enabled:
+ return
+
# and add self to the root
- root = plugins['root']
- root.add_subtree(self.name, self.get_tree(site))
+ root = site[FACILITY]['root']
+ root.add_subtree(self.name, self.tree)
- plugins['enabled'].append(self)
+ self.set_config_value('enabled', '1')
+ self.save_plugin_config(FACILITY)
self._debug('IdP Provider enabled: %s' % self.name)
def disable(self, site):
- plugins = site[FACILITY]
- if self not in plugins['enabled']:
+ if not self.is_enabled:
return
# remove self to the root
- root = plugins['root']
+ root = site[FACILITY]['root']
root.del_subtree(self.name)
- plugins['enabled'].remove(self)
+ self.set_config_value('enabled', '0')
+ self.save_plugin_config(FACILITY)
self._debug('IdP Provider disabled: %s' % self.name)
FACILITY = 'provider_config'
-class LoadProviders(object):
+class LoadProviders(Log):
def __init__(self, root, site):
loader = PluginLoader(LoadProviders, FACILITY, 'IdpProvider')
self._debug('Available providers: %s' % str(available))
providers['root'] = root
- for item in providers['whitelist']:
- self._debug('IdP Provider in whitelist: %s' % item)
- if item not in providers['available']:
- continue
- providers['available'][item].enable(site)
-
- def _debug(self, fact):
- if cherrypy.config.get('debug', False):
- cherrypy.log(fact)
+ for item in providers['available']:
+ plugin = providers['available'][item]
+ plugin.register(site)
class ProvidersInstall(object):