Example #1
0
def init_memorious():
    if settings.DEBUG:
        configure_logging(level=logging.DEBUG)
    else:
        configure_logging(level=logging.INFO)
    for func in get_extensions("memorious.plugins"):
        func()
Example #2
0
def create_app(config={}):
    configure_logging(level=logging.DEBUG)
    app = Flask("aleph")
    app.config.from_object(settings)
    app.config.update(config)

    if "postgres" not in settings.DATABASE_URI:
        raise RuntimeError("aleph database must be PostgreSQL!")

    app.config.update({
        "SQLALCHEMY_DATABASE_URI": settings.DATABASE_URI,
        "FLASK_SKIP_DOTENV": True,
        "FLASK_DEBUG": settings.DEBUG,
        "BABEL_DOMAIN": "aleph",
        "PROFILE": settings.PROFILE,
    })

    if settings.PROFILE:
        app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30])

    migrate.init_app(app, db, directory=settings.ALEMBIC_DIR)
    configure_oauth(app, cache=get_cache())
    mail.init_app(app)
    db.init_app(app)
    babel.init_app(app)
    CORS(
        app,
        resources=r"/api/*",
        origins=settings.CORS_ORIGINS,
        supports_credentials=True,
    )
    feature_policy = {
        "accelerometer": NONE,
        "camera": NONE,
        "geolocation": NONE,
        "gyroscope": NONE,
        "magnetometer": NONE,
        "microphone": NONE,
        "payment": NONE,
        "usb": NONE,
    }
    talisman.init_app(
        app,
        force_https=settings.FORCE_HTTPS,
        strict_transport_security=settings.FORCE_HTTPS,
        feature_policy=feature_policy,
        content_security_policy=settings.CONTENT_POLICY,
    )

    from aleph.views import mount_app_blueprints

    mount_app_blueprints(app)

    # This executes all registered init-time plugins so that other
    # applications can register their behaviour.
    for plugin in get_extensions("aleph.init"):
        plugin(app=app)

    return app
Example #3
0
def create_app(config={}):
    configure_logging()
    app = Flask('aleph')
    app.config.from_object(settings)
    app.config.update(config)

    if 'postgres' not in settings.DATABASE_URI:
        raise RuntimeError("aleph database must be PostgreSQL!")

    app.config.update({
        'SQLALCHEMY_DATABASE_URI': settings.DATABASE_URI,
        'FLASK_SKIP_DOTENV': True,
        'FLASK_DEBUG': settings.DEBUG,
        'BABEL_DOMAIN': 'aleph',
    })

    migrate.init_app(app, db, directory=settings.ALEMBIC_DIR)
    configure_oauth(app, cache=get_cache())
    mail.init_app(app)
    db.init_app(app)
    babel.init_app(app)
    CORS(app,
         resources=r'/api/*',
         origins=settings.CORS_ORIGINS,
         supports_credentials=True)
    feature_policy = {
        'accelerometer': NONE,
        'camera': NONE,
        'geolocation': NONE,
        'gyroscope': NONE,
        'magnetometer': NONE,
        'microphone': NONE,
        'payment': NONE,
        'usb': NONE
    }
    talisman.init_app(app,
                      force_https=settings.FORCE_HTTPS,
                      strict_transport_security=settings.FORCE_HTTPS,
                      feature_policy=feature_policy,
                      content_security_policy=settings.CONTENT_POLICY)

    from aleph.views import mount_app_blueprints
    mount_app_blueprints(app)

    # Monkey-patch followthemoney
    # from aleph.logic.names import name_frequency
    # registry.name._specificity = name_frequency

    # This executes all registered init-time plugins so that other
    # applications can register their behaviour.
    for plugin in get_extensions('aleph.init'):
        plugin(app=app)

    return app
Example #4
0
File: core.py Project: pudo/aleph
def create_app(config={}):
    app = Flask('aleph')
    app.config.from_object(settings)
    app.config.update(config)

    if 'postgres' not in settings.DATABASE_URI:
        raise RuntimeError("aleph database must be PostgreSQL!")

    app.config.update({
        'SQLALCHEMY_DATABASE_URI': settings.DATABASE_URI,
        'BABEL_DOMAIN': 'aleph'
    })

    queue = Queue(settings.QUEUE_NAME,
                  routing_key=settings.QUEUE_ROUTING_KEY,
                  queue_arguments={'x-max-priority': 9})
    celery.conf.update(
        imports=('aleph.queues'),
        broker_url=settings.BROKER_URI,
        task_always_eager=settings.EAGER,
        task_eager_propagates=True,
        task_ignore_result=True,
        task_acks_late=True,
        task_queues=(queue,),
        task_default_queue=settings.QUEUE_NAME,
        task_default_routing_key=settings.QUEUE_ROUTING_KEY,
        worker_max_tasks_per_child=1000,
        result_persistent=False,
        beat_schedule={
            'hourly': {
                'task': 'aleph.logic.scheduled.hourly',
                'schedule': crontab(hour='*', minute=0)
            },
            'daily': {
                'task': 'aleph.logic.scheduled.daily',
                'schedule': crontab(hour=5, minute=0)
            }
        },
    )

    migrate.init_app(app, db, directory=settings.ALEMBIC_DIR)
    configure_oauth(app)
    mail.init_app(app)
    db.init_app(app)
    babel.init_app(app)
    CORS(app, origins=settings.CORS_ORIGINS)

    # This executes all registered init-time plugins so that other
    # applications can register their behaviour.
    for plugin in get_extensions('aleph.init'):
        plugin(app=app)
    return app
