"""Application. The API application is a `flask` application. It provides simple features such as registering a url for a specific handlers. """ from flask import Flask from flask_sqlalchemy import SQLAlchemy from owslogger import flask_logger from owsrequest import flask_request from charts import config from snowflake_connector.snowflake_conn import set_default_sessionmaker app = Flask(config.SERVICE_NAME) app.config['SQLALCHEMY_DATABASE_URI'] = config.DB_URL app.config['SQLALCHEMY_ENGINE_OPTIONS'] = config.SQLALCHEMY_ENGINE_OPTIONS app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = config.SQLALCHEMY_TRACK_MODIFICATIONS db = SQLAlchemy(app) flask_logger.setup( app, config.ENVIRONMENT, config.LOGGER_NAME, config.LOGGER_LEVEL, config.SERVICE_NAME, config.SERVICE_VERSION, exclude_paths=[config.HEALTH_CHECK], ) flask_request.setup(app, config.ENVIRONMENT, add_request_context=True) if config.ENVIRONMENT == config.DEV_ENVIRONMENT: from flasgger import Swagger app.config["SWAGGER"] = { "title": "ows-charts 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)) sf_config = { 'role': config.SNOWFLAKE_ROLE, 'account': config.SNOWFLAKE_ACCOUNT, 'user': config.SNOWFLAKE_USER, 'password': 'dummy_password', # we're using key pair auth, pk is passed in config.SNOWFLAKE_CONNECT_ARGS # noqa 'database': config.SNOWFLAKE_DATABASE, 'schema': config.SNOWFLAKE_SCHEMA, 'warehouse': config.SNOWFLAKE_WAREHOUSE, 'client_session_keep_alive': True, } # service-wide Snowflake connection pool settings set_default_sessionmaker( pool_size=config.SNOWFLAKE_POOL_SIZE, pool_recycle=config.SNOWFLAKE_POOL_RECYCLE, pool_pre_ping=config.SNOWFLAKE_POOL_PRE_PING, pool_reset_on_return=config.SNOWFLAKE_POOL_RESET_ON_RETURN, max_overflow=config.SNOWFLAKE_POOL_MAX_OVERFLOW, connect_args=config.SNOWFLAKE_CONNECT_ARGS, sf_config=sf_config ) app.config['JSON_SORT_KEYS'] = False