Пример #1
0
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
        })
Пример #2
0
def init_app(app, db, 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, 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

    # Load all views.py files to register @app.routes() with Flask
    register_routes()

    init_db(app, db)
    
    if str(app.name) == 'login':
        # Initialize DB content
        init_user_roles(user_manager)
        init_admin_user(app, user_manager)
        db_adapter.commit()

    app.logger.info("Webapp started.")
    return app
Пример #3
0
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")
Пример #4
0
 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
Пример #5
0
def create_token():
    current_user.api_token = random_string(64)
    db.session.commit()
    session['api_token'] = current_user.api_token