Example #5
0
    def auction(self, file_path, entity):
        if not entity.has("mimeType"):
            if file_path.is_dir():
                entity.add("mimeType", DirectoryIngestor.MIME_TYPE)
                return DirectoryIngestor
            entity.add("mimeType", self.MAGIC.from_file(file_path.as_posix()))

        best_score, best_cls = 0, None
        for cls in get_extensions("ingestors"):
            score = cls.match(file_path, entity)
            if score > best_score:
                best_score = score
                best_cls = cls

        if best_cls is None:
            raise ProcessingException("Format not supported")
        return best_cls
Example #6
0
def create_app(config={}):
    app = Flask('aleph')
    app.config.from_object(settings)
    app.config.update(config)

    if 'postgres' not in settings.DATABASE_URI:
        raise RuntimeError("aleph database must be PostgreSQL!")

    app.config.update({
        'SQLALCHEMY_DATABASE_URI': settings.DATABASE_URI,
        'BABEL_DOMAIN': 'aleph'
    })

    migrate.init_app(app, db, directory=settings.ALEMBIC_DIR)
    configure_oauth(app)
    mail.init_app(app)
    db.init_app(app)
    babel.init_app(app)
    CORS(app, origins=settings.CORS_ORIGINS)
    feature_policy = {
        'accelerometer': NONE,
        'camera': NONE,
        'geolocation': NONE,
        'gyroscope': NONE,
        'magnetometer': NONE,
        'microphone': NONE,
        'payment': NONE,
        'usb': NONE
    }
    Talisman(app,
             force_https=settings.FORCE_HTTPS,
             strict_transport_security=settings.FORCE_HTTPS,
             feature_policy=feature_policy,
             content_security_policy=settings.CONTENT_POLICY)

    # This executes all registered init-time plugins so that other
    # applications can register their behaviour.
    for plugin in get_extensions('aleph.init'):
        plugin(app=app)
    return app
Example #7
0
def init_memorious():
    for func in get_extensions('memorious.plugins'):
        func()
 def test_extensions(self):
     exts = get_extensions("servicelayer.test")
     assert len(exts), exts
     assert get_extensions in exts, exts
Example #9
0
def create_app(config={}):
    app = Flask('aleph')
    app.config.from_object(settings)
    app.config.update(config)

    if 'postgres' not in settings.DATABASE_URI:
        raise RuntimeError("aleph database must be PostgreSQL!")

    app.config.update({
        'SQLALCHEMY_DATABASE_URI': settings.DATABASE_URI,
        'BABEL_DOMAIN': 'aleph'
    })

    queue = Queue(settings.QUEUE_NAME,
                  routing_key=settings.QUEUE_ROUTING_KEY,
                  queue_arguments={'x-max-priority': 9})
    celery.conf.update(
        imports=('aleph.queues'),
        broker_url=settings.BROKER_URI,
        task_always_eager=settings.EAGER,
        task_eager_propagates=True,
        task_ignore_result=True,
        task_acks_late=True,
        task_queues=(queue,),
        task_default_queue=settings.QUEUE_NAME,
        task_default_routing_key=settings.QUEUE_ROUTING_KEY,
        worker_max_tasks_per_child=1000,
        result_persistent=False,
        beat_schedule={
            'hourly': {
                'task': 'aleph.logic.scheduled.hourly',
                'schedule': crontab(hour='*', minute=0)
            },
            'daily': {
                'task': 'aleph.logic.scheduled.daily',
                'schedule': crontab(hour=5, minute=0)
            }
        },
    )

    migrate.init_app(app, db, directory=settings.ALEMBIC_DIR)
    configure_oauth(app)
    mail.init_app(app)
    db.init_app(app)
    babel.init_app(app)
    CORS(app, origins=settings.CORS_ORIGINS)

    # This executes all registered init-time plugins so that other
    # applications can register their behaviour.
    for plugin in get_extensions('aleph.init'):
        plugin(app=app)

    # Set up opencensus tracing and its integrations. Export collected traces
    # to Stackdriver Trace on a background thread.
    # if settings.STACKDRIVER_TRACE_PROJECT_ID:
    #     exporter = stackdriver_exporter.StackdriverExporter(
    #         project_id=settings.STACKDRIVER_TRACE_PROJECT_ID,
    #         transport=BackgroundThreadTransport
    #     )
    #     sampler = probability.ProbabilitySampler(
    #         rate=settings.TRACE_SAMPLING_RATE
    #     )
    #     blacklist_paths = ['/healthz', ]
    #     FlaskMiddleware(
    #         app, exporter=exporter, sampler=sampler,
    #         blacklist_paths=blacklist_paths
    #     )
    #     integrations = ['postgresql', 'sqlalchemy', 'httplib']
    #     config_integration.trace_integrations(integrations)
    #     # Set up logging
    #     setup_stackdriver_logging()
    return app