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
Exemple #2
0
 def list_consents(self, provider=None):
     store = UserStore()
     d = []
     for prov, clientid, parameters in store.get_all_consents(self.name):
         if provider is not None:
             if prov != provider:
                 continue
         d.append({
             'provider': prov,
             'client': clientid,
             'attrs': json.loads(parameters)
         })
     return d
Exemple #3
0
 def load_plugin_data(self, plugin):
     store = UserStore()
     return store.load_plugin_data(plugin, self.name)
Exemple #4
0
 def save_plugin_data(self, plugin, data):
     store = UserStore()
     store.save_plugin_data(plugin, self.name, data)
Exemple #5
0
 def _get_user_data(self, username):
     store = UserStore()
     return store.load_user_preferences(username)
Exemple #6
0
 def revoke_consent(self, provider, clientid):
     store = UserStore()
     store.delete_consent(self.name, provider, clientid)
Exemple #7
0
 def grant_consent(self, provider, clientid, parameters):
     store = UserStore()
     store.store_consent(self.name, provider, clientid,
                         json.dumps(parameters))
Exemple #8
0
 def load_plugin_data(self, plugin):
     store = UserStore()
     return store.load_plugin_data(plugin, self.name)
Exemple #9
0
 def save_plugin_data(self, plugin, data):
     store = UserStore()
     store.save_plugin_data(plugin, self.name, data)
Exemple #10
0
 def _get_user_data(self, username):
     store = UserStore()
     return store.load_user_preferences(username)
Exemple #11
0
 def get_consent(self, provider, clientid):
     store = UserStore()
     data = store.get_consent(self.name, provider, clientid)
     if data is not None:
         return json.loads(data)
     return None
Exemple #12
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