Esempio n. 1
0
    def setUp(self):
        test_config_file = StringIO('''
[flask]
; should be a string
secret_key                 : 12345678
debug                      : true
permanent_session_lifetime : 100
server_name                = testserv
send_file_max_age_default  : 3600
some_other_flask_var       : something with multiple words

[wibble]
wobble : woo
warble = 123

[foo bar]
bar : http://baz/qux
interp : %(bar)s/hi
''')
        app = flask.Flask(__name__)
        with app.app_context():
            app.iniconfig = FlaskIni()
            # Tests the readfp() primarily - separate test case for read()
            app.iniconfig.readfp(test_config_file)

        @app.route('/hello')
        def hello_world():
            return 'Hello world!'

        self.app = app
Esempio n. 2
0
def create_app(config='config/askomics.ini',
               app_name='askomics',
               blueprints=None):
    """Create the AskOmics app

    Parameters
    ----------
    config : str, optional
        Path to the config file
    app_name : str, optional
        Application name
    blueprints : None, optional
        Flask blueprints

    Returns
    -------
    Flask
        AskOmics Flask application
    """
    conf = configparser.ConfigParser()
    conf.read(config)

    sentry_dsn = None
    try:
        sentry_dsn = conf['sentry']['server_dsn']
    except Exception:
        pass

    if sentry_dsn:
        version = get_distribution('askomics').version
        name = get_distribution('askomics').project_name
        sentry_sdk.init(dsn=sentry_dsn,
                        release="{}@{}".format(name, version),
                        integrations=[FlaskIntegration(),
                                      CeleryIntegration()])

    app = Flask(app_name, static_folder='static', template_folder='templates')

    app.iniconfig = FlaskIni()

    with app.app_context():

        app.iniconfig.read(config)
        proxy_path = None
        try:
            proxy_path = app.iniconfig.get('askomics', 'reverse_proxy_path')
            app.config['REVERSE_PROXY_PATH'] = proxy_path
        except Exception:
            pass

        if blueprints is None:
            blueprints = BLUEPRINTS

        for blueprint in blueprints:
            app.register_blueprint(blueprint)

    if proxy_path:
        ReverseProxyPrefixFix(app)

    return app
Esempio n. 3
0
config_file = os.getenv('LAUNCHER_CONFIG', 'settings.ini')
assert config_file is not None and os.path.isfile(
    config_file), "invalid LAUNCHER_CONFIG"

default_file = os.path.join(os.path.dirname(config_file), "default.json")
assert os.path.isfile(
    default_file), "Cannot find default.json: %s" % default_file

with open(default_file) as default_fh:
    default_config = default_fh.read()
    base_config = json.loads(default_config)
    assert 'storages' in base_config, "incomplete configuration - missing " \
                                      "`storages` in %s" % default_file

app.iniconfig = FlaskIni()
with app.app_context():
    app.iniconfig.read(config_file)

app.logger.setLevel(
    logging.getLevelName(
        app.iniconfig.get('default', 'log_level', fallback='ERROR')))

redis_db = RedisDatabase(app.iniconfig.get('redis', 'host'),
                         app.iniconfig.get('redis', 'port', fallback=6379),
                         app.iniconfig.get('redis', 'db', fallback=0),
                         app.iniconfig.get('redis', 'password', fallback=None))

