def set_dbproxy(dbUser, userName): b = Borg() dbPasswd = current_user.dbtoken dbUser = canonicalDbUser(dbUser) dbName = dbUser + '_default' db_proxy = MySQLDatabaseProxy(user=dbUser, passwd=dbPasswd, db=dbName) pSettings = db_proxy.getProjectSettings() id = b.init_settings() db_proxy.close() session['session_id'] = id b.settings[id]['dbProxy'] = db_proxy b.settings[id]['dbUser'] = dbUser b.settings[id]['userName'] = userName b.settings[id]['dbPasswd'] = dbPasswd b.settings[id]['dbHost'] = b.dbHost b.settings[id]['dbPort'] = b.dbPort b.settings[id]['dbName'] = dbName b.settings[id]['rPasswd'] = b.rPasswd b.settings[id]['fontSize'] = pSettings['Font Size'] b.settings[id]['apFontSize'] = pSettings['AP Font Size'] b.settings[id]['fontName'] = pSettings['Font Name'] b.settings[id]['jsonPrettyPrint'] = False return b.settings[id]
def main(): parser = argparse.ArgumentParser( description= 'Computer Aided Integration of Requirements and Information Security - Backup server' ) parser.add_argument('tarArchive', help='Model archive tarball to be created ') args = parser.parse_args() cairis.core.BorgFactory.initialise() b = Borg() aNames = accounts(b.rPasswd, b.dbHost, b.dbPort) for email in aNames: userPasswd = dbtoken(b.rPasswd, b.dbHost, b.dbPort, email) dbUser = canonicalDbUser(email) dbName = dbUser + '_default' dbProxy = MySQLDatabaseProxy(b.dbHost, b.dbPort, dbUser, userPasswd, dbName) packageFile = b.tmpDir + '/' + email + '.cairis' try: exportPackage(packageFile, None, 0, dbProxy) logger.info('Exported ' + email + ' default database') except ARMException as ex: logger.info('Error exporting ' + email + ' default database : ' + str(ex)) exportPackage(packageFile, None, 1, dbProxy) logger.info('Exported ' + email + ' default database by ignoring validity checks') dbProxy.close() with tarfile.open(args.tarArchive, 'w') as archive: for p in os.listdir(b.tmpDir): modelName = b.tmpDir + '/' + p archive.add(modelName, arcname=p, filter=lambda x: x if x.name.endswith('.cairis') else None) hashFile = b.tmpDir + '/hashes.txt' with open(hashFile, 'w') as f: f.write('\n'.join( list( map(lambda x: ','.join(x), emailHashes(b.rPasswd, b.dbHost, b.dbPort))))) archive.add(hashFile, arcname='hashes.txt')
def set_dbproxy(): b = Borg() db_proxy = MySQLDatabaseProxy() pSettings = db_proxy.getProjectSettings() id = b.init_settings() db_proxy.close() session['session_id'] = id b.settings[id]['dbProxy'] = db_proxy b.settings[id]['dbUser'] = b.dbUser b.settings[id]['dbPasswd'] = b.dbPasswd b.settings[id]['dbHost'] = b.dbHost b.settings[id]['dbPort'] = b.dbPort b.settings[id]['dbName'] = b.dbName b.settings[id]['fontSize'] = pSettings['Font Size'] b.settings[id]['apFontSize'] = pSettings['AP Font Size'] b.settings[id]['fontName'] = pSettings['Font Name'] b.settings[id]['jsonPrettyPrint'] = False return b.settings[id]
def set_dbproxy(): b = Borg() db_proxy = MySQLDatabaseProxy() pSettings = db_proxy.getProjectSettings() id = b.init_settings() db_proxy.close() session['session_id'] = id b.settings[id]['dbProxy'] = db_proxy b.settings[id]['dbUser'] = b.dbUser b.settings[id]['dbPasswd'] = b.dbPasswd b.settings[id]['dbHost'] = b.dbHost b.settings[id]['dbPort'] = b.dbPort b.settings[id]['dbName'] = b.dbName b.settings[id]['fontSize'] = pSettings['Font Size'] b.settings[id]['apFontSize'] = pSettings['AP Font Size'] b.settings[id]['fontName'] = pSettings['Font Name'] b.settings[id]['jsonPrettyPrint'] = False return b.settings[id]
def set_dbproxy(dbUser,userName): b = Borg() dbName = dbUser + '_default' dbPasswd = current_user.dbtoken db_proxy = MySQLDatabaseProxy(user=dbUser,passwd=dbPasswd,db=dbName) pSettings = db_proxy.getProjectSettings() id = b.init_settings() db_proxy.close() session['session_id'] = id b.settings[id]['dbProxy'] = db_proxy b.settings[id]['dbUser'] = dbUser b.settings[id]['userName'] = userName b.settings[id]['dbPasswd'] = dbPasswd b.settings[id]['dbHost'] = b.dbHost b.settings[id]['dbPort'] = b.dbPort b.settings[id]['dbName'] = dbName b.settings[id]['rPasswd'] = b.rPasswd b.settings[id]['fontSize'] = pSettings['Font Size'] b.settings[id]['apFontSize'] = pSettings['AP Font Size'] b.settings[id]['fontName'] = pSettings['Font Name'] b.settings[id]['jsonPrettyPrint'] = False return b.settings[id]
def validate_proxy(session, id, request=None, conf=None): """ Validates that the DB proxy object is properly set up :param session: The session object of the request :param id: The session ID provided by the user :param conf: A dictionary containing configuration settings for direct authenrication :return: The MySQLDatabaseProxy object associated to the session :rtype : MySQLDatabaseProxy :raise CairisHTTPError: Raises a CairisHTTPError when the database could not be properly set up """ if session is not None: session_id = session.get('session_id', -1) else: session_id = None if conf is not None: if isinstance(conf, dict): try: db_proxy = MySQLDatabaseProxy(host=conf['host'], port=conf['port'], user=conf['user'], passwd=conf['passwd'], db=conf['db']) if db_proxy is not None: return db_proxy else: raise CairisHTTPError( status_code=httplib.CONFLICT, message='The database connection could not be created.' ) except DatabaseProxyException: raise CairisHTTPError( status_code=httplib.BAD_REQUEST, message= 'The provided settings are invalid and cannot be used to create a database connection' ) if not (session_id is None and id is None): if id is None: id = session_id b = Borg() db_proxy = b.get_dbproxy(id) if db_proxy is None: raise CairisHTTPError( status_code=httplib.CONFLICT, message='The database connection could not be created.') elif isinstance(db_proxy, MySQLDatabaseProxy): return db_proxy else: raise CairisHTTPError( status_code=httplib.CONFLICT, message= 'The database connection was not properly set up. Please try to reset the connection.' ) else: raise CairisHTTPError( status_code=httplib.BAD_REQUEST, message= 'The session is neither started or no session ID is provided with the request.' )
def __init__(self, host=None, port=None, user=None, passwd=None, db=None): MySQLDatabaseProxy.__init__(self, host, port, user, passwd, db)