def _storeConfigEntryDB(key, value, typ=None, desc=None): """ lowest level for storing database entries in the config table """ confEntries = Session.query(Config).filter(Config.Key == unicode(key)) theConf = None # update if confEntries.count() == 1: theConf = confEntries[0] theConf.Value = unicode(value) if (typ is not None): theConf.Type = unicode(typ) if (desc is not None): theConf.Description = unicode(desc) # insert elif confEntries.count() == 0: theConf = Config( Key=unicode(key), Value=unicode(value), Type=unicode(typ), Description=unicode(desc) ) if theConf is not None: Session.add(theConf) return 101
def _storeConfigEntryDB(key, value, typ=None, desc=None): """ lowest level for storing database entries in the config table """ confEntries = Config.query.filter_by(Key=str(key)) theConf = None # update if confEntries.count() == 1: theConf = confEntries[0] theConf.Value = str(value) theConf.Type = typ theConf.Description = desc # insert elif confEntries.count() == 0: theConf = Config(Key=str(key), Value=str(value), Type=str(typ), Description=str(desc)) if theConf is not None: db.session.add(theConf) return 101
def test_setup_db_erase_all(app, engine, capsys, erase): app.echo = Echo(verbosity=1) # GIVEN a database with records app.cli_cmd = "init-database" setup_db(app) init_db_tables(app, drop_data=True, add_defaults=True) KEY = "linotp.foobar" item = Config(Key=KEY, Value="123", Type="int", Description="test item") db.session.add(item) db.session.commit() assert db.session.query(Config).filter_by(Key=KEY).count() == 1 db.session.remove() # WHEN I invoke `setup_db` setup_db(app) init_db_tables(app, drop_data=erase, add_defaults=False) if erase: # Additional record should have disappeared assert db.session.query(Config).filter_by(Key=KEY).count() == 0 else: # Additional record should still be there assert db.session.query(Config).filter_by(Key=KEY).count() == 1 item = db.session.query(Config).filter_by(Key=KEY).first() db.session.delete(item) db.session.commit()
def set_version(self, version): """ set the version new db model number - on update: update the entry - on new: create new db entry :param version: set the new db model version """ if version == self.current_version: return config_entry = self._query_version() if config_entry: config_entry.Value = version else: config_entry = Config(Key=self.db_model_key, Value=version) db.session.add(config_entry)
def _storeConfigDB(key, val, typ=None, desc=None): value = val log.debug('storeConfigDB: key %r : value %r' % (key, value)) if (not key.startswith("linotp.")): key = "linotp." + key confEntries = Session.query(Config).filter(Config.Key == unicode(key)) theConf = None if typ is not None and typ == 'password': value = encryptPassword(val) en = decryptPassword(value) if (en != val): raise Exception( "StoreConfig: Error during encoding password type!") # # update if confEntries.count() == 1: theConf = confEntries[0] theConf.Value = unicode(value) if (typ is not None): theConf.Type = unicode(typ) if (desc is not None): theConf.Description = unicode(desc) # # insert elif confEntries.count() == 0: theConf = Config(Key=unicode(key), Value=unicode(value), Type=unicode(typ), Description=unicode(desc)) if theConf is not None: Session.add(theConf) return 101