redis_db_without_decode = RedisDatabase(
    app.iniconfig.get('redis', 'host'),
    app.iniconfig.get('redis', 'port', fallback=6379),
Esempio n. 4
0
 def setUp(self):
     app = flask.Flask(__name__)
     app.iniconfig = FlaskIni()
     self.app = app
     self.filename = 'test_config.ini'
Esempio n. 5
0
from datetime import timedelta
from flask import make_response, request, current_app
from functools import update_wrapper
from flask_cors import CORS, cross_origin
from aggregations import plotA1, plotA2, plotA3, plotA4, plotA5, plotB1, plotB2, plotB3, plotB4, plotB5

UPLOAD_FOLDER = '/data'
ALLOWED_EXTENSIONS = ['csv']

# Flask init
application = Flask(__name__)
application.logger.info("application.py init")
application.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

with application.app_context():
    application.iniconfig = FlaskIni()
    application.iniconfig.read(os.environ['APP_SETTINGS'])
    application.logger.info("Loading application settings")

CORS(application)


def allowed_file(filename):
    return '.' in filename and \
           filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS


@application.route('/upload', methods=['GET', 'POST'])
def upload():
    if request.method == 'POST':
        # check if the post request has the file part
Esempio n. 6
0
def create_app(config='config/genocrowd.ini',
               app_name='genocrowd',
               blueprints=None):
    """Create the Genocrowd app

    Parameters
    ----------
    config : str, optional
        Path to the config file
    app_name : str, optional
        Application name
    blueprints : None, optional
        Flask blueprints

    Returns
    -------
    Flask
        Genocrowd Flask application
    """
    conf = configparser.ConfigParser()
    conf.read(config)
    sentry_dsn = None
    try:
        sentry_dsn = conf['sentry']['server_dsn']
    except Exception:
        pass
    if sentry_dsn:
        version = get_distribution('genocrowd').version
        name = get_distribution('genocrowd').project_name
        sentry_sdk.init(dsn=sentry_dsn,
                        release="{}@{}".format(name, version),
                        integrations=[FlaskIntegration(),
                                      CeleryIntegration()])
    app = Flask(app_name, static_folder='static', template_folder='templates')
    app.iniconfig = FlaskIni()
    with app.app_context():
        app.iniconfig.read(config)
        proxy_path = None
        try:
            proxy_path = app.iniconfig.get('genocrowd', 'reverse_proxy_path')
            app.config['REVERSE_PROXY_PATH'] = proxy_path
        except Exception:
            pass
        mongo_dbname = app.iniconfig.get('flask', 'mongo_dbname')
        app.config['MONGO_DBNAME'] = mongo_dbname
        mongo_uri = app.iniconfig.get('flask', 'mongo_uri')
        app.config['MONGO_URI'] = mongo_uri
        if not mongo_uri:
            raise Exception("Missing mongo_uri in config file")
        if not mongo_dbname:
            raise Exception("Missing mongo_dbname in config file")
        app.mongo = PyMongo(app)
        app.bcrypt = Bcrypt(app)
        users = app.mongo.db.users
        app.mongo.db.genes
        app.mongo.db.answers
        groups = app.mongo.db.groups

        app.genocrowd_admin_email = app.iniconfig.get('genocrowd',
                                                      'genocrowd_admin_email')
        app.genocrowd_admin_password = app.iniconfig.get(
            'genocrowd', 'genocrowd_admin_password')

        app.apollo_admin_email = app.iniconfig.get('genocrowd',
                                                   'apollo_admin_email')
        app.apollo_admin_password = app.iniconfig.get('genocrowd',
                                                      'apollo_admin_password')
        app.apollo_dataset_path = app.iniconfig.get('genocrowd',
                                                    'apollo_dataset_path')
        app.apollo_org_id = app.iniconfig.get('genocrowd', 'apollo_org_id')
        app.apollo_url = app.iniconfig.get('genocrowd', 'apollo_url')
        # We don't want ending slash
        if app.apollo_url.endswith("/"):
            app.apollo_url = app.apollo_url[:-1]

        app.apollo_url_ext = app.iniconfig.get('genocrowd', 'apollo_url_ext')
        # We don't want ending slash
        if app.apollo_url_ext.endswith("/"):
            app.apollo_url_ext = app.apollo_url_ext[:-1]

        configure_logging(app)

        if users.find_one() is None:
            # Create default admin user
            local_auth = LocalAuth(app, None)
            local_auth.add_user_to_database('admin', app.genocrowd_admin_email,
                                            app.genocrowd_admin_password,
                                            'admin', 'admin')

        if blueprints is None:
            blueprints = BLUEPRINTS

        for blueprint in blueprints:
            app.register_blueprint(blueprint)

        if groups.find_one() is None:
            # Initiate the groups database
            data = Data(app, None)
            data.initiate_groups()

    if proxy_path:
        ReverseProxyPrefixFix(app)
    return app