Esempio n. 1
0
def create_app(config: Box = None):
    app = Flask(__name__)
    app.config = Box(app.config)
    app.config.update(config)
    with app.app_context():

        app.web3 = Web3(Web3.HTTPProvider(config.HTTP_BLOCKCHAIN_ENDPOINT))

        if config.BLOCKCHAIN_GAS_PRICE_STRATEGY == 'fast':
            app.web3.eth.setGasPriceStrategy(
                gas_price_strategies.fast_gas_price_strategy)
        elif config.BLOCKCHAIN_GAS_PRICE_STRATEGY == 'medium':
            app.web3.eth.setGasPriceStrategy(
                gas_price_strategies.medium_gas_price_strategy)
        else:
            raise ValueError(
                'BLOCKCHAIN_GAS_PRICE must be in ["fast", "medium"], got: "{}"'
                .format(config.BLOCKCHAIN_GAS_PRICE_STRATEGY))

        app.repos = Box(subscriptions=repos.Subscriptions(
            config=config.SUBSCRIPTIONS_REPO),
                        contract=repos.Contract(config=config.CONTRACT_REPO))
        app.contract = Contract(
            web3=app.web3,
            repo=app.repos.contract,
            network_id=config.CONTRACT_NETWORK_ID,
            artifact_key=config.CONTRACT_BUILD_ARTIFACT_KEY)

        app.register_blueprint(api.blueprint)
        error_handlers.register(app)

        app.config.TOPIC_BASE_URL = urllib.parse.urljoin(
            config.CHANNEL_URL, api.TOPIC_BASE_URL)

    return app
Esempio n. 2
0
def create_app(config_object=None):
    if config_object is None:
        config_object = BaseConfig

    app = Flask(__name__)
    app.config.from_object(config_object)
    app.logger = loggers.create_logger(app.config)

    SENTRY_DSN = app.config.get("SENTRY_DSN")
    if SENTRY_DSN:
        import sentry_sdk
        from sentry_sdk.integrations.flask import FlaskIntegration
        sentry_sdk.init(SENTRY_DSN, integrations=[FlaskIntegration()])

    db.init_app(app)

    with app.app_context():
        from api import views

        app.register_blueprint(views.blueprint)

        ma.init_app(app)
        migrate.init_app(app, db)

        handlers.register(app)
        register_specs(app)

        with app.test_request_context():
            app.config['HUB_URL'] = urljoin(
                app.config['SERVICE_URL'],
                url_for('views.subscriptions_by_id', _external=False))

    return app
Esempio n. 3
0
def create_app(config_object=None):
    """
    FLASK_ENV=development FLASK_APP=apis.subscriptions.app flask run
    """
    if config_object is None:
        config_object = Config
    app = Flask(__name__)
    app.config.from_object(config_object)
    SENTRY_DSN = app.config.get("SENTRY_DSN")
    if SENTRY_DSN:
        import sentry_sdk
        from sentry_sdk.integrations.flask import FlaskIntegration
        from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration
        sentry_sdk.init(SENTRY_DSN, integrations=[FlaskIntegration(), AwsLambdaIntegration()])
    app.register_blueprint(index.blueprint)
    app.register_blueprint(subscriptions.blueprint)
    handlers.register(app)
    return app
Esempio n. 4
0
def create_app(config_object=None):
    if config_object is None:
        config_object = Config

    app = Flask(__name__)
    app.config.from_object(config_object)
    app.logger = loggers.create_logger(app.config)

    with app.app_context():
        from api import views

        app.register_blueprint(views.blueprint)

        handlers.register(app)

        with app.test_request_context():
            app.config['HUB_URL'] = urljoin(
                app.config['SERVICE_URL'],
                url_for('views.subscriptions_by_jurisdiction', _external=False)
            )

    return app
Esempio n. 5
0
def create_app(config: Box = None):
    app = Flask(__name__)
    app.config = Box(app.config)
    app.config.update(config)
    with app.app_context():

        app.web3 = Web3(Web3.HTTPProvider(config.HTTP_BLOCKCHAIN_ENDPOINT))
        app.repos = Box(subscriptions=repos.Subscriptions(
            config=config.SUBSCRIPTIONS_REPO),
                        contract=repos.Contract(config=config.CONTRACT_REPO))
        app.contract = Contract(
            web3=app.web3,
            repo=app.repos.contract,
            network_id=config.CONTRACT_NETWORK_ID,
            artifact_key=config.CONTRACT_BUILD_ARTIFACT_KEY)

        app.register_blueprint(api.blueprint)
        error_handlers.register(app)

        app.config.TOPIC_BASE_URL = urllib.parse.urljoin(
            config.CHANNEL_URL, api.TOPIC_BASE_URL)

    return app
Esempio n. 6
0
def app():
    app = Flask('common_api_errors_test_app')
    app.config.from_object(TestConfig)
    handlers.register(app)
    yield app
Esempio n. 7
0
from flask import Flask, Response
from libtrustbridge.errors import handlers
from libtrustbridge.utils.loggers import logging


logger = logging.getLogger('dummy-test-helper')

app = Flask(__name__)
handlers.register(app)


@app.route('/response/<int:status_code>/<message>', methods=['GET', 'POST'])
def request_response(status_code, message):
    logger.info(f'Requested response with status: {status_code} and message:{message}')
    return Response(
        message,
        status=status_code
    )