"""Config for initializing the namex-api."""
import os

from dotenv import find_dotenv, load_dotenv

# this will load all the envars from a .env file located in the project root (api)
load_dotenv(find_dotenv())

CONFIGURATION = {
    'development': 'config.DevConfig',
    'testing': 'config.TestConfig',
    'production': 'config.Config',
    'default': 'config.Config'
}


class Config(object):
    """Base config (also production config)."""

    PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))

    SECRET_KEY = 'a secret'

    SQLALCHEMY_TRACK_MODIFICATIONS = False

    NRO_SERVICE_ACCOUNT = os.getenv('NRO_SERVICE_ACCOUNT', 'nro_service_account')

    SOLR_BASE_URL = os.getenv('SOLR_BASE_URL', None)
    SOLR_SYNONYMS_API_URL = os.getenv('SOLR_SYNONYMS_API_URL', None)
    NRO_EXTRACTOR_URI = os.getenv('NRO_EXTRACTOR_URI', None)
    AUTO_ANALYZE_URL = os.getenv('AUTO_ANALYZE_URL', None)
    AUTO_ANALYZE_CONFIG = os.getenv('AUTO_ANALYZE_CONFIG', None)
    REPORT_SVC_URL = os.getenv('REPORT_SVC_URL', None)
    REPORT_TEMPLATE_PATH = os.getenv('REPORT_PATH', 'report-templates')

    ALEMBIC_INI = 'migrations/alembic.ini'

    # POSTGRESQL
    DB_USER = os.getenv('DATABASE_USERNAME', '')
    DB_PASSWORD = os.getenv('DATABASE_PASSWORD', '')
    DB_NAME = os.getenv('DATABASE_NAME', '')
    DB_HOST = os.getenv('DATABASE_HOST', '')
    DB_PORT = os.getenv('DATABASE_PORT', '5432')
    SQLALCHEMY_DATABASE_URI = 'postgresql://{user}:{password}@{host}:{port}/{name}'.format(
        user=DB_USER,
        password=DB_PASSWORD,
        host=DB_HOST,
        port=int(DB_PORT),
        name=DB_NAME
    )
    # ORACLE - LEGACY NRO NAMESDB
    NRO_USER = os.getenv('NRO_USER', '')
    NRO_SCHEMA = os.getenv('NRO_SCHEMA', None)
    NRO_PASSWORD = os.getenv('NRO_PASSWORD', '')
    NRO_DB_NAME = os.getenv('NRO_DB_NAME', '')
    NRO_HOST = os.getenv('NRO_HOST', '')
    NRO_PORT = int(os.getenv('NRO_PORT', '1521'))

    # JWT_OIDC Settings
    JWT_OIDC_WELL_KNOWN_CONFIG = os.getenv('JWT_OIDC_WELL_KNOWN_CONFIG')
    JWT_OIDC_ALGORITHMS = os.getenv('JWT_OIDC_ALGORITHMS')
    JWT_OIDC_JWKS_URI = os.getenv('JWT_OIDC_JWKS_URI')
    JWT_OIDC_ISSUER = os.getenv('JWT_OIDC_ISSUER')
    JWT_OIDC_AUDIENCE = os.getenv('JWT_OIDC_AUDIENCE')
    JWT_OIDC_CLIENT_SECRET = os.getenv('JWT_OIDC_CLIENT_SECRET')
    JWT_OIDC_CACHING_ENABLED = os.getenv('JWT_OIDC_CACHING_ENABLED')

    JWT_OIDC_JWKS_CACHE_TIMEOUT = int(os.getenv('JWT_OIDC_JWKS_CACHE_TIMEOUT', '300'))

    TESTING = False,
    DEBUG = False

    # You can disable NRO updates for Name Requests by setting the variable in your .env / OpenShift configuration
    DISABLE_NAMEREQUEST_NRO_UPDATES = int(os.getenv('DISABLE_NAMEREQUEST_NRO_UPDATES', 0))
    DISABLE_NAMEREQUEST_SOLR_UPDATES = int(os.getenv('DISABLE_NAMEREQUEST_SOLR_UPDATES', 0))


