-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathconfig.py
64 lines (50 loc) · 1.89 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
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Contributors: Andrew Krug <[email protected]>
"""Configuration loader for different environments."""
import os
import watchtower
import logging
from utils import get_secret
class Config(object):
def __init__(self, app):
self.app = app
self.environment = os.environ.get('ENVIRONMENT')
self.settings = self._init_env()
def _init_env(self):
if self.environment == 'Production':
self.app.logger.addHandler(watchtower.CloudWatchLogHandler())
return ProductionConfig()
elif self.environment == 'Staging':
self.app.logger.addHandler(watchtower.CloudWatchLogHandler())
return StagingConfig()
else:
return DevelopmentConfig()
class DefaultConfig(object):
"""Defaults for the configuration objects."""
DEBUG = True
LOG_LEVEL = logging.DEBUG
PERMANENT_SESSION = True
PERMANENT_SESSION_LIFETIME = 86400
SECRET_KEY = get_secret('accessproxy.flask_secret', {'app': 'accessproxy'})
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_SECURE = True
SESSION_TYPE = 'filesystem'
SESSION_FILE_THRESHOLD = 5000
SESSION_FILE_DIR = '/tmp/accessproxy/sessions/'
SESSION_FILE_MODE = 0o600
REVERSE_PROXY_COOKIE_NAME = 'session'
CA_USER_SECRET_KEY = get_secret('accessproxy.ca_user_key', {'app': 'accessproxy'})
CA_USER_PUBLIC_KEY = get_secret('accessproxy.ca_user_key_pub', {'app': 'accessproxy'})
class ProductionConfig(DefaultConfig):
LOG_LEVEL = logging.INFO
DEBUG = False
class StagingConfig(DefaultConfig):
LOG_LEVEL = logging.DEBUG
DEBUG = False
class DevelopmentConfig(DefaultConfig):
DEVELOPMENT = True
DEBUG = True
SECRET_KEY = 'abab123123'