-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.py
68 lines (46 loc) · 1.62 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
import os, random, string, uuid
class Config(object):
basedir = os.path.abspath(os.path.dirname(__file__))
# Set up the App SECRET_KEY
SECRET_KEY = os.getenv('SECRET_KEY', uuid.uuid4().hex)
if not SECRET_KEY:
SECRET_KEY = ''.join(random.choice( string.ascii_lowercase ) for i in range( 32 ))
SQLALCHEMY_TRACK_MODIFICATIONS = False
DB_ENGINE = os.getenv('DB_ENGINE' , None)
DB_USERNAME = os.getenv('DB_USERNAME' , None)
DB_PASS = os.getenv('DB_PASS' , None)
DB_HOST = os.getenv('DB_HOST' , None)
DB_PORT = os.getenv('DB_PORT' , None)
DB_NAME = os.getenv('DB_NAME' , None)
USE_SQLITE = True
# try to set up a Relational DBMS
if DB_ENGINE and DB_NAME and DB_USERNAME:
try:
# Relational DBMS: PSQL, MySql
SQLALCHEMY_DATABASE_URI = '{}://{}:{}@{}:{}/{}'.format(
DB_ENGINE,
DB_USERNAME,
DB_PASS,
DB_HOST,
DB_PORT,
DB_NAME
)
USE_SQLITE = False
except:
pass
if USE_SQLITE:
# This will create a file in <app> FOLDER
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'db.sqlite3')
class ProductionConfig(Config):
DEBUG = False
# Security
SESSION_COOKIE_HTTPONLY = True
REMEMBER_COOKIE_HTTPONLY = True
REMEMBER_COOKIE_DURATION = 3600
class DebugConfig(Config):
DEBUG = True
# Load all possible configurations
config_dict = {
'Production': ProductionConfig,
'Debug' : DebugConfig
}