import sentry_sdk from flask import Flask from sentry_sdk.integrations.flask import FlaskIntegration from werkzeug.middleware.proxy_fix import ProxyFix from auth_proxy.logs import ( configure_logging, register_logging_context_hooks, register_logging_events_hooks, ) from . import views from .settings import Settings def create_app(config=None): configure_logging() app = Flask("auth_proxy") app.wsgi_app = ProxyFix(app.wsgi_app) configure_app(app, config) sentry_conditional_init(app.config) register_blueprints(app) register_logging_context_hooks(app) register_logging_events_hooks(app) return app def configure_app(app, config=None): app.config.from_object(Settings) if config: app.config.from_object(config) def register_blueprints(app): app.register_blueprint(views.proxy) def sentry_conditional_init(config): dsn = config.get("SENTRY_DSN", None) if dsn is not None: # pragma: no cover sentry_sdk.init( dsn=dsn, environment=config.get("ENV"), integrations=[FlaskIntegration()], )