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