예제 #1
0
def execute_upgrade(cfgfile):
    cherrypy.lib.sessions.SqlSession = ipsilon.util.sessions.SqlSession
    cherrypy.config.update(cfgfile)

    # pylint: disable=protected-access
    Store._is_upgrade = True

    adminstore = AdminStore()
    # First try to upgrade the config store before continuing
    if not _upgrade_database(adminstore):
        return upgrade_failed()

    admin_config = adminstore.load_config()
    for option in admin_config:
        cherrypy.config[option] = admin_config[option]

    # Initialize a minimal env
    template_env = Environment(loader=FileSystemLoader(os.path.join(cherrypy.config["base.dir"], "templates")))
    root = Root("default", template_env)

    # Handle the session store if that is Sql
    logger.debug("Handling sessions datastore")
    if cherrypy.config["tools.sessions.storage_type"] != "sql":
        logger.debug("Not SQL-based, skipping")
    else:
        dburi = cherrypy.config["tools.sessions.storage_dburi"]
        SqlSession.setup(storage_dburi=dburi)
        if not _upgrade_database(SqlSession._store):
            return upgrade_failed()

    # Now handle the rest of the default datastores
    for store in [UserStore, TranStore]:
        store = store()
        logger.debug("Handling default datastore %s", store.__class__.__name__)
        if not _upgrade_database(store):
            return upgrade_failed()

    # And now datastores for any of the plugins
    userstore = UserStore()
    for facility in ["provider_config", "login_config", "info_config"]:
        for plugin in root._site[facility].enabled:
            logger.debug("Handling plugin %s", plugin)
            plugin = root._site[facility].available[plugin]
            logger.debug("Creating plugin AdminStore table")
            adminstore.create_plugin_data_table(plugin.name)
            logger.debug("Creating plugin UserStore table")
            userstore.create_plugin_data_table(plugin.name)
            for store in plugin.used_datastores():
                logger.debug("Handling plugin datastore %s", store.__class__.__name__)
                if not _upgrade_database(store):
                    return upgrade_failed()

    # We are done with the init/upgrade
    # pylint: disable=protected-access
    Store._is_upgrade = False
예제 #2
0
 def _data(self):
     if not self.uses_store:
         raise Exception('Tried to get plugin data while ' +
                         'uses_store=False (%s)' % self.facility)
     if not self.__data:
         self.__data = AdminStore()
     return self.__data
예제 #3
0
 def __init__(self, plugins):
     self.name = None
     self._config = None
     self._data = AdminStore()
     self._plugins = plugins
     self.is_enabled = False
예제 #4
0
class PluginObject(Log):

    def __init__(self, plugins):
        self.name = None
        self._config = None
        self._data = AdminStore()
        self._plugins = plugins
        self.is_enabled = False

    @property
    def is_readonly(self):
        return self._data.is_readonly

    def on_enable(self):
        return

    def on_disable(self):
        return

    def save_enabled_state(self):
        enabled = []
        self._plugins.refresh_enabled()
        enabled.extend(self._plugins.enabled)
        if self.is_enabled:
            if self.name not in enabled:
                enabled.append(self.name)
        else:
            if self.name in enabled:
                enabled.remove(self.name)
        self._plugins.save_enabled(enabled)

    def enable(self):
        if self.is_enabled:
            return

        self.refresh_plugin_config()
        self.on_enable()
        self._data.create_plugin_data_table(self.name)
        is_upgrade = Store._is_upgrade  # pylint: disable=protected-access
        try:
            Store._is_upgrade = True  # pylint: disable=protected-access
            for store in self.used_datastores():
                store.upgrade_database()
        finally:
            Store._is_upgrade = is_upgrade  # pylint: disable=protected-access
        self.is_enabled = True
        self.debug('Plugin enabled: %s' % self.name)

    def disable(self):
        if not self.is_enabled:
            return

        self.on_disable()

        self.is_enabled = False
        self.debug('Plugin disabled: %s' % self.name)

    def used_datastores(self):
        return []

    def import_config(self, config):
        self._config = config

    def export_config(self):
        return self._config

    def get_plugin_config(self):
        return self._data.load_options(self._plugins.facility, self.name)

    def refresh_plugin_config(self):
        config = self.get_plugin_config()
        if config:
            try:
                self.import_config(config)
            except Exception, e:  # pylint: disable=broad-except
                self.error('Failed to refresh config for %s (%s)' %
                           (self.name, e))
예제 #5
0
 def __init__(self, plugins):
     self.name = None
     self._config = None
     self._data = AdminStore()
     self._plugins = plugins
     self.is_enabled = False