class DevConfig(Config):
    """Dev config used for development."""

    TESTING = False,
    DEBUG = True

    # We can't run NRO locally unless you're provisioned, you can disable NRO updates for Name Requests by setting the variable in your .env
    DISABLE_NAMEREQUEST_NRO_UPDATES = int(os.getenv('DISABLE_NAMEREQUEST_NRO_UPDATES', 0))
    DISABLE_NAMEREQUEST_SOLR_UPDATES = int(os.getenv('DISABLE_NAMEREQUEST_SOLR_UPDATES', 0))


class TestConfig(Config):
    """Test config used for pytests."""

    DEBUG = True
    TESTING = True
    # POSTGRESQL
    DB_USER = os.getenv('DATABASE_TEST_USERNAME', '')
    DB_PASSWORD = os.getenv('DATABASE_TEST_PASSWORD', '')
    DB_NAME = os.getenv('DATABASE_TEST_NAME', '')
    DB_HOST = os.getenv('DATABASE_TEST_HOST', '')
    DB_PORT = os.getenv('DATABASE_TEST_PORT', '5432')
    # Allows for NRO add / update bypass if necessary (for local development)
    LOCAL_DEV_MODE = os.getenv('LOCAL_DEV_MODE', False)
    # Set this in your .env to debug SQL Alchemy queries (for local development)
    SQLALCHEMY_ECHO = 'debug' if os.getenv('DEBUG_SQL_QUERIES', False) else False
    SQLALCHEMY_DATABASE_URI = 'postgresql://{user}:{password}@{host}:{port}/{name}'.format(
        user=DB_USER,
        password=DB_PASSWORD,
        host=DB_HOST,
        port=int(DB_PORT),
        name=DB_NAME
    )

    # We can't run NRO locally for running our tests
    DISABLE_NAMEREQUEST_NRO_UPDATES = int(os.getenv('DISABLE_NAMEREQUEST_NRO_UPDATES', 1))
    DISABLE_NAMEREQUEST_SOLR_UPDATES = int(os.getenv('DISABLE_NAMEREQUEST_SOLR_UPDATES', 0))

    # JWT OIDC settings
    # JWT_OIDC_TEST_MODE will set jwt_manager to use
    JWT_OIDC_TEST_MODE = True
    JWT_OIDC_TEST_AUDIENCE = 'example'
    JWT_OIDC_TEST_ISSUER = 'https://example.localdomain/auth/realms/example'
    JWT_OIDC_TEST_KEYS = {
        'keys': [
            {
                'kid': 'flask-jwt-oidc-test-client',
                'kty': 'RSA',
                'alg': 'RS256',
                'use': 'sig',
                'n': 'AN-fWcpCyE5KPzHDjigLaSUVZI0uYrcGcc40InVtl-rQRDmAh-C2W8H4_Hxhr5VLc6crsJ2LiJTV_E72S03pzpOOaaYV6-TzAjCou2GYJIXev7f6Hh512PuG5wyxda_TlBSsI-gvphRTPsKCnPutrbiukCYrnPuWxX5_cES9eStR',  # noqa: E501
                'e': 'AQAB'
            }
        ]
    }

    JWT_OIDC_TEST_PRIVATE_KEY_JWKS = {
        'keys': [
            {
                'kid': 'flask-jwt-oidc-test-client',
                'kty': 'RSA',
                'alg': 'RS256',
                'use': 'sig',
                'n': 'AN-fWcpCyE5KPzHDjigLaSUVZI0uYrcGcc40InVtl-rQRDmAh-C2W8H4_Hxhr5VLc6crsJ2LiJTV_E72S03pzpOOaaYV6-TzAjCou2GYJIXev7f6Hh512PuG5wyxda_TlBSsI-gvphRTPsKCnPutrbiukCYrnPuWxX5_cES9eStR',  # noqa: E501
                'e': 'AQAB',
                'd': 'C0G3QGI6OQ6tvbCNYGCqq043YI_8MiBl7C5dqbGZmx1ewdJBhMNJPStuckhskURaDwk4-8VBW9SlvcfSJJrnZhgFMjOYSSsBtPGBIMIdM5eSKbenCCjO8Tg0BUh_xa3CHST1W4RQ5rFXadZ9AeNtaGcWj2acmXNO3DVETXAX3x0',  # noqa: E501
                'p': 'APXcusFMQNHjh6KVD_hOUIw87lvK13WkDEeeuqAydai9Ig9JKEAAfV94W6Aftka7tGgE7ulg1vo3eJoLWJ1zvKM',
                'q': 'AOjX3OnPJnk0ZFUQBwhduCweRi37I6DAdLTnhDvcPTrrNWuKPg9uGwHjzFCJgKd8KBaDQ0X1rZTZLTqi3peT43s',
                'dp': 'AN9kBoA5o6_Rl9zeqdsIdWFmv4DB5lEqlEnC7HlAP-3oo3jWFO9KQqArQL1V8w2D4aCd0uJULiC9pCP7aTHvBhc',
                'dq': 'ANtbSY6njfpPploQsF9sU26U0s7MsuLljM1E8uml8bVJE1mNsiu9MgpUvg39jEu9BtM2tDD7Y51AAIEmIQex1nM',
                'qi': 'XLE5O360x-MhsdFXx8Vwz4304-MJg-oGSJXCK_ZWYOB_FGXFRTfebxCsSYi0YwJo-oNu96bvZCuMplzRI1liZw'
            }
        ]
    }

    JWT_OIDC_TEST_PRIVATE_KEY_PEM = """
    -----BEGIN RSA PRIVATE KEY-----
    MIICXQIBAAKBgQDfn1nKQshOSj8xw44oC2klFWSNLmK3BnHONCJ1bZfq0EQ5gIfg
    tlvB+Px8Ya+VS3OnK7Cdi4iU1fxO9ktN6c6TjmmmFevk8wIwqLthmCSF3r+3+h4e
    ddj7hucMsXWv05QUrCPoL6YUUz7Cgpz7ra24rpAmK5z7lsV+f3BEvXkrUQIDAQAB
    AoGAC0G3QGI6OQ6tvbCNYGCqq043YI/8MiBl7C5dqbGZmx1ewdJBhMNJPStuckhs
    kURaDwk4+8VBW9SlvcfSJJrnZhgFMjOYSSsBtPGBIMIdM5eSKbenCCjO8Tg0BUh/
    xa3CHST1W4RQ5rFXadZ9AeNtaGcWj2acmXNO3DVETXAX3x0CQQD13LrBTEDR44ei
    lQ/4TlCMPO5bytd1pAxHnrqgMnWovSIPSShAAH1feFugH7ZGu7RoBO7pYNb6N3ia
    C1idc7yjAkEA6Nfc6c8meTRkVRAHCF24LB5GLfsjoMB0tOeEO9w9Ous1a4o+D24b
    AePMUImAp3woFoNDRfWtlNktOqLel5PjewJBAN9kBoA5o6/Rl9zeqdsIdWFmv4DB
    5lEqlEnC7HlAP+3oo3jWFO9KQqArQL1V8w2D4aCd0uJULiC9pCP7aTHvBhcCQQDb
    W0mOp436T6ZaELBfbFNulNLOzLLi5YzNRPLppfG1SRNZjbIrvTIKVL4N/YxLvQbT
    NrQw+2OdQACBJiEHsdZzAkBcsTk7frTH4yGx0VfHxXDPjfTj4wmD6gZIlcIr9lZg
    4H8UZcVFN95vEKxJiLRjAmj6g273pu9kK4ymXNEjWWJn
    -----END RSA PRIVATE KEY-----"""

[((196, 209), 'dotenv.find_dotenv', 'find_dotenv', ([], {}), '()\n', (207, 209), False, 'from dotenv import find_dotenv, load_dotenv\n'), ((608, 663), 'os.getenv', 'os.getenv', (['"""NRO_SERVICE_ACCOUNT"""', '"""nro_service_account"""'], {}), "('NRO_SERVICE_ACCOUNT', 'nro_service_account')\n", (617, 663), False, 'import os\n'), ((685, 717), 'os.getenv', 'os.getenv', (['"""SOLR_BASE_URL"""', 'None'], {}), "('SOLR_BASE_URL', None)\n", (694, 717), False, 'import os\n'), ((746, 786), 'os.getenv', 'os.getenv', (['"""SOLR_SYNONYMS_API_URL"""', 'None'], {}), "('SOLR_SYNONYMS_API_URL', None)\n", (755, 786), False, 'import os\n'), ((811, 847), 'os.getenv', 'os.getenv', (['"""NRO_EXTRACTOR_URI"""', 'None'], {}), "('NRO_EXTRACTOR_URI', None)\n", (820, 847), False, 'import os\n'), ((871, 906), 'os.getenv', 'os.getenv', (['"""AUTO_ANALYZE_URL"""', 'None'], {}), "('AUTO_ANALYZE_URL', None)\n", (880, 906), False, 'import os\n'), ((933, 971), 'os.getenv', 'os.getenv', (['"""AUTO_ANALYZE_CONFIG"""', 'None'], {}), "('AUTO_ANALYZE_CONFIG', None)\n", (942, 971), False, 'import os\n'), ((993, 1026), 'os.getenv', 'os.getenv', (['"""REPORT_SVC_URL"""', 'None'], {}), "('REPORT_SVC_URL', None)\n", (1002, 1026), False, 'import os\n'), ((1054, 1098), 'os.getenv', 'os.getenv', (['"""REPORT_PATH"""', '"""report-templates"""'], {}), "('REPORT_PATH', 'report-templates')\n", (1063, 1098), False, 'import os\n'), ((1175, 1209), 'os.getenv', 'os.getenv', (['"""DATABASE_USERNAME"""', '""""""'], {}), "('DATABASE_USERNAME', '')\n", (1184, 1209), False, 'import os\n'), ((1228, 1262), 'os.getenv', 'os.getenv', (['"""DATABASE_PASSWORD"""', '""""""'], {}), "('DATABASE_PASSWORD', '')\n", (1237, 1262), False, 'import os\n'), ((1277, 1307), 'os.getenv', 'os.getenv', (['"""DATABASE_NAME"""', '""""""'], {}), "('DATABASE_NAME', '')\n", (1286, 1307), False, 'import os\n'), ((1322, 1352), 'os.getenv', 'os.getenv', (['"""DATABASE_HOST"""', '""""""'], {}), "('DATABASE_HOST', '')\n", (1331, 1352), False, 'import os\n'), ((1367, 1401), 'os.getenv', 'os.getenv', (['"""DATABASE_PORT"""', '"""5432"""'], {}), "('DATABASE_PORT', '5432')\n", (1376, 1401), False, 'import os\n'), ((1671, 1696), 'os.getenv', 'os.getenv', (['"""NRO_USER"""', '""""""'], {}), "('NRO_USER', '')\n", (1680, 1696), False, 'import os\n'), ((1714, 1743), 'os.getenv', 'os.getenv', (['"""NRO_SCHEMA"""', 'None'], {}), "('NRO_SCHEMA', None)\n", (1723, 1743), False, 'import os\n'), ((1763, 1792), 'os.getenv', 'os.getenv', (['"""NRO_PASSWORD"""', '""""""'], {}), "('NRO_PASSWORD', '')\n", (1772, 1792), False, 'import os\n'), ((1811, 1839), 'os.getenv', 'os.getenv', (['"""NRO_DB_NAME"""', '""""""'], {}), "('NRO_DB_NAME', '')\n", (1820, 1839), False, 'import os\n'), ((1855, 1880), 'os.getenv', 'os.getenv', (['"""NRO_HOST"""', '""""""'], {}), "('NRO_HOST', '')\n", (1864, 1880), False, 'import os\n'), ((1989, 2028), 'os.getenv', 'os.getenv', (['"""JWT_OIDC_WELL_KNOWN_CONFIG"""'], {}), "('JWT_OIDC_WELL_KNOWN_CONFIG')\n", (1998, 2028), False, 'import os\n'), ((2055, 2087), 'os.getenv', 'os.getenv', (['"""JWT_OIDC_ALGORITHMS"""'], {}), "('JWT_OIDC_ALGORITHMS')\n", (2064, 2087), False, 'import os\n'), ((2112, 2142), 'os.getenv', 'os.getenv', (['"""JWT_OIDC_JWKS_URI"""'], {}), "('JWT_OIDC_JWKS_URI')\n", (2121, 2142), False, 'import os\n'), ((2165, 2193), 'os.getenv', 'os.getenv', (['"""JWT_OIDC_ISSUER"""'], {}), "('JWT_OIDC_ISSUER')\n", (2174, 2193), False, 'import os\n'), ((2218, 2248), 'os.getenv', 'os.getenv', (['"""JWT_OIDC_AUDIENCE"""'], {}), "('JWT_OIDC_AUDIENCE')\n", (2227, 2248), False, 'import os\n'), ((2278, 2313), 'os.getenv', 'os.getenv', (['"""JWT_OIDC_CLIENT_SECRET"""'], {}), "('JWT_OIDC_CLIENT_SECRET')\n", (2287, 2313), False, 'import os\n'), ((2345, 2382), 'os.getenv', 'os.getenv', (['"""JWT_OIDC_CACHING_ENABLED"""'], {}), "('JWT_OIDC_CACHING_ENABLED')\n", (2354, 2382), False, 'import os\n'), ((3382, 3421), 'os.getenv', 'os.getenv', (['"""DATABASE_TEST_USERNAME"""', '""""""'], {}), "('DATABASE_TEST_USERNAME', '')\n", (3391, 3421), False, 'import os\n'), ((3440, 3479), 'os.getenv', 'os.getenv', (['"""DATABASE_TEST_PASSWORD"""', '""""""'], {}), "('DATABASE_TEST_PASSWORD', '')\n", (3449, 3479), False, 'import os\n'), ((3494, 3529), 'os.getenv', 'os.getenv', (['"""DATABASE_TEST_NAME"""', '""""""'], {}), "('DATABASE_TEST_NAME', '')\n", (3503, 3529), False, 'import os\n'), ((3544, 3579), 'os.getenv', 'os.getenv', (['"""DATABASE_TEST_HOST"""', '""""""'], {}), "('DATABASE_TEST_HOST', '')\n", (3553, 3579), False, 'import os\n'), ((3594, 3633), 'os.getenv', 'os.getenv', (['"""DATABASE_TEST_PORT"""', '"""5432"""'], {}), "('DATABASE_TEST_PORT', '5432')\n", (3603, 3633), False, 'import os\n'), ((3733, 3767), 'os.getenv', 'os.getenv', (['"""LOCAL_DEV_MODE"""', '(False)'], {}), "('LOCAL_DEV_MODE', False)\n", (3742, 3767), False, 'import os\n'), ((481, 506), 'os.path.dirname', 'os.path.dirname', (['__file__'], {}), '(__file__)\n', (496, 506), False, 'import os\n'), ((1900, 1929), 'os.getenv', 'os.getenv', (['"""NRO_PORT"""', '"""1521"""'], {}), "('NRO_PORT', '1521')\n", (1909, 1929), False, 'import os\n'), ((2422, 2469), 'os.getenv', 'os.getenv', (['"""JWT_OIDC_JWKS_CACHE_TIMEOUT"""', '"""300"""'], {}), "('JWT_OIDC_JWKS_CACHE_TIMEOUT', '300')\n", (2431, 2469), False, 'import os\n'), ((2669, 2716), 'os.getenv', 'os.getenv', (['"""DISABLE_NAMEREQUEST_NRO_UPDATES"""', '(0)'], {}), "('DISABLE_NAMEREQUEST_NRO_UPDATES', 0)\n", (2678, 2716), False, 'import os\n'), ((2761, 2809), 'os.getenv', 'os.getenv', (['"""DISABLE_NAMEREQUEST_SOLR_UPDATES"""', '(0)'], {}), "('DISABLE_NAMEREQUEST_SOLR_UPDATES', 0)\n", (2770, 2809), False, 'import os\n'), ((3104, 3151), 'os.getenv', 'os.getenv', (['"""DISABLE_NAMEREQUEST_NRO_UPDATES"""', '(0)'], {}), "('DISABLE_NAMEREQUEST_NRO_UPDATES', 0)\n", (3113, 3151), False, 'import os\n'), ((3196, 3244), 'os.getenv', 'os.getenv', (['"""DISABLE_NAMEREQUEST_SOLR_UPDATES"""', '(0)'], {}), "('DISABLE_NAMEREQUEST_SOLR_UPDATES', 0)\n", (3205, 3244), False, 'import os\n'), ((3882, 3919), 'os.getenv', 'os.getenv', (['"""DEBUG_SQL_QUERIES"""', '(False)'], {}), "('DEBUG_SQL_QUERIES', False)\n", (3891, 3919), False, 'import os\n'), ((4247, 4294), 'os.getenv', 'os.getenv', (['"""DISABLE_NAMEREQUEST_NRO_UPDATES"""', '(1)'], {}), "('DISABLE_NAMEREQUEST_NRO_UPDATES', 1)\n", (4256, 4294), False, 'import os\n'), ((4339, 4387), 'os.getenv', 'os.getenv', (['"""DISABLE_NAMEREQUEST_SOLR_UPDATES"""', '(0)'], {}), "('DISABLE_NAMEREQUEST_SOLR_UPDATES', 0)\n", (4348, 4387), False, 'import os\n')]