"""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 owsclient import OwsClient from owslogger import flask_logger from owsrequest import flask_request from owsrequest.ows_client import correlation_id_getter, request_context_getter from collaborator import config app = Flask(config.SERVICE_NAME) flask_logger.setup( app=app, dsn=config.LOGGER_DSN, environment=config.ENVIRONMENT, logger_name=config.LOGGER_NAME, logger_level=config.LOGGER_LEVEL, service_name=config.SERVICE_NAME, service_version=config.SERVICE_VERSION, exclude_paths=[config.HEALTH_CHECK], ) if config.SQLALCHEMY_LOGGER_LEVEL: logging.basicConfig() logging.getLogger("sqlalchemy.engine").setLevel(config.SQLALCHEMY_LOGGER_LEVEL) try: import uwsgi # noqa uwsgiRunning = True except ImportError: uwsgiRunning = False flask_request.setup( app, config.ENVIRONMENT, add_request_context=True, label_profile=True, verify_access=True, rules_file="collaborator/access_rules.yml", access_log_only=config.ONLY_LOG_ACCESS_ERRORS, exclude_paths=[config.HEALTH_CHECK], uwsgi_cache_enabled=uwsgiRunning, ) if config.ENVIRONMENT == config.DEV_ENVIRONMENT: from flasgger import Swagger app.config["SWAGGER"] = {"title": "ows-collaborator Documentation", "uiversion": 2} try: Swagger(app, template_file=config.SWAGGER_FILE_PATH) except FileNotFoundError: print("Could not find swagger file at {}".format(config.SWAGGER_FILE_PATH)) ows_client = OwsClient( environment=config.ENVIRONMENT, service_name=config.SERVICE_NAME, correlation_id_getter=correlation_id_getter, request_context_getter=request_context_getter, )