"""Application configuration.""" import logging import os from os.path import abspath, dirname, join, pardir from dotenv import load_dotenv from owsclient import OwsClient from owsrequest.ows_client import correlation_id_getter, request_context_getter from python_pdp_sdk.backends import authorization_backend from python_pdp_sdk.connectors.ows_pdp import ows_pdp from secrets_manager.flask_ext import FlaskSecretsManager from sqlalchemy.pool import QueuePool, StaticPool from users import constants # Load environment variables from a .env file if present dotenv_path = abspath(join(dirname(__file__), pardir, '.env')) load_dotenv(dotenv_path) # Service information SERVICE_NAME = 'ows-users' SERVICE_VERSION = '1.0.0' os.environ['SERVICE_NAME'] = SERVICE_NAME # Logger Name LOGGER_NAME = 'users' LOGGER_LEVEL = logging.INFO # NEO4J DEBUG LOG ENABLE_NEO4J_DEBUG_LOGS = bool(os.environ.get('ENABLE_NEO4J_DEBUG_LOGS', False)) # Health check HEALTH_CHECK = '/hello/' # exclude urls USER_PROFILES_FOR_APP_URL = '/users/identity//application//profiles' USER_IDENTITY_FROM_PROFILE_URL = '/profile/profile_id//profile_type//identity' LABEL_PROFILE_ACCESS_URL = '/users/identity//label-profile-access/' AUTH0_USER_IDENTITY_FROM_PROFILE_URL = ( '/auth0/users/profile/profile_id//profile_type//identity' ) PRIMARY_VEND_CONTACT_URL = '/users/identity//primary-vend-contact' VALID_INVITATION = '/users/identity/email//valid-invitation' INTERNAL_USERS_URL = '/internal/users' INTERNAL_USER_BY_EMAIL_URL = '/internal/user/get_by_email' # List of all our existing environments: # # - test: the test environment is used by py.test to perform small adjustments # to the code. For instance: create the tables etc. # # - dev: the dev environment is used for development purposes. It points to # a different set of databases. # # - prod: production environment. Points directly to all our production # servers. QA_ENVIRONMENT = 'qa' DEV_ENVIRONMENT = 'dev' PROD_ENVIRONMENT = 'prod' TEST_ENVIRONMENT = 'test' # Default email address to use as a sender. SENDER_DEFAULT_EMAIL_ADDRESS = os.environ.get( 'SENDER_DEFAULT_EMAIL_ADDRESS', 'donotreply@theorchard.com' ) ENVIRONMENT = os.environ.get('Environment') or DEV_ENVIRONMENT ENVIRONMENTS = [QA_ENVIRONMENT, DEV_ENVIRONMENT, PROD_ENVIRONMENT, TEST_ENVIRONMENT] if ENVIRONMENT not in ENVIRONMENTS: raise Exception('The environment used is not properly named.') secrets_manager_client = FlaskSecretsManager( application_context=False, environment=ENVIRONMENT, service_name=SERVICE_NAME ) APP_URL = os.environ.get('APP_URL', 'http://localhost:5000') # Sentry configuration SENTRY = os.environ.get('SENTRY_DSN') or None # Dynamodb configuration AWS_REGION = os.environ.get('AWS_REGION') or 'us-east-1' AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID') AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY') AWS_SESSION_TOKEN = os.environ.get('AWS_SESSION_TOKEN') DYNAMODB_HOST = 'https://dynamodb.{}.amazonaws.com'.format(AWS_REGION) DYNAMODB_SOCIAL_AUTH_TABLE = os.environ.get('DYNAMODB_SOCIAL_AUTH_TABLE') # RSA information RSA_LENGTH = 512 RSA_EXPIRATION = 3600 * 1000 # makes it valid for an hour, in ms # Workstation URL URL_WORKSTATION = ''.join( [os.environ.get('URL_WORKSTATION', 'http://workstation.qaorch.com'), '{resource}'] ) # OA URL URL_OA = ''.join([os.environ.get('URL_OA', 'https://oa.qaorch.com'), '{resource}']) # Workstation Secret SECRET_WORKSTATION = os.environ.get( 'SECRET_WORKSTATION', 'dlAS*zH()1Y$7K5w3YR1/iz1Hvxz3E_l*B~x%cwodKkN85r?&yE^CO_d56 OwsClient: """Set up ows-client.""" return OwsClient( correlation_id_getter=correlation_id_getter, environment=environment, request_context_getter=request_context_getter, service_name=SERVICE_NAME, ) def setup_authorization_backend( ows_client: OwsClient, ) -> authorization_backend.AuthorizationBackend: """Set up Authorization Backend.""" ows_pdp_client = ows_pdp.OwsPdpClient(ows_client=ows_client) return authorization_backend.PdpAuthorizationBackend(ows_pdp_client) ows_client = setup_ows_client(ENVIRONMENT) pdp_authorization_backend = setup_authorization_backend(ows_client)