def __enter__(self): if not os.access('/tmp/openEASE/dockerbridge/', os.W_OK): client.notify("files_lft_set_writeable") self.lftdir = os.path.join('/tmp/openEASE/dockerbridge', random_string(16)) os.mkdir(self.lftdir) return self
def generate_rosauth(user_container_name, dest, cache=False): """ Generate the mac for use with rosauth and compile a json object with all necessary information to authenticate with the server. :param user_container_name: Name of the user container :param dest: IP of the destination :return: a json object for ros """ client = request.remote_addr rand = random_string(30) t = int(time.time()) level = "user" end = int(t + 3600) return jsonify({ 'mac': generate_mac(user_container_name, client, dest, rand, t, level, end, cache), 'client': client, 'dest': dest, 'rand': rand, 't': t, 'level': level, 'end': end })
def init_app(app, db_instance, extra_config_settings={}): # Initialize app config settings app.config.from_object("webrob.config.settings") # Read config from 'app/settings.py' file app.config.update(extra_config_settings) # Overwrite with 'extra_config_settings' parameter if app.testing: app.config["WTF_CSRF_ENABLED"] = False # Disable CSRF checks while testing if os.environ["EASE_DEBUG"] == "true": app.config["DEBUG"] = True app.config["SECRET_KEY"] = app.config["DEV_SECRET_KEY"] else: try: app.config["SECRET_KEY"] = open("/etc/ease_secret/secret", "rb").read() except IOError: app.config["SECRET_KEY"] = random_string(64) # Setup Flask-Mail mail = Mail(app) babel = Babel(app) # Setup Flask-User to handle user account related forms from webrob.models.users import User db_adapter = SQLAlchemyAdapter(db_instance, User) app.user_manager = UserManager(db_adapter, app) # Init Flask-User and bind to app # Load all models.py files to register db.Models with SQLAlchemy from webrob.models import users from webrob.models import tutorials from webrob.models import teaching from webrob.models import experiments # Load all views.py files to register @app.routes() with Flask from webrob.pages import api from webrob.pages import db from webrob.pages import editor from webrob.pages import experiments from webrob.pages import knowrob from webrob.pages import login from webrob.pages import meshes from webrob.pages import mongo from webrob.pages import tutorials from webrob.pages import oauth init_db(app, db_instance) init_webapp(app, db_instance) add_user( app=app, db=db_instance, user_manager=app.user_manager, name="admin", mail=os.environ.get("OPENEASE_MAIL_USERNAME", "*****@*****.**"), pw=os.environ.get("OPENEASE_ADMIN_PASSWORD"), roles=["admin"], ) app.logger.info("Webapp started.") return app
def init_app(app, db_instance, extra_config_settings={}): # Initialize app config settings app.config.from_object('webrob.config.settings') # Read config from 'app/settings.py' file app.config.update(extra_config_settings) # Overwrite with 'extra_config_settings' parameter if app.testing: app.config['WTF_CSRF_ENABLED'] = False # Disable CSRF checks while testing if os.environ['EASE_DEBUG'] == 'true': app.config['DEBUG'] = True app.config['SECRET_KEY'] = app.config['DEV_SECRET_KEY'] else: try: app.config['SECRET_KEY'] = open('/etc/ease_secret/secret', 'rb').read() except IOError: app.config['SECRET_KEY'] = random_string(64) # Setup Flask-Mail mail = Mail(app) babel = Babel(app) # Setup Flask-User to handle user account related forms from webrob.models.users import User db_adapter = SQLAlchemyAdapter(db_instance, User) user_manager = UserManager(db_adapter, app) # Init Flask-User and bind to app # Load all models.py files to register db.Models with SQLAlchemy from webrob.models import users from webrob.models import tutorials from webrob.models import experiments # Load all views.py files to register @app.routes() with Flask from webrob.pages import api from webrob.pages import db from webrob.pages import editor from webrob.pages import experiments from webrob.pages import knowrob from webrob.pages import login from webrob.pages import meshes from webrob.pages import mongo from webrob.pages import tutorials init_db(app, db_instance) init_webapp(app, db_instance) add_user(app,db_instance,user_manager,'admin', os.environ.get('OPENEASE_MAIL_USERNAME', '*****@*****.**'), os.environ.get('OPENEASE_ADMIN_PASSWORD'), ['admin']) app.logger.info("Webapp started.") return app
def start_user_container(application_image, user_container_name): """ Starts a user container based on the given image. If the container already exists, it will stop and remove the container first. Also, a data container is created and mounted inside the given container, and a rosauth secret is generated. Note that containers are stopped and removed after 10 minutes if the refresh function is not called periodically beforehand. :param application_image: Image the container should be based on :param user_container_name: Name of the container. """ try: client.notify("create_user_data_container", user_container_name) client.notify("files_writesecret", user_container_name, random_string(16)) clear_secretcache() client.notify("start_user_container", application_image, user_container_name) except JsonRpcError, e: flash("Error: Connection to your OpenEASE instance failed.") app.logger.error("ConnectionError during connect: " + str(e.message) + str(e.data) + "\n")
def __enter__(self): if not os.access("/tmp/openEASE/dockerbridge/", os.W_OK): client.notify("files_lft_set_writeable") self.lftdir = os.path.join("/tmp/openEASE/dockerbridge", random_string(16)) os.mkdir(self.lftdir) return self
def create_token(): current_user.api_token = random_string(64) db.session.commit() session['api_token'] = current_user.api_token