예제 #6
0
class PluginObject(Log):
    def __init__(self, plugins):
        self.name = None
        self._config = None
        self._data = AdminStore()
        self._plugins = plugins
        self.is_enabled = False

    @property
    def is_readonly(self):
        return self._data.is_readonly

    def on_enable(self):
        return

    def on_disable(self):
        return

    def on_reconfigure(self):
        return

    def save_enabled_state(self):
        enabled = []
        self._plugins.refresh_enabled()
        enabled.extend(self._plugins.enabled)
        if self.is_enabled:
            if self.name not in enabled:
                enabled.append(self.name)
        else:
            if self.name in enabled:
                enabled.remove(self.name)
        self._plugins.save_enabled(enabled)

    def enable(self):
        if self.is_enabled:
            return

        self.refresh_plugin_config()
        self.on_enable()
        self._data.create_plugin_data_table(self.name)
        is_upgrade = Store._is_upgrade  # pylint: disable=protected-access
        try:
            Store._is_upgrade = True  # pylint: disable=protected-access
            for store in self.used_datastores():
                store.upgrade_database()
        finally:
            Store._is_upgrade = is_upgrade  # pylint: disable=protected-access
        self.is_enabled = True
        self.debug('Plugin enabled: %s' % self.name)

    def disable(self):
        if not self.is_enabled:
            return

        self.on_disable()

        self.is_enabled = False
        self.debug('Plugin disabled: %s' % self.name)

    def used_datastores(self):
        return []

    def import_config(self, config):
        self._config = config

    def export_config(self):
        return self._config

    def get_plugin_config(self):
        return self._data.load_options(self._plugins.facility, self.name)

    def refresh_plugin_config(self):
        config = self.get_plugin_config()
        if config:
            try:
                self.import_config(config)
            except Exception as e:  # pylint: disable=broad-except
                self.error('Failed to refresh config for %s (%s)' %
                           (self.name, e))
        self.on_reconfigure()

    def save_plugin_config(self, config=None):
        if config is None:
            config = self.export_config()

        self._data.save_options(self._plugins.facility, self.name, config)

    def get_data(self, idval=None, name=None, value=None):
        return self._data.get_data(self.name,
                                   idval=idval,
                                   name=name,
                                   value=value)

    def save_data(self, data):
        self._data.save_data(self.name, data)

    def new_datum(self, datum):
        self._data.new_datum(self.name, datum)

    def del_datum(self, idval):
        self._data.del_datum(self.name, idval)

    def wipe_config_values(self):
        self._data.delete_options(self._plugins.facility, self.name, None)

    def wipe_data(self):
        self._data.wipe_data(self.name)
예제 #7
0
def execute_upgrade(cfgfile):
    cherrypy.lib.sessions.SqlSession = ipsilon.util.sessions.SqlSession
    cherrypy.lib.sessions.EtcdSession = ipsilon.util.sessions.EtcdSession
    cherrypy.config.update(cfgfile)

    # pylint: disable=protected-access
    Store._is_upgrade = True

    adminstore = AdminStore()
    # First try to upgrade the config store before continuing
    if _upgrade_database(adminstore) not in [True, None]:
        return upgrade_failed()

    admin_config = adminstore.load_config()
    for option in admin_config:
        cherrypy.config[option] = admin_config[option]

    # Initialize a minimal env
    template_env = Environment(loader=FileSystemLoader(
        os.path.join(cherrypy.config['base.dir'], 'templates')))
    root = Root('default', template_env)

    # Handle the session store if that is Sql
    logger.info('Handling sessions datastore')
    sesstype = cherrypy.config['tools.sessions.storage_type'].lower()
    if sesstype == 'sql':
        dburi = cherrypy.config['tools.sessions.storage_dburi']
        SqlSession.setup(storage_dburi=dburi)
        if _upgrade_database(SqlSession._store) not in [True, None]:
            return upgrade_failed()
    elif sesstype == 'etcd':
        dburi = cherrypy.config['tools.sessions.storage_dburi']
        EtcdSession.setup(storage_dburi=dburi)
        if _upgrade_database(EtcdSession._store) not in [True, None]:
            return upgrade_failed()
    else:
        logger.info('File based, skipping')

    # Now handle the rest of the default datastores
    for store in [UserStore, TranStore]:
        store = store()
        logger.info('Handling default datastore %s', store.__class__.__name__)
        if _upgrade_database(store) not in [True, None]:
            return upgrade_failed()

    # And now datastores for any of the plugins
    userstore = UserStore()
    for facility in [
            'provider_config', 'login_config', 'info_config', 'authz_config'
    ]:
        for plugin in root._site[facility].enabled:
            logger.info('Handling plugin %s', plugin)
            plugin = root._site[facility].available[plugin]
            logger.info('Creating plugin AdminStore table')
            adminstore.create_plugin_data_table(plugin.name)
            logger.info('Creating plugin UserStore table')
            userstore.create_plugin_data_table(plugin.name)
            for store in plugin.used_datastores():
                logger.info('Handling plugin datastore %s',
                            store.__class__.__name__)
                if _upgrade_database(store) not in [True, None]:
                    return upgrade_failed()

    # We are done with the init/upgrade
    # pylint: disable=protected-access
    Store._is_upgrade = False