-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.py
More file actions
78 lines (63 loc) · 2.16 KB
/
config.py
File metadata and controls
78 lines (63 loc) · 2.16 KB
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
71
72
73
74
75
76
77
78
import os
from sqlalchemy_utils import database_exists, create_database
basedir = os.path.abspath(os.path.dirname(__file__))
def parse_var_env(var_name):
v = os.environ.get(var_name)
if v == "True":
v = True
elif v == "False":
v = False
return v
class Config(object):
SECRET_KEY = parse_var_env('SECRET_KEY')
ENV ='production'
DEBUG = parse_var_env('DEBUG')
SQLALCHEMY_DATABASE_URI = 'sqlite:////' + os.path.join(basedir, parse_var_env('DATABASE_URI'))
SQLALCHEMY_ECHO = False
SQLALCHEMY_RECORD_QUERIES = False
SQLALCHEMY_TRACK_MODIFICATIONS = False
ELASTICSEARCH_URL = parse_var_env('ELASTICSEARCH_URL')
DEFAULT_INDEX_NAME = parse_var_env('DEFAULT_INDEX_NAME')
INDEX_PREFIX = parse_var_env('INDEX_PREFIX')
SEARCH_RESULT_PER_PAGE = parse_var_env('SEARCH_RESULT_PER_PAGE')
APP_URL_PREFIX = parse_var_env('APP_URL_PREFIX')
API_URL_PREFIX = parse_var_env('API_URL_PREFIX')
API_VERSION = parse_var_env('API_VERSION')
@staticmethod
def init_app(app):
pass
class StagingConfig(Config):
ENV = 'development'
DEBUG = parse_var_env('DEBUG')
@staticmethod
def init_app(app):
print('THIS APP IS IN PRE-PROD MODE. YOU SHOULD NOT SEE THIS IN PRODUCTION.')
with app.app_context():
db_url = app.config["SQLALCHEMY_DATABASE_URI"]
if not database_exists(db_url):
create_database(db_url)
else:
pass
class LocalConfig(Config):
ENV = 'development'
DEBUG = parse_var_env('DEBUG')
@staticmethod
def init_app(app):
print('THIS APP IS IN LOCAL DEV MODE. YOU SHOULD NOT SEE THIS IN PRODUCTION.')
class TestConfig(Config):
ENV = 'testing'
@staticmethod
def init_app(app):
print('THIS APP IS IN TEST MODE. YOU SHOULD NOT SEE THIS IN PRODUCTION.')
with app.app_context():
db_url = app.config["SQLALCHEMY_DATABASE_URI"]
if not database_exists(db_url):
create_database(db_url)
else:
pass
config = {
"local": LocalConfig,
"staging": StagingConfig,
"prod": Config,
"test": TestConfig
}