"""Auth Application. The auth application is responsible for providing the different endpoints that allows a user to log in and other applications to verify the validity of a token. """ import logging import sys import connector_neo4j from flask import Flask import owsclient from owslogger import flask_logger from owslogger.logger import DDJsonFormatter from owsrequest import flask_request from owsrequest.ows_client import correlation_id_getter, request_context_getter from pythonfeatures import pythonfeatures from pythonfeatures.constants import split as split_constants from users import config app = Flask(config.SERVICE_NAME) # Setting up the logging 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, uwsgi_cache_enabled=uwsgiRunning, add_request_context=True, label_profile=True, verify_access=True, rules_file='users/access_rules.yml', exclude_paths=[ config.HEALTH_CHECK, config.USER_PROFILES_FOR_APP_URL, config.USER_IDENTITY_FROM_PROFILE_URL, config.LABEL_PROFILE_ACCESS_URL, config.AUTH0_USER_IDENTITY_FROM_PROFILE_URL, config.PRIMARY_VEND_CONTACT_URL, config.VALID_INVITATION, config.INTERNAL_USERS_URL, config.INTERNAL_USER_BY_EMAIL_URL, ], access_log_only=config.ONLY_LOG_ACCESS_ERRORS, ) is_enabled = ( pythonfeatures.get_single_feature_by_attributes('neo4j_aura', {'service': config.SERVICE_NAME}) ).message == split_constants.FEATURE_ENABLED if is_enabled: neo4j_username = config.NEO4J_AURA_USERNAME neo4j_password = config.NEO4J_AURA_PASSWORD neo4j_url = config.NEO4J_AURA_URL else: neo4j_username = config.NEO4J_USERNAME neo4j_password = config.NEO4J_PASSWORD neo4j_url = config.NEO4J_URL connector_neo4j.configure( neo4j_url, neo4j_username, neo4j_password, max_transaction_retry_time=config.NEO4J_MAX_RETRY_TIME, ) # Add DEBUG logs for Neo4j driver if config.ENABLE_NEO4J_DEBUG_LOGS: neo_handler = logging.StreamHandler(sys.stdout) neo_formatter = DDJsonFormatter(config.SERVICE_NAME, config.ENVIRONMENT, config.SERVICE_VERSION) neo_handler.setFormatter(neo_formatter) logging.getLogger('neo4j').addHandler(neo_handler) logging.getLogger('neo4j').setLevel(logging.DEBUG) # Set up owsclient ows_client = owsclient.OwsClient( service_name=config.SERVICE_NAME, environment=config.ENVIRONMENT, correlation_id_getter=correlation_id_getter, request_context_getter=request_context_getter, )