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
|
## LDAP Backend config
|
34
|
ldap_url = config.get('ldap', 'url')
|
35
|
ldap_bind_dn = config.get('ldap', 'base_dn')
|
36
|
ldap_bind_password = config.get('ldap', 'bind_password')
|
37
|
ldap_base_dn = config.get('ldap', 'base_dn')
|
38
|
|
39
|
debug = config.getboolean('debug', 'debug')
|
40
|
|
41
|
# Log configuration
|
42
|
LOGGING = {{
|
43
|
'version': 1,
|
44
|
'disable_existing_loggers': True,
|
45
|
|
46
|
'formatters': {{
|
47
|
'console': {{
|
48
|
'format': '%(asctime)s %(levelname)s %(message)s',
|
49
|
'datefmt': '%H:%M:%S',
|
50
|
}},
|
51
|
'file': {{
|
52
|
'format': '%(asctime)s %(levelname)s %(uuid)s %(message)s',
|
53
|
'datefmt': '%Y-%m-%d %H:%M:%S'
|
54
|
}}
|
55
|
}},
|
56
|
'handlers': {{
|
57
|
'console': {{
|
58
|
'level': 'DEBUG',
|
59
|
'class': 'logging.StreamHandler',
|
60
|
'formatter': 'console'
|
61
|
}},
|
62
|
'syslog': {{
|
63
|
'level': 'DEBUG',
|
64
|
'class': 'entrouvert.logging.handlers.SysLogHandler',
|
65
|
'formatter': 'file',
|
66
|
'address': '/dev/log'
|
67
|
}},
|
68
|
}},
|
69
|
'loggers': {{
|
70
|
'': {{
|
71
|
'handlers': ['console'],
|
72
|
'level': 'INFO',
|
73
|
'propagate': False,
|
74
|
}},
|
75
|
'mandaye': {{
|
76
|
'handlers': ['console', 'syslog'],
|
77
|
'level': 'INFO',
|
78
|
'propagate': False,
|
79
|
}},
|
80
|
'cam': {{
|
81
|
'handlers': ['console', 'syslog'],
|
82
|
'level': 'INFO',
|
83
|
'propagate': False,
|
84
|
}},
|
85
|
}},
|
86
|
}}
|
87
|
|
88
|
if config.getboolean('debug', 'log_debug'):
|
89
|
LOGGING['loggers']['']['level'] = 'DEBUG'
|
90
|
LOGGING['loggers']['mandaye']['level'] = 'DEBUG'
|
91
|
LOGGING['loggers']['cam']['level'] = 'DEBUG'
|
92
|
|
93
|
## PATH
|
94
|
# Configuration directory
|
95
|
config_root = config.get('dirs', 'config_root')
|
96
|
# Templates directories
|
97
|
templates_directories = []
|
98
|
if config.get('dirs', 'templates_directories'):
|
99
|
templates_directories = config.get('dirs', 'templates_directories').split(' ')
|
100
|
templates_directories.append(os.path.join(BASE_DIR, 'templates'))
|
101
|
# Static url
|
102
|
static_url = config.get('dirs', 'static_url')
|
103
|
# Static folder
|
104
|
static_root = config.get('dirs', 'static_root')
|
105
|
# Data dir
|
106
|
data_dir = config.get('dirs', 'data_dir')
|
107
|
|
108
|
# template vars
|
109
|
template_vars = {{}}
|
110
|
if config.has_section('template_vars'):
|
111
|
for option in config.options('template_vars'):
|
112
|
template_vars[option] = config.get('template_vars', option)
|
113
|
|
114
|
# Supported authentification
|
115
|
authentifications = {{
|
116
|
'saml2': 'mandaye.auth.saml2.SAML2Auth'
|
117
|
}}
|
118
|
|
119
|
# sp mappers
|
120
|
mappers = {{
|
121
|
'linuxfr': '{project_name}.mappers.linuxfr_example',
|
122
|
}}
|
123
|
|
124
|
# Raven Sentry configuration
|
125
|
raven_dsn = config.get('debug', 'sentry_dsn')
|
126
|
|
127
|
# Email notification configuration
|
128
|
email_notification = config.getboolean('email', 'notification')
|
129
|
email_prefix = config.get('email', 'prefix')
|
130
|
smtp_host = config.get('email', 'smtp_host')
|
131
|
smtp_port = config.getint('email', 'smtp_port')
|
132
|
email_from = config.get('email', 'from')
|
133
|
email_to = config.get('email', 'to').split()
|
134
|
|
135
|
# Use long traceback with xtraceback
|
136
|
use_long_trace = config.getboolean('debug', 'use_long_trace')
|
137
|
# Ask Mandaye to auto decompress a response message
|
138
|
# Decompress response only if you load a filter
|
139
|
auto_decompress = config.getboolean('mandaye', 'auto_decompress')
|
140
|
# Ask mandaye to add a toolbar with Mandaye's links
|
141
|
mandaye_toolbar = config.getboolean('mandaye', 'toolbar')
|
142
|
mandaye_offline_toolbar = config.getboolean('mandaye', 'offline_toolbar')
|
143
|
# Authentic 2 auto connection
|
144
|
a2_auto_connection = config.getboolean('mandaye', 'a2_auto_connection')
|
145
|
|
146
|
# Choose storage (sql or ldap)
|
147
|
if config.get('mandaye', 'storage_backend') == 'sql':
|
148
|
storage_backend = "mandaye.backends.sql"
|
149
|
elif config.get('mandaye', 'storage_backend') == 'ldap':
|
150
|
storage_backend = "mandaye.backends.ldap_back"
|
151
|
else:
|
152
|
ImproperlyConfigured('Storage backend must be sql or ldap')
|
153
|
|
154
|
# Encrypt service provider passwords with a secret
|
155
|
# You should install pycypto to use this feature
|
156
|
encrypt_sp_password = config.getboolean('mandaye', 'encrypt_sp_password')
|
157
|
# Must be a 15, 24, or 32 bytes long
|
158
|
encrypt_secret = config.get('mandaye', 'encrypt_secret')
|
159
|
|
160
|
session_type = config.get('session', 'type')
|
161
|
if session_type not in ('file', 'dbm', 'memory', 'memcached'):
|
162
|
raise ImproperlyConfigured('Sesssion type %r not supported' % session_type)
|
163
|
if session_type == 'memcached':
|
164
|
session_type = 'ext:memcached'
|
165
|
|
166
|
# Beaker session configuration
|
167
|
session_opts = {{
|
168
|
'session.type': session_type,
|
169
|
'session.url': config.get('session', 'url'),
|
170
|
'session.cookie_expires': config.getboolean('session', 'cookie_expires'),
|
171
|
'session.timeout': config.getint('session', 'timeout'),
|
172
|
'session.data_dir': config.get('session', 'data_dir'),
|
173
|
'session.path': '/'
|
174
|
}}
|
175
|
|
176
|
# Import local config
|
177
|
try:
|
178
|
from cam.local_config import *
|
179
|
except ImportError, e:
|
180
|
if not 'local_config' in e.args[0]:
|
181
|
raise ImproperlyConfigured('Error while importing "local_config.py"')
|
182
|
|