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
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}) queues = ( Queue(WORKER_QUEUE, routing_key=WORKER_ROUTING_KEY), Queue(USER_QUEUE, routing_key=USER_ROUTING_KEY), ) celery.conf.update( imports=('aleph.queues'), broker_url=settings.BROKER_URI, # broker_connection_retry=False, broker_connection_max_retries=3, broker_pool_limit=None, task_always_eager=settings.EAGER, task_eager_propagates=True, task_ignore_result=True, task_acks_late=True, task_queues=queues, task_default_queue=WORKER_QUEUE, task_default_routing_key=WORKER_ROUTING_KEY, worker_max_tasks_per_child=500, worker_disable_rate_limits=True, result_persistent=False, beat_schedule={ 'alert-every-night': { 'task': 'aleph.logic.alerts.check_alerts', 'schedule': crontab(hour=1, minute=30) } }, ) migrate.init_app(app, db, directory=settings.ALEMBIC_DIR) configure_oauth(app) mail.init_app(app) db.init_app(app) CORS(app, origins=settings.CORS_ORIGINS) # Enable raven to submit issues to sentry if a DSN is defined. This will # report errors from Flask and Celery operation modes to Sentry. if settings.SENTRY_DSN: sentry.init_app(app, dsn=settings.SENTRY_DSN, logging=True, level=logging.ERROR) register_logger_signal(sentry.client) register_signal(sentry.client, ignore_expected=True) # 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
def create_app(config={}): app = Flask('aleph') app.config.from_object(default_settings) app.config.from_envvar('ALEPH_SETTINGS', silent=True) app.config.update(config) app_name = app.config.get('APP_NAME') if not app.debug and app.config.get('MAIL_ADMINS'): credentials = (app.config.get('MAIL_USERNAME'), app.config.get('MAIL_PASSWORD')) mail_handler = SMTPHandler(app.config.get('MAIL_SERVER'), app.config.get('MAIL_FROM'), app.config.get('MAIL_ADMINS'), '[%s] Crash report' % app_name, credentials=credentials, secure=()) mail_handler.setLevel(logging.ERROR) app.logger.addHandler(mail_handler) if 'postgres' not in app.config.get('SQLALCHEMY_DATABASE_URI', ''): raise RuntimeError("aleph database must be PostgreSQL!") queues = ( Queue(WORKER_QUEUE, routing_key=WORKER_ROUTING_KEY), Queue(USER_QUEUE, routing_key=USER_ROUTING_KEY), ) # celery.conf.update(app.config) celery.conf.update( imports=('aleph.queues'), broker_url=app.config['CELERY_BROKER_URL'], task_always_eager=app.config['CELERY_ALWAYS_EAGER'], task_eager_propagates=True, task_ignore_result=True, result_persistent=False, task_queues=queues, task_default_queue=WORKER_QUEUE, task_default_routing_key=WORKER_ROUTING_KEY, # ultra-high time limit to shoot hung tasks: task_time_limit=3600 * 3, worker_max_tasks_per_child=200, worker_disable_rate_limits=True, beat_schedule=app.config['CELERYBEAT_SCHEDULE'], ) migrate.init_app(app, db, directory=app.config.get('ALEMBIC_DIR')) configure_oauth(app) mail.init_app(app) db.init_app(app) # This executes all registered init-time plugins so that other # applications can register their behaviour. for plugin in get_init(): plugin(app=app) return app
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
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
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
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=False, 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) # Enable raven to submit issues to sentry if a DSN is defined. This will # report errors from Flask and Celery operation modes to Sentry. if settings.SENTRY_DSN: sentry.init_app(app, dsn=settings.SENTRY_DSN, logging=True, level=logging.ERROR) register_logger_signal(sentry.client) register_signal(sentry.client, ignore_expected=True) # 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
def create_app(config={}): app = Flask('aleph') app.config.from_object(default_settings) app.config.from_envvar('ALEPH_SETTINGS', silent=True) app.config.update(config) app_name = app.config.get('APP_NAME') if app.config.get("TESTING"): # The testing configuration is inferred from the production # settings, but it can only be derived after the config files # have actually been evaluated. database_uri = app.config.get('SQLALCHEMY_DATABASE_URI') app.config['SQLALCHEMY_DATABASE_URI'] = database_uri + '_test' es_index = app.config.get('ELASTICSEARCH_INDEX', app.config.get('APP_NAME')) app.config['ELASTICSEARCH_INDEX'] = es_index + '_test' if not app.debug and app.config.get('MAIL_ADMINS'): credentials = (app.config.get('MAIL_USERNAME'), app.config.get('MAIL_PASSWORD')) mail_handler = SMTPHandler(app.config.get('MAIL_SERVER'), app.config.get('MAIL_FROM'), app.config.get('MAIL_ADMINS'), '[%s] Crash report' % app_name, credentials=credentials, secure=()) mail_handler.setLevel(logging.ERROR) app.logger.addHandler(mail_handler) if 'postgres' not in app.config.get('SQLALCHEMY_DATABASE_URI', ''): raise RuntimeError("aleph database must be PostgreSQL!") queues = ( Queue(WORKER_QUEUE, routing_key=WORKER_ROUTING_KEY), Queue(USER_QUEUE, routing_key=USER_ROUTING_KEY), ) celery.conf.update( imports=('aleph.queues'), broker_url=app.config['CELERY_BROKER_URL'], task_always_eager=app.config['CELERY_ALWAYS_EAGER'], task_eager_propagates=True, task_ignore_result=True, result_persistent=False, task_queues=queues, task_default_queue=WORKER_QUEUE, task_default_routing_key=WORKER_ROUTING_KEY, # ultra-high time limit to shoot hung tasks: task_time_limit=3600 * 3, worker_max_tasks_per_child=500, worker_disable_rate_limits=True, # worker_hijack_root_logger=False, beat_schedule=app.config['CELERYBEAT_SCHEDULE'], ) celery.conf.update(app.config.get('CELERY', {})) migrate.init_app(app, db, directory=app.config.get('ALEMBIC_DIR')) configure_oauth(app) mail.init_app(app) db.init_app(app) try: ldap.init_app(app) except LDAPException as error: log.info(error) # This executes all registered init-time plugins so that other # applications can register their behaviour. for plugin in get_init(): plugin(app=app) return app
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=500, 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) cache.init_app(app, config={'CACHE_TYPE': 'simple'}) CORS(app, origins=settings.CORS_ORIGINS) # Enable raven to submit issues to sentry if a DSN is defined. This will # report errors from Flask and Celery operation modes to Sentry. if settings.SENTRY_DSN: sentry.init_app(app, dsn=settings.SENTRY_DSN, logging=True, level=logging.ERROR) register_logger_signal(sentry.client) register_signal(sentry.client, ignore_expected=True) # 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