"""Global application-level constants for configuration""" import multiprocessing import os APP_NAME = 'delphi-api' ENVIRONMENT = os.getenv('ENVIRONMENT', 'dev') PKG_PATH = os.path.dirname(os.path.abspath(__file__)) STATIC_PATH = os.path.join(PKG_PATH, 'static') #: Port to expose for webserver SERVICE_PORT = os.getenv('SERVICE_PORT', 8000) #: AWS configuration AWS_DEFAULT_REGION = os.getenv('AWS_DEFAULT_REGION', 'us-east-1') #: Auth0 and OAuth2 config AUTH0_DOMAIN = os.getenv('AUTH0_DOMAIN', 'dev-delphi.auth0.com') AUTH0_API_AUDIENCE = os.getenv('AUTH0_API_AUDIENCE', 'dev-delphi-api') AUTH0_ALGORITHMS = ['RS256'] #: This shouldn't be changed without updating the implementors. It's here to find usages in code DEFAULT_OAUTH2_FLOW = 'client_credentials' OAUTH2_CALLBACK_URL = '/oauth/callback' OAUTH2_TOKEN_URL = '/oauth/token' #: Used for the bucket name in the S3 URI for files – Not used ARCHIVE_BUCKET = os.getenv('ARCHIVE_BUCKET', f'{ENVIRONMENT}-sme-data-archive') #: Default size for API results pagination (-1 for unlimited) DEFAULT_PAGE_SIZE = 5000 MINUTES = 60 HOURS = 60 * MINUTES #: Default TTL for caches DEFAULT_CACHE_TTL = 2 * HOURS DEFAULT_CACHE_MAX_SIZE = 128 # max number of objects to hold # Recommended 10 hours # See: https://community.auth0.com/t/auth0-failures-getting-well-known-jwks-json/13863/2 #: Cache TTL for the Auth0 jwks.json AUTH0_KEY_SIG_CACHE_TTL = 10 * HOURS #: Cache for getting the RSA key from the key signatures RSA_KEY_CACHE_TTL = 1 * HOURS #: Cache for the secretsmanager request identifying our clients by the provided client_id TRACING_CACHE_TTL = 24 * HOURS #: AWS secret name for the secret containing the list of Auth0 clients by client ID CLIENTS_LIST_SECRET_NAME = os.getenv('CLIENTS_LIST_SECRET_NAME', f'delphi/{ENVIRONMENT}/delphi-api/clients_list') #: Cache duration to store the clients list from AWS secrets manager CLIENTS_LIST_CACHE_TTL = int(os.getenv('CLIENTS_LIST_CACHE_TTL', DEFAULT_CACHE_TTL)) #: Profiling ENABLE_PROFILING = os.getenv('PROFILE', 'false').lower() == 'true' #: Log level config DEBUG = os.getenv('DEBUG', 'false').lower() == 'true' or ENABLE_PROFILING RELOAD_WORKERS = os.getenv('RELOAD_WORKERS', 'false').lower() == 'true' LOG_LEVEL = os.getenv('LOG_LEVEL', ('DEBUG' if DEBUG else 'INFO')) #: GCP Config BIGTABLE_INSTANCE_ID = os.getenv('BIGTABLE_INSTANCE_ID', f'{ENVIRONMENT}-delphi-consumer-analytics-hdd') BIGTABLE_APP_PROFILE_ID = os.getenv('BIGTABLE_APP_PROFILE_ID', None) #: Upper limit of rows to read per query (0 for unlimited) BIGTABLE_MAX_ROWS_READ = int(os.getenv('BIGTABLE_MAX_ROWS_READ', 0)) #: Sentry DSN key https://@sentry.io/ SENTRY_DSN = os.getenv('SENTRY_DSN') SENTRY_ENABLE = os.getenv('SENTRY_ENABLE', 'true').lower() == 'true' and bool(SENTRY_DSN) SENTRY_PROJECT = os.getenv('SENTRY_PROJECT', APP_NAME) #: Postgres Config POSTGRES_URL = 'postgres://{username}:{password}@{address}:{port}/{dbname}'.format( username=os.getenv('POSTGRES_USER', 'postgres'), password=os.getenv('POSTGRES_PASSWORD', 'postgres'), address=os.getenv('POSTGRES_ADDRESS', 'localhost'), port=os.getenv('POSTGRES_PORT', '5432'), dbname=os.getenv('POSTGRES_DB', 'test_db'), ) POSTGRES_SCHEMA_NAME = os.getenv('POSTGRES_SCHEMA_NAME', 'public') #: SQLAlchemy Config SQLALCHEMY_DATABASE_URI = POSTGRES_URL SQLALCHEMY_TRACK_MODIFICATIONS = True #: Fake data enabled ENABLE_FAKE_DATA = os.getenv('ENABLE_FAKE_DATA', 'true').lower() == 'true' #: Atlas Image Service ATLAS_HOST = os.getenv('ATLAS_HOST', 'https://qa-images-api.atlas.stream') #: Threadpool config - enable/disable for aggregations USE_THREAD_POOL_FOR_AGG = os.getenv('USE_THREAD_POOL_FOR_AGG', 'true').lower() == 'true' MAX_THREADS = multiprocessing.cpu_count() * 2 + 1