-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathconfig.py
41 lines (32 loc) · 1.06 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
from dotenv import load_dotenv
from pathlib import Path
from pymongo import MongoClient
BASE_DIR = Path(__file__).resolve().parent
dotenv_path = os.path.join(BASE_DIR, '.env')
load_dotenv(dotenv_path)
class Config:
CSRF_ENABLED = True
SECRET_KEY = os.getenv("SECRET_KEY")
class ProductionConfig(Config):
DB_NAME = os.getenv("DB_NAME_PROD")
MONGO_URI = os.getenv('MONGO_GCE_URI')
class TestingConfig(Config):
MONGO_URI = os.getenv('MONGO_GCE_URI')
DB_NAME = os.getenv("DB_NAME_STAGE")
class DevelopmentConfig(Config):
MONGO_URI = os.getenv("MONGO_DEV_URI")
DB_NAME = os.getenv("DB_NAME_DEV")
app_config = {
"development": DevelopmentConfig,
"testing": TestingConfig,
"production": ProductionConfig,
"staging": TestingConfig
}
environment = os.getenv("FLASK_ENV")
print("ENVIRONMENT", environment or 'staging')
configuration = app_config.get(environment, TestingConfig)
def connect_mongo(tenant):
client = MongoClient(configuration.MONGO_URI)
db = client[f'{configuration.DB_NAME}_{tenant.lower()}']
return db