-
-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathconfigs.py
70 lines (48 loc) · 1.93 KB
/
configs.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
import sys
from dataclasses import dataclass
@dataclass
class PaginatorConfig:
per_page: int = 20
max_page_size: int = 200
def get_sys_exec_root_or_drive():
path = sys.executable
while os.path.split(path)[1]:
path = os.path.split(path)[0]
return path
pg_user = os.environ.get('POSTGRES_USER')
if not pg_user:
raise KeyError("Application requires 'POSTGRES_USER' to run")
pg_pw = os.environ.get('POSTGRES_PASSWORD')
if not pg_pw:
raise KeyError("Application requires 'POSTGRES_PASSWORD' to run")
pg_db = os.environ.get('POSTGRES_DB')
if not pg_db:
raise KeyError("Application requires 'POSTGRES_DB' to run")
pg_host = os.environ.get('POSTGRES_HOST')
if not pg_host:
raise KeyError("Application requires 'POSTGRES_HOST' to run")
algolia_app_id = os.environ.get('ALGOLIA_APP_ID')
algolia_api_key = os.environ.get('ALGOLIA_API_KEY')
if not all([algolia_app_id, algolia_api_key]):
print("Application requires 'ALGOLIA_APP_ID' and 'ALGOLIA_API_KEY' for search")
secret_key = os.environ.get('SECRET_KEY', None)
security_password_hash = 'pbkdf2_sha512'
# Replace this with your own salt.
security_password_salt = os.environ.get('SECURITY_PASSWORD_SALT', None)
if not all([secret_key, security_password_salt]):
print("Application requires 'SECRET_KEY' and 'SECURITY HASH'")
index_name = os.environ.get("INDEX_NAME")
class Config:
SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_DATABASE_URI = f"postgresql://{pg_user}:{pg_pw}@{pg_host}:5432/{pg_db}"
SECRET_KEY = secret_key
SECURITY_PASSWORD_HASH = security_password_hash
SECURITY_PASSWORD_SALT = security_password_salt
ALGOLIA_APP_ID = algolia_app_id
ALGOLIA_API_KEY = algolia_api_key
INDEX_NAME = index_name
# Can pass in changes to defaults, such as PaginatorConfig(per_page=40)
RESOURCE_PAGINATOR = PaginatorConfig()
LANGUAGE_PAGINATOR = PaginatorConfig()
CATEGORY_PAGINATOR = PaginatorConfig()