"""Application. The API application is a `flask` application. It provides simple features such as registering a url for a specific handlers. """ import logging from flask import Flask from owslogger import flask_logger from owsrequest import flask_request from podcast import config from podcast.connectors import sentry app = Flask(config.SERVICE_NAME) if config.SENTRY: sentry.init_sentry(config.SENTRY) flask_logger.setup( app, config.ENVIRONMENT, config.LOGGER_NAME, config.LOGGER_LEVEL, config.SERVICE_NAME, config.SERVICE_VERSION, exclude_paths=[config.HEALTH_CHECK]) try: import uwsgi # noqa uwsgiRunning = True except ImportError: uwsgiRunning = False flask_request.setup( app, config.ENVIRONMENT, add_request_context=True, uwsgi_cache_enabled=uwsgiRunning, label_profile=True, verify_access=True, rules_file='podcast/access_rules.yml', access_log_only=config.ONLY_LOG_ACCESS_ERRORS, exclude_paths=[config.HEALTH_CHECK]) if config.ENVIRONMENT == config.DEV_ENVIRONMENT: try: from flasgger import Swagger app.config['SWAGGER'] = { 'title': 'ows-podcast Documentation', 'uiversion': 2 } Swagger(app, template_file=config.SWAGGER_FILE_PATH) except ModuleNotFoundError: logging.warning('Cannot import flasgger. Go on without swagger.') except Exception: print('Could not find swagger file at {}'.format( config.SWAGGER_FILE_PATH)) app.config['EXECUTOR_TYPE'] = 'thread' app.config['EXECUTOR_MAX_WORKERS'] = 10