forked from OperationCode/resources_api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configs.py
55 lines (39 loc) · 1.49 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
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")
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}"
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()