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(config.CONFIGURATION[run_mode])

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

    errorhandlers.init_app(app)
    db.init_app(app)
    ma.init_app(app)
    rsbc_schemas.init_app(app)
    flags.init_app(app)
    queue.init_app(app)
    babel.init_app(app)

    app.register_blueprint(API_BLUEPRINT)
    app.register_blueprint(OPS_BLUEPRINT)
    setup_jwt_manager(app, jwt)

    @app.route('/')
    def be_nice_swagger_redirect():  # pylint: disable=unused-variable
        return redirect('/api/v1', code=HTTPStatus.MOVED_PERMANENTLY)

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

    register_shellcontext(app)

    return app
Exemplo n.º 2
0
from flask import Flask
from legal_api import db
from legal_api.config import get_named_config
from legal_api.models import (
    Business,
    Filing,
)
from legal_api.services import queue
from legal_api.models.colin_event_id import ColinEventId

load_dotenv(find_dotenv())

FLASK_APP = Flask(__name__)
FLASK_APP.config.from_object(get_named_config('production'))
db.init_app(FLASK_APP)
queue.init_app(FLASK_APP)

COLIN_API = os.getenv('COLIN_API', None)
UPDATER_USERNAME = os.getenv('UPDATER_USERNAME')

ROWCOUNT = 0
TIMEOUT = 15
FAILED_CORPS = []
NEW_CORPS = []
LOADED_FILING_HISTORY = []
FAILED_FILING_HISTORY = []


def load_corps(csv_filepath: str = 'corp_nums/corps_to_load.csv'):
    """Load corps in given csv file from oracle into postgres."""
    global ROWCOUNT
Exemplo n.º 3
0
    app.config.from_object(config.CONFIGURATION[run_mode])

    # Configure Sentry
    if dsn := app.config.get('SENTRY_DSN', None):
        # pylint==2.7.4 errors out on the syntatic sugar for sentry_sdk
        # the error is skipped by disable=abstract-class-instantiated
        sentry_sdk.init(  # pylint: disable=abstract-class-instantiated
            dsn=dsn,
            integrations=[FlaskIntegration()],
            send_default_pii=False
        )

    db.init_app(app)
    rsbc_schemas.init_app(app)
    flags.init_app(app)
    queue.init_app(app)
    babel.init_app(app)
    endpoints.init_app(app)

    setup_jwt_manager(app, jwt)

    register_shellcontext(app)

    return app


def setup_jwt_manager(app, jwt_manager):
    """Use flask app to configure the JWTManager to work for a particular Realm."""
    def get_roles(a_dict):
        return a_dict['realm_access']['roles']  # pragma: no cover
    app.config['JWT_ROLE_CALLBACK'] = get_roles