diff --git a/requirements.txt b/requirements.txt index fb8bc52..0586a3d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,3 +9,5 @@ click==6.7 Babel==2.6.0 Flask-Caching==1.4.0 pymongo==3.7.0 +azure-keyvault==1.1.0 +msrestazure==0.5.1 diff --git a/setup.py b/setup.py index 7ffa1ae..1f832b2 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ 'click==6.7', 'Babel==2.6.0', 'Flask-Caching==1.4.0', - 'azure-keyvault=1.1.0', + 'azure-keyvault==1.1.0', 'msrestazure==0.5.1' ], extras_require={ diff --git a/track/config.py b/track/config.py index 1c3de50..3d2eb29 100644 --- a/track/config.py +++ b/track/config.py @@ -4,8 +4,8 @@ from azure.keyvault import KeyVaultClient from msrestazure.azure_active_directory import MSIAuthentication, ServicePrincipalCredentials -class Config: +class Config: DEBUG = False TESTING = False MONGO_URI = "mongodb://localhost:27017/track" @@ -18,23 +18,22 @@ def init_app(app): A_DAY = 60 * 60 * 24 + class ProductionConfig(Config): - - if os.environ.get("TRACKER_KEYVAULT_URI", None) != None: + if os.environ.get("TRACKER_KEYVAULT_URI", None) is not None and os.environ.get("SECRET_NAME_RO", None) is not None: + KV_URI = os.environ.get("TRACKER_KEYVAULT_URI") + SECRET_NAME = os.environ.get("SECRET_NAME_RO") creds = MSIAuthentication(resource='https://vault.azure.net') keyvault = KeyVaultClient(creds) - KV_URI = os.environ.get("TRACKER_KEYVAULT_URI") - MONGO_URI = keyvault.get_secret(KV_URI, "cosmosdb-ro-conn-string", "").value + MONGO_URI = keyvault.get_secret(KV_URI, SECRET_NAME, "").value else: MONGO_URI = os.environ.get("TRACKER_MONGO_URI", None) - CACHE_TYPE = "filesystem" CACHE_DIR = os.environ.get("TRACKER_CACHE_DIR", "./.cache") CACHE_DEFAULT_TIMEOUT = int(os.environ.get("TRACKER_CACHE_TIMEOUT", A_DAY)) - @staticmethod def init_app(app): Config.init_app(app)