-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.py
84 lines (70 loc) · 2.15 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
"""Configuration for tower app."""
import os
basedir = os.path.abspath(os.path.dirname(__file__))
def make_mongo_uri(
host='localhost',
port=27017,
database='default',
replica_set=None,
username=None,
password=None):
"""Make the mongo connection URI."""
uri = 'mongodb://'
if username is not None and password is not None:
uri += username + ':' + password + '@'
if ',' in host:
host = host.split(',')
if not isinstance(host, basestring):
if port is not None:
host = [x + ':' + str(port) for x in host]
uri += ",".join(host)
else:
uri += host
if port is not None:
uri += ':' + str(port)
if database is not None:
uri += '/' + database
if replica_set is not None:
uri += '?replicaSet=' + replica_set
uri += '?ssl=true'
return uri
class Config:
"""Configuration class for tower app."""
SECRET_KEY = os.environ.get('APP_SECRET')
ROOT_DIR = os.environ.get('ROOT_DIR')
SLACK_TOKEN = os.environ.get('SLACK_TOKEN')
@staticmethod
def init_app(app):
"""Initialize the config."""
pass
class TestingConfig(Config):
"""Test configuration settings."""
TESTING = True
SERVER_NAME = '0.0.0.0:5000'
MONGODB_SETTINGS = {
"db": 'testing',
"username": '',
"password": '',
"host": 'localhost',
"port": 27017
}
class DevelopmentConfig(Config):
"""Development configuration settings."""
ROOT_DIR = os.environ.get('ROOT_DIR')
SERVER_NAME = 'mpala.herokuapp.com'
DEBUG = True
MONGODB_SETTINGS = {
"HOST": make_mongo_uri(
host=os.environ.get('MONGODB_DEV_HOST'),
port=int(os.environ.get('MONGODB_DEV_PORT')),
database=os.environ.get('MONGODB_DEV_DATABASE'),
username=os.environ.get('MONGODB_DEV_USER'),
password=os.environ.get('MONGODB_DEV_PASSWORD'),
#replica_set=os.environ.get('MONGODB_DEV_REPLICASET')
)
}
config = {
'development': DevelopmentConfig,
'default': DevelopmentConfig,
'testing': TestingConfig
}