1
|
import logging
|
2
|
import os
|
3
|
|
4
|
from ConfigParser import SafeConfigParser
|
5
|
from mandaye.exceptions import ImproperlyConfigured
|
6
|
|
7
|
# get configuration files from :
|
8
|
# 1. default-settings.ini from source code
|
9
|
# 2. os.environ.get('SETTINGS_INI') if it exists
|
10
|
# else /etc/mandaye-cam/config.ini
|
11
|
# and then /etc/mandaye-cam/local-config.ini
|
12
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
13
|
SETTINGS_INI = (os.path.join(BASE_DIR, 'default-config.ini'),)
|
14
|
if os.environ.get('SETTINGS_INI'):
|
15
|
SETTINGS_INI += (os.environ.get('SETTINGS_INI'),)
|
16
|
else:
|
17
|
ETC_DIR = os.path.join('/', 'etc', 'mandaye-cam')
|
18
|
SETTINGS_INI += (
|
19
|
os.path.join(ETC_DIR, 'config.ini'),
|
20
|
os.path.join(ETC_DIR, 'local-config.ini')
|
21
|
)
|
22
|
|
23
|
config = SafeConfigParser()
|
24
|
config.read(SETTINGS_INI)
|
25
|
|
26
|
## SQL Backend config
|
27
|
# Database configuration
|
28
|
# http://docs.sqlalchemy.org/en/rel_0_7/core/engines.html
|
29
|
# rfc 1738 https://tools.ietf.org/html/rfc1738
|
30
|
# dialect+driver://username:password@host:port/database
|
31
|
db_url = config.get('database', 'url')
|
32
|
|
33
|
debug = config.getboolean('debug', 'debug')
|
34
|
|
35
|
# Log configuration
|
36
|
LOGGING = {{
|
37
|
'version': 1,
|
38
|
'disable_existing_loggers': True,
|
39
|
|
40
|
'formatters': {{
|
41
|
'console': {{
|
42
|
'format': '%(asctime)s %(levelname)s %(message)s',
|
43
|
'datefmt': '%H:%M:%S',
|
44
|
}},
|
45
|
'file': {{
|
46
|
'format': '%(asctime)s %(levelname)s %(uuid)s %(message)s',
|
47
|
'datefmt': '%Y-%m-%d %H:%M:%S'
|
48
|
}}
|
49
|
}},
|
50
|
'handlers': {{
|
51
|
'console': {{
|
52
|
'level': 'DEBUG',
|
53
|
'class': 'logging.StreamHandler',
|
54
|
'formatter': 'console'
|
55
|
}},
|
56
|
'syslog': {{
|
57
|
'level': 'DEBUG',
|
58
|
'class': 'entrouvert.logging.handlers.SysLogHandler',
|
59
|
'formatter': 'file',
|
60
|
'address': '/dev/log'
|
61
|
}},
|
62
|
}},
|
63
|
'loggers': {{
|
64
|
'': {{
|
65
|
'handlers': ['console'],
|
66
|
'level': 'INFO',
|
67
|
'propagate': False,
|
68
|
}},
|
69
|
'mandaye': {{
|
70
|
'handlers': ['console', 'syslog'],
|
71
|
'level': 'INFO',
|
72
|
'propagate': False,
|
73
|
}},
|
74
|
'cam': {{
|
75
|
'handlers': ['console', 'syslog'],
|
76
|
'level': 'INFO',
|
77
|
'propagate': False,
|
78
|
}},
|
79
|
}},
|
80
|
}}
|
81
|
|
82
|
if config.getboolean('debug', 'log_debug'):
|
83
|
LOGGING['loggers']['']['level'] = 'DEBUG'
|
84
|
LOGGING['loggers']['mandaye']['level'] = 'DEBUG'
|
85
|
LOGGING['loggers']['cam']['level'] = 'DEBUG'
|
86
|
|
87
|
## PATH
|
88
|
# Configuration directory
|
89
|
config_root = config.get('dirs', 'config_root')
|
90
|
# Templates directories
|
91
|
templates_directories = [os.path.join(BASE_DIR, 'templates')]
|
92
|
if config.get('dirs', 'templates_directories'):
|
93
|
templates_directories.extend(config.get('dirs', 'templates_directories').split(' '))
|
94
|
# Static url
|
95
|
static_url = config.get('dirs', 'static_url')
|
96
|
# Static folder
|
97
|
static_root = config.get('dirs', 'static_root')
|
98
|
# Data dir
|
99
|
data_dir = config.get('dirs', 'data_dir')
|
100
|
|
101
|
# Supported authentification
|
102
|
authentifications = {{
|
103
|
'saml2': 'mandaye.auth.saml2.SAML2Auth'
|
104
|
}}
|
105
|
|
106
|
# sp mappers
|
107
|
mappers = {{
|
108
|
'linuxfr': '{project_name}.mappers.linuxfr_example',
|
109
|
}}
|
110
|
|
111
|
# Raven Sentry configuration
|
112
|
raven_dsn = config.get('debug', 'sentry_dsn')
|
113
|
|
114
|
# Email notification configuration
|
115
|
email_notification = config.getboolean('email', 'notification')
|
116
|
email_prefix = config.get('email', 'prefix')
|
117
|
smtp_host = config.get('email', 'smtp_host')
|
118
|
smtp_port = config.getint('email', 'smtp_port')
|
119
|
email_from = config.get('email', 'from')
|
120
|
email_to = config.get('email', 'to').split()
|
121
|
|
122
|
# Use long traceback with xtraceback
|
123
|
use_long_trace = config.getboolean('debug', 'use_long_trace')
|
124
|
# Ask Mandaye to auto decompress a response message
|
125
|
# Decompress response only if you load a filter
|
126
|
auto_decompress = config.getboolean('mandaye', 'auto_decompress')
|
127
|
# Ask mandaye to add a toolbar with Mandaye's links
|
128
|
mandaye_toolbar = config.getboolean('mandaye', 'toolbar')
|
129
|
# Authentic 2 auto connection
|
130
|
a2_auto_connection = config.getboolean('mandaye', 'a2_auto_connection')
|
131
|
|
132
|
# Choose storage
|
133
|
# Only mandaye.backends.sql at the moment
|
134
|
if config.get('mandaye', 'storage_backend') == 'sql':
|
135
|
storage_backend = "mandaye.backends.sql"
|
136
|
else:
|
137
|
ImproperlyConfigured('Storage backend must be sql')
|
138
|
|
139
|
# Encrypt service provider passwords with a secret
|
140
|
# You should install pycypto to use this feature
|
141
|
encrypt_sp_password = config.getboolean('mandaye', 'encrypt_sp_password')
|
142
|
# Must be a 15, 24, or 32 bytes long
|
143
|
encrypt_secret = config.get('mandaye', 'encrypt_secret')
|
144
|
|
145
|
session_type = config.get('session', 'type')
|
146
|
if session_type not in ('file', 'dbm', 'memory', 'memcached'):
|
147
|
raise ImproperlyConfigured('Sesssion type %r not supported' % session_type)
|
148
|
if session_type == 'memcached':
|
149
|
session_type = 'ext:memcached'
|
150
|
|
151
|
# Beaker session configuration
|
152
|
session_opts = {{
|
153
|
'session.type': session_type,
|
154
|
'session.url': config.get('session', 'url'),
|
155
|
'session.cookie_expires': config.getboolean('session', 'cookie_expires'),
|
156
|
'session.timeout': config.getint('session', 'timeout'),
|
157
|
'session.data_dir': config.get('session', 'data_dir')
|
158
|
}}
|
159
|
|
160
|
# Import local config
|
161
|
try:
|
162
|
from cam.local_config import *
|
163
|
except ImportError, e:
|
164
|
if not 'local_config' in e.args[0]:
|
165
|
raise ImproperlyConfigured('Error while importing "local_config.py"')
|
166
|
|