def setup(): app.config["configuration"] = Configuration() while not app.config["configuration"].get_newest_config(): time.sleep(1) app.artemis_logger.info("waiting for postgrest") try: app.config["VERSION"] = "{}@{}".format(os.getenv("SYSTEM_VERSION"), os.getenv("REVISION", "HEAD")) except BaseException: app.config["VERSION"] = "Fail" app.artemis_logger.debug("failed to get version") if not os.path.isfile(app.config["DB_FULL_PATH"]): app.artemis_logger.debug("setting database for the first time") db.create_all() def create_roles(ctx): ctx.create_role(name="admin") ctx.commit() ctx.create_role(name="pending") ctx.commit() ctx.create_role(name="user") ctx.commit() create_roles(data_store) def create_user(ctx): try: email = os.getenv("USER_ROOT_EMAIL", "") username = os.getenv("USER_ROOT_USERNAME", "admin") password = os.getenv("USER_ROOT_PASSWORD", "admin") is_active = True if password: password = hash_password(password) user = ctx.create_user(username=username, email=email, password=password, active=is_active) ctx.commit() role = ctx.find_or_create_role("admin") ctx.add_role_to_user(user, role) ctx.commit() except BaseException: app.artemis_logger.exception("exception") create_user(data_store) app.extensions["security"]._unauthorized_callback = lambda: abort(400)
def setup(): app.config["configuration"] = Configuration() while not app.config["configuration"].get_newest_config(): time.sleep(1) app.artemis_logger.info("waiting for postgrest") try: app.config["VERSION"] = os.getenv("SYSTEM_VERSION") except BaseException: app.config["VERSION"] = "Fail" app.artemis_logger.debug("failed to get version") modules = Modules_state() try: app.artemis_logger.debug("Starting Database..") if not modules.is_any_up_or_running("database"): app.artemis_logger.error("Couldn't start Database.") exit(-1) except BaseException: app.artemis_logger.exception("exception while starting Database") exit(-1) try: app.artemis_logger.debug("Request status of all modules..") app.config["status"] = modules.get_response_all() except BaseException: app.artemis_logger.exception("exception while retrieving status of modules..") exit(-1) app.artemis_logger.debug("setting database for the first time") if not os.path.isfile(app.config["DB_FULL_PATH"]): db.create_all() def create_roles(ctx): ctx.create_role(name="admin") ctx.commit() ctx.create_role(name="pending") ctx.commit() ctx.create_role(name="user") ctx.commit() create_roles(data_store) def create_user(ctx): try: email = os.getenv("USER_ROOT_EMAIL", "") username = os.getenv("USER_ROOT_USERNAME", "admin") password = os.getenv("USER_ROOT_PASSWORD", "admin") is_active = True if password: password = hash_password(password) user = ctx.create_user( username=username, email=email, password=password, active=is_active ) ctx.commit() role = ctx.find_or_create_role("admin") ctx.add_role_to_user(user, role) ctx.commit() except BaseException: app.artemis_logger.exception("exception") create_user(data_store)
def setup(): app.config['configuration'] = Configuration() while not app.config['configuration'].get_newest_config(): time.sleep(1) app.artemis_logger.info('waiting for postgrest') try: app.config['VERSION'] = os.getenv('SYSTEM_VERSION') except BaseException: app.config['VERSION'] = 'Fail' app.artemis_logger.debug('failed to get version') modules = Modules_state() try: app.artemis_logger.debug('Starting Database..') modules.call('database', 'start') if not modules.is_up_or_running('database'): app.artemis_logger.error('Couldn\'t start Database.') exit(-1) except BaseException: app.artemis_logger.exception('exception while starting Database') exit(-1) try: app.artemis_logger.debug('Request status of all modules..') app.config['status'] = modules.get_response_all() except BaseException: app.artemis_logger.exception( 'exception while retrieving status of modules..') exit(-1) app.artemis_logger.debug("setting database for the first time") if not os.path.isfile(app.config['DB_FULL_PATH']): db.create_all() def create_roles(ctx): ctx.create_role(name='admin') ctx.commit() ctx.create_role(name='pending') ctx.commit() ctx.create_role(name='user') ctx.commit() create_roles(data_store) def create_user(ctx): try: email = os.getenv('USER_ROOT_EMAIL', '') username = os.getenv('USER_ROOT_USERNAME', 'admin') password = os.getenv('USER_ROOT_PASSWORD', 'admin') is_active = True if password is not None: password = hash_password(password) user = ctx.create_user(username=username, email=email, password=password, active=is_active) ctx.commit() role = ctx.find_or_create_role('admin') ctx.add_role_to_user(user, role) ctx.commit() except BaseException: app.artemis_logger.exception("exception") create_user(data_store)