"""Application. The API application is a `flask` application. It provides simple features such as registering a url for a specific handlers. """ from artwork import config from artwork.connectors.database import db from flask import Flask from owslogger import flask_logger from owsrequest import flask_request app = Flask(config.SERVICE_NAME) LOG_LEVEL_INT_TO_STRING = { 10: 'DEBUG', 20: 'INFO', 30: 'WARNING', 40: 'ERROR', 50: 'CRITICAL', } flask_logger.setup( app, config.ENVIRONMENT, config.LOGGER_NAME, LOG_LEVEL_INT_TO_STRING[config.LOGGER_LEVEL], config.SERVICE_NAME, config.SERVICE_VERSION, exclude_paths=[config.HEALTH_CHECK], ) try: import uwsgi uwsgiNumproc = uwsgi.numproc uwsgiRunning = True except ImportError: uwsgiRunning = False flask_request.setup( app, config.ENVIRONMENT, uwsgi_cache_enabled=uwsgiRunning, add_request_context=True ) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['ENVIRONMENT'] = config.ENVIRONMENT app.config['SERVICE_NAME'] = config.SERVICE_NAME app.config[ 'SQLALCHEMY_DATABASE_URI' ] = 'mysql+pymysql://{user}:{password}@{host}:{port}/{db}?charset={charset}'.format( user=config.AR_MYSQL_USER, password=config.AR_MYSQL_PASSWORD, host=config.AR_MYSQL_HOST, port=config.AR_MYSQL_PORT, db=config.AR_MYSQL_DATABASE, charset='utf8', ) app.config['SQLALCHEMY_BINDS'] = { 'dd': 'mysql+pymysql://{user}:{password}@{host}:{port}/{db}?charset={charset}'.format( # noqa user=config.DD_MYSQL_USER, password=config.DD_MYSQL_PASSWORD, host=config.DD_MYSQL_HOST, port=config.DD_MYSQL_PORT, db=config.DD_MYSQL_DATABASE, charset='utf8', ) } db.init_app(app) config.secrets_manager_client.init_app(app) if config.ENVIRONMENT == config.DEV_ENVIRONMENT: from flasgger import Swagger app.config['SWAGGER'] = {'title': 'ows-artwork Documentation', 'uiversion': 2} try: Swagger(app, template_file=config.SWAGGER_FILE_PATH) except Exception: print('Could not find swagger file at {}'.format(config.SWAGGER_FILE_PATH))