Beispiel #1
0
def __add_config_to_connexion_app(
    app: App,
    config: Mapping
) -> App:
    """Adds configuration to Flask app and replaces default Connexion and Flask
    settings."""
    # Replace Connexion app settings
    app.host = get_conf(config, 'server', 'host')
    app.port = get_conf(config, 'server', 'port')
    app.debug = get_conf(config, 'server', 'debug')

    # Replace Flask app settings
    app.app.config['DEBUG'] = app.debug
    app.app.config['ENV'] = get_conf(config, 'server', 'environment')
    app.app.config['TESTING'] = get_conf(config, 'server', 'testing')

    # Log Flask config
    logger.debug('Flask app settings:')
    for (key, value) in app.app.config.items():
        logger.debug('* {}: {}'.format(key, value))

    # Add user configuration to Flask app config
    app.app.config.update(config)

    logger.info('Connexion app configured.')
    return app
Beispiel #2
0
def run_server():
    app = App(__name__)

    print("Connexion app created")

    # Set configurations for connexion app
    app.host = '0.0.0.0'
    app.port = '8080'
    app.debug = True

    print("connexion app configured")

    # Register MongoDB
    app.app.config["MONGO_URI"] = "mongodb://localhost:27017/PG3"

    # TODO: Try to remove this datebase name later

    mongo = PyMongo(app.app)

    # db = mongo.db['PG1']

    resident = {
        "Room": "102",
        "Name": "Sarthak Gupta",
        "Hometown": "Jammu",
        "Company": "Intuit"
    }

    collection1id = mongo.db['collection1'].insert_one(resident).inserted_id
    print("Database should be created till now")

    app.add_api('swagger.yaml')
    return app
Beispiel #3
0
def __add_config_to_connexion_app(
    app: App,
    config: Config,
) -> App:
    """Replace default Connexion and Flask app settings and add FOCA- and user-
    defined configuration parameters to Flask app.

    Args:
        app: Connexion app.
        config: App configuration.

    Returns:
        Connexion app.
    """
    conf = config.server

    # replace Connexion app settings
    app.host = conf.host
    app.port = conf.port
    app.debug = conf.debug

    # replace Flask app settings
    app.app.config['DEBUG'] = conf.debug
    app.app.config['ENV'] = conf.environment
    app.app.config['TESTING'] = conf.testing

    logger.debug('Flask app settings:')
    for (key, value) in app.app.config.items():
        logger.debug('* {}: {}'.format(key, value))

    # Add user configuration to Flask app config
    app.app.config['FOCA'] = config

    logger.debug('Connexion app configured.')
    return app