-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.py
47 lines (35 loc) · 1.3 KB
/
settings.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
42
43
44
45
46
47
import os
settings_data = {
"POSTGRES_USER": os.getenv("POSTGRES_USER", "postgres"),
"POSTGRES_DB": os.getenv("POSTGRES_DB", "postgres"),
"POSTGRES_PASSWORD": os.getenv("POSTGRES_PASSWORD", "postgres"),
"POSTGRES_HOST": os.getenv("POSTGRES_HOST", "localhost"),
"POSTGRES_PORT": os.getenv("POSTGRES_PORT", 5432),
}
PSQL_CONN = (
# Will throw:
# sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres
# See: https://stackoverflow.com/a/64698899/2290820
f"""postgresql://{settings_data['POSTGRES_USER']}:"""
f"""{settings_data['POSTGRES_PASSWORD']}@"""
f"""{settings_data['POSTGRES_HOST']}:"""
f"""{settings_data['POSTGRES_PORT']}/"""
f"""{settings_data['POSTGRES_DB']}"""
)
class StageEnv:
@classmethod
def env(cls):
return cls.__name__.lower()
class Production(StageEnv):
debug = False
mongo_uri = settings_data.get("MONGO_CONNECTION")
postgres_uri = settings_data.get("PSQL_CONNECTION")
class Test(StageEnv):
debug = True
mongo_uri = settings_data.get("MONGO_CONNECTION", "mongodb://localhost:27017")
postgres_uri = settings_data.get("PSQL_CONNECTION", PSQL_CONN)
ENV_CONFIG_DICT = {
Test.env(): Test,
Production.env(): Production,
}
ENV_CLASS = ENV_CONFIG_DICT[os.getenv("ENV", "test")]