def configure_extensions(app):
    """
    Attaches and configures any needed flask extensions
    to our app.

    :param app:
    """
    db.init_app(app)
    migrate.init_app(app, db, app.config.get("FLASK_MIGRATIONS_PATH", "migrations"))
    principal.init_app(app)
    smtp_mail.init_app(app)
    metrics.init_app(app)

    # the legacy Raven[flask] relied on SENTRY_CONFIG
    if app.config.get("SENTRY_DSN", None) or app.config.get("SENTRY_CONFIG", None):
        # priority given to SENTRY_DSN
        sentry_dsn = app.config.get("SENTRY_DSN", None) or app.config["SENTRY_CONFIG"]['dsn']
        sentry_sdk.init(
            dsn=sentry_dsn,
            integrations=[SqlalchemyIntegration(),
                          CeleryIntegration(),
                          RedisIntegration(),
                          FlaskIntegration()],
            # associating users to errors
            send_default_pii=True,
            shutdown_timeout=60,
            environment=app.config.get("LEMUR_ENV", ''),
        )

    if app.config["CORS"]:
        # set cors defaults, if not in config
        if "CORS_ORIGINS" not in app.config:
            app.config["CORS_ORIGINS"] = "*"
        if "CORS_ALLOW_HEADERS" not in app.config:
            app.config["CORS_ALLOW_HEADERS"] = ["Authorization", "Content-Type"]

        # cors init app
        cors.init_app(
            app,
            resources=r"/api/*",
            supports_credentials=True,
        )

    Attaches and configures any needed flask extensions
    to our app.

    :param app:
    
lemur/factory.py