Exemplo n.º 1
0
def create_app(run_mode=os.getenv('FLASK_ENV', 'production')):
    """Return a configured Flask App using the Factory method."""
    app = Flask(__name__)
    app.config.from_object(CONFIGURATION[run_mode])

    # Configure Sentry
    if app.config.get('SENTRY_DSN', None):
        sentry_sdk.init(dsn=app.config.get('SENTRY_DSN'),
                        integrations=[FlaskIntegration()])

    from auth_api.resources import API_BLUEPRINT, OPS_BLUEPRINT  # pylint: disable=import-outside-toplevel

    db.init_app(app)
    ma.init_app(app)
    mail.init_app(app)

    app.register_blueprint(API_BLUEPRINT)
    app.register_blueprint(OPS_BLUEPRINT)

    setup_jwt_manager(app, JWT)

    ExceptionHandler(app)

    @app.after_request
    def add_version(response):  # pylint: disable=unused-variable
        version = get_run_version()
        response.headers['API'] = f'auth_api/{version}'
        return response

    register_shellcontext(app)

    return app
Exemplo n.º 2
0
def create_app(run_mode=os.getenv('FLASK_ENV', 'production')):
    """Return a configured Flask App using the Factory method."""
    app = Flask(__name__)
    app.config.from_object(config.CONFIGURATION[run_mode])

    # Configure Sentry
    if str(app.config.get('SENTRY_ENABLE')).lower() == 'true':
        if app.config.get('SENTRY_DSN', None):
            sentry_sdk.init(  # pylint: disable=abstract-class-instantiated
                dsn=app.config.get('SENTRY_DSN'),
                integrations=[FlaskIntegration()])

    from auth_api.resources import TEST_BLUEPRINT  # pylint: disable=import-outside-toplevel
    from auth_api.resources import API_BLUEPRINT, OPS_BLUEPRINT  # pylint: disable=import-outside-toplevel

    db.init_app(app)
    ma.init_app(app)
    mail.init_app(app)

    app.register_blueprint(API_BLUEPRINT)
    app.register_blueprint(OPS_BLUEPRINT)

    if os.getenv('FLASK_ENV', 'production') in ['development', 'testing']:
        app.register_blueprint(TEST_BLUEPRINT)

    if os.getenv('FLASK_ENV', 'production') != 'testing':
        setup_jwt_manager(app, jwt)

    ExceptionHandler(app)

    @app.before_request
    def set_origin():
        g.origin_url = request.environ.get('HTTP_ORIGIN', 'localhost')

    @app.after_request
    def handle_after_request(response):  # pylint: disable=unused-variable
        add_version(response)
        camelize_json(response)
        return response

    def add_version(response):
        version = get_run_version()
        response.headers['API'] = f'auth_api/{version}'

    def camelize_json(response):
        if (response.headers['Content-Type'] == 'application/json'
                and 'swagger.json' not in request.base_url):
            response.set_data(
                json.dumps(camelize(json.loads(response.get_data()))))

    register_shellcontext(app)
    build_cache(app)

    return app
Exemplo n.º 3
0
def create_app(run_mode=os.getenv('FLASK_ENV', 'production')):
    """Return a configured Flask App using the Factory method."""
    app = Flask(__name__)
    app.config.from_object(config.CONFIGURATION[run_mode])

    # Configure Sentry
    if app.config.get('SENTRY_DSN', None):
        sentry_sdk.init(
            dsn=app.config.get('SENTRY_DSN'),
            integrations=[FlaskIntegration()]
        )

    from auth_api.resources import API_BLUEPRINT, OPS_BLUEPRINT, \
        TEST_BLUEPRINT  # pylint: disable=import-outside-toplevel

    db.init_app(app)
    ma.init_app(app)
    mail.init_app(app)

    app.register_blueprint(API_BLUEPRINT)
    app.register_blueprint(OPS_BLUEPRINT)

    if os.getenv('FLASK_ENV', 'production') in ['development', 'testing']:
        app.register_blueprint(TEST_BLUEPRINT)

    if os.getenv('FLASK_ENV', 'production') != 'testing':
        setup_jwt_manager(app, JWT)

    ExceptionHandler(app)

    @app.after_request
    def handle_after_request(response):  # pylint: disable=unused-variable
        add_version(response)
        camelize_json(response)
        return response

    def add_version(response):
        version = get_run_version()
        response.headers['API'] = f'auth_api/{version}'

    def camelize_json(response):
        if response.headers['Content-Type'] == 'application/json':
            response.set_data(json.dumps(camelize(json.loads(response.get_data()))))

    register_shellcontext(app)
    build_cache(app)

    return app