-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
118 lines (89 loc) · 3.45 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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# -*- coding: utf-8 -*-
import os
import logging
from logging.handlers import RotatingFileHandler
basedir = os.path.dirname(__file__)
class Config:
ADMINS = os.environ.get('ADMINS', '').split(',')
PRIVATE_KEY = os.environ.get('PRIVATE_KEY', os.path.join(basedir, 'auth_privkey.pem'))
PUBLIC_KEY = os.environ.get('PUBLIC_KEY', os.path.join(basedir, 'auth_pubkey.pem'))
SALT_KEY = os.environ.get('SALT_KEY', 'random')
CONFIRM_BASE_URL = os.environ.get('CONFIRM_BASE_URL', 'http://localhost/app_dev.php/register/confirm/')
PAGINATION_SIZE = int(os.environ.get('PAGINATION_SIZE', '10'))
ELASTICSEARCH_HOST = os.environ.get('ELASTICSEARCH_HOST', '')
ELASTICSEARCH_USER = os.environ.get('ELASTICSEARCH_USER', '')
ELASTICSEARCH_SECRET = os.environ.get('ELASTICSEARCH_SECRET', '')
MAIL_SERVER = os.environ.get('MAIL_SERVER', 'localhost')
MAIL_PORT = int(os.environ.get('MAIL_PORT', '1025'))
MAIL_USE_TLS = os.environ.get('MAIL_USE_TLS', 'False') == 'True'
MAIL_USE_SSL = os.environ.get('MAIL_USE_SSL', 'False') == 'True'
MAIL_DEBUG = os.environ.get('MAIL_DEBUG', 'False') == 'True'
MAIL_USERNAME = os.environ.get('MAIL_USERNAME', '')
MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD', '')
MAIL_DEFAULT_SENDER = os.environ.get('MAIL_DEFAULT_SENDER', 'rastadev@dev.dev')
LOG_PATH = os.environ.get('LOG_PATH', os.path.join(basedir, 'goals_backend.log'))
LOG_SIZE = int(os.environ.get('LOG_SIZE', '20000'))
LOG_COUNT = int(os.environ.get('LOG_COUNT', '10'))
LOG_ENCODING = os.environ.get('LOG_ENCODING', 'utf-8')
RESTPLUS_SWAGGER_UI_DOC_EXPANSION = 'list'
RESTPLUS_VALIDATE = True
RESTPLUS_MASK_SWAGGER = False
RESTPLUS_ERROR_404_HELP = True
JSON_SORT_KEYS = False
@staticmethod
def init_app(app):
"""
Init app
:param app: Flask App
:type app: Flask
"""
with open(app.config['PRIVATE_KEY']) as f:
app.config['PRIVATE_KEY'] = f.read()
with open(app.config['PUBLIC_KEY']) as f:
app.config['PUBLIC_KEY'] = f.read()
class DevelopmentConfig(Config):
"""
Development configuration
"""
DEBUG = True
@staticmethod
def init_app(app):
"""
Init app
:param app: Flask App
:type app: Flask
"""
Config.init_app(app)
for hdler in app.logger.handlers:
if isinstance(hdler, logging.FileHandler):
if hdler.baseFilename == os.path.abspath(os.fspath(app.config['LOG_PATH'])):
return
handler = RotatingFileHandler(app.config['LOG_PATH'],
maxBytes=app.config['LOG_SIZE'],
backupCount=app.config['LOG_COUNT'],
encoding=app.config['LOG_ENCODING'])
formatter = logging.Formatter(
'%(asctime)s %(levelname)s: %(message)s '
'[in %(pathname)s:%(lineno)d]'
)
handler.setFormatter(formatter)
handler.setLevel(logging.INFO)
app.logger.addHandler(handler)
class ProductionConfig(Config):
"""
Production configuration
"""
DEBUG = False
@staticmethod
def init_app(app):
"""
Init app
:param app: Flask App
:type app: Flask
"""
DevelopmentConfig.init_app(app)
config = {
'development': DevelopmentConfig,
'production': ProductionConfig,
'default': DevelopmentConfig
}