-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.py
70 lines (58 loc) · 2.34 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
import os
import urllib.parse
basedir = os.path.abspath(os.path.dirname(__file__))
# Environment variables
if os.path.exists('config.env'):
print('Importing environment from .env file')
for line in open('config.env'):
var = line.strip().split('=')
if len(var) == 2:
os.environ[var[0]] = var[1].replace("\"", "")
class Config:
APP_NAME = os.environ.get('APP_NAME')
if os.environ.get('SECRET_KEY'):
SECRET_KEY = os.environ.get('SECRET_KEY')
else:
SECRET_KEY = 'SECRET_KEY_ENV_VAR_NOT_SET'
print('SECRET KEY ENV VAR NOT SET! SHOULD NOT SEE IN PRODUCTION')
SQLALCHEMY_COMMIT_ON_TEARDOWN = True
SQLALCHEMY_TRACK_MODIFICATIONS = False
# Email
MAIL_SERVER = os.environ.get('MAIL_SERVER')
MAIL_PORT = os.environ.get('MAIL_PORT') or 587
MAIL_USE_TLS = os.environ.get('MAIL_USE_TLS') or True
MAIL_USE_SSL = os.environ.get('MAIL_USE_SSL') or False
MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
MAIL_DEFAULT_SENDER = os.environ.get('MAIL_DEFAULT_SENDER')
# Admin account
ADMIN_PASSWORD = os.environ.get('ADMIN_PASSWORD') or 'password'
ADMIN_EMAIL = os.environ.get('ADMIN_EMAIL')
EMAIL_SUBJECT_PREFIX = '[{}]'.format(APP_NAME)
EMAIL_SENDER = '{app_name} Admin <{email}>'.format(
app_name=APP_NAME, email=MAIL_USERNAME)
# AWS
FLASKS3_BUCKET_NAME = os.environ.get('FLASKS3_BUCKET_NAME')
FLASKS3_URL_STYLE = os.environ.get('FLASKS3_URL_STYLE')
FLASKS3_BUCKET_DOMAIN = os.environ.get('FLASKS3_BUCKET_DOMAIN')
AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
@staticmethod
def init_app(app):
pass
class DevelopmentConfig(Config):
DEBUG = True
ASSETS_DEBUG = True
SQLALCHEMY_DATABASE_URI = os.environ.get('DEV_DATABASE_URL') or \
'sqlite:///' + os.path.join(basedir, 'data-dev.sqlite')
class ProductionConfig(Config):
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL')
SSL_DISABLE = (os.environ.get('SSL_DISABLE') or 'True') == 'True'
@classmethod
def init_app(cls, app):
Config.init_app(app)
assert os.environ.get('SECRET_KEY'), 'SECRET_KEY IS NOT SET!'
config = {
'development': DevelopmentConfig,
'production': ProductionConfig
}