0001-Centralized-config.py-into-mandaye-core.patch
MANIFEST.in | ||
---|---|---|
1 | 1 |
include MANIFEST.in |
2 | 2 |
include VERSION |
3 |
include mandaye/alembic.ini |
|
3 |
include mandaye/alembic.ini mandaye/default-config.ini
|
|
4 | 4 | |
5 | 5 |
recursive-include mandaye/alembic * |
6 | 6 |
recursive-include mandaye/templates *.html |
mandaye/__init__.py | ||
---|---|---|
1 | 1 |
__version__='0.10.2' |
2 | ||
3 |
import os |
|
4 | ||
5 |
from importlib import import_module |
|
6 | ||
7 |
from mandaye import global_config |
|
8 |
from mandaye.exceptions import ImproperlyConfigured |
|
9 | ||
10 |
ENVIRONMENT_VARIABLE = "MANDAYE_CONFIG_MODULE" |
|
11 |
config = None |
|
12 | ||
13 |
if os.environ.has_key(ENVIRONMENT_VARIABLE): |
|
14 |
try: |
|
15 |
mod = import_module(os.environ[ENVIRONMENT_VARIABLE]) |
|
16 |
except ImportError, e: |
|
17 |
raise ImproperlyConfigured('Error importing config %s: "%s"' % (os.environ[ENVIRONMENT_VARIABLE], e)) |
|
18 |
config = mod |
|
19 |
else: |
|
20 |
config = global_config |
|
21 |
mandaye/config.py | ||
---|---|---|
1 |
import os |
|
2 | ||
3 |
from ConfigParser import SafeConfigParser |
|
4 |
from mandaye.exceptions import ImproperlyConfigured |
|
5 | ||
6 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
|
7 | ||
8 |
# get configuration files from : |
|
9 |
# 1. default-settings.ini from source code |
|
10 |
# 2. from MANDAYE_CONFIG_FILE environ variable |
|
11 |
SETTINGS_INI = [os.path.join(BASE_DIR, 'default-config.ini')] |
|
12 |
if 'MANDAYE_CONFIG_FILES' in os.environ: |
|
13 |
print 'Loading setting files %r' % os.environ['MANDAYE_CONFIG_FILES'] |
|
14 |
SETTINGS_INI += os.environ['MANDAYE_CONFIG_FILES'].split(' ') |
|
15 |
config = SafeConfigParser() |
|
16 |
config.read(SETTINGS_INI) |
|
17 | ||
18 | ||
19 |
def section2dict(section): |
|
20 |
res = dict() |
|
21 |
if config.has_section(section): |
|
22 |
for opt in config.options(section): |
|
23 |
res[opt] = config.get(section, opt) |
|
24 |
return res |
|
25 | ||
26 |
## SQL Backend config |
|
27 |
# Database configuration |
|
28 |
# dialect+driver://username:password@host:port/database |
|
29 |
db_url = config.get('database', 'url') |
|
30 | ||
31 |
## LDAP Backend config |
|
32 |
ldap_url = config.get('ldap', 'url') |
|
33 |
ldap_bind_dn = config.get('ldap', 'bind_dn') |
|
34 |
ldap_bind_password = config.get('ldap', 'bind_password') |
|
35 |
ldap_base_dn = config.get('ldap', 'base_dn') |
|
36 | ||
37 |
debug = config.getboolean('debug', 'debug') |
|
38 | ||
39 |
# Log configuration |
|
40 |
logger_name = config.get('debug', 'logger_name') |
|
41 |
LOGGING = { |
|
42 |
'version': 1, |
|
43 |
'disable_existing_loggers': True, |
|
44 | ||
45 |
'formatters': { |
|
46 |
'console': { |
|
47 |
'format': '%(asctime)s %(levelname)s %(message)s', |
|
48 |
'datefmt': '%H:%M:%S', |
|
49 |
}, |
|
50 |
'syslog': { |
|
51 |
'format': 'mandaye(pid=%(process)d) %(name)s %(levelname)s %(uuid)s %(message)s', |
|
52 |
'datefmt': '%Y-%m-%d %H:%M:%S' |
|
53 |
} |
|
54 |
}, |
|
55 |
'handlers': { |
|
56 |
'console': { |
|
57 |
'level': 'DEBUG', |
|
58 |
'class': 'logging.StreamHandler', |
|
59 |
'formatter': 'console' |
|
60 |
}, |
|
61 |
'syslog': { |
|
62 |
'level': 'DEBUG', |
|
63 |
'class': 'entrouvert.logging.handlers.SysLogHandler', |
|
64 |
'formatter': 'syslog', |
|
65 |
'address': '/dev/log' |
|
66 |
}, |
|
67 |
}, |
|
68 |
'loggers': { |
|
69 |
'': { |
|
70 |
'handlers': ['console'], |
|
71 |
'level': 'INFO', |
|
72 |
'propagate': False, |
|
73 |
}, |
|
74 |
'mandaye': { |
|
75 |
'handlers': ['console', 'syslog'], |
|
76 |
'level': 'INFO', |
|
77 |
'propagate': False, |
|
78 |
}, |
|
79 |
logger_name: { |
|
80 |
'handlers': ['console', 'syslog'], |
|
81 |
'level': 'INFO', |
|
82 |
'propagate': False, |
|
83 |
}, |
|
84 |
}, |
|
85 |
} |
|
86 | ||
87 |
if config.getboolean('debug', 'log_debug'): |
|
88 |
LOGGING['loggers']['']['level'] = 'DEBUG' |
|
89 |
LOGGING['loggers']['mandaye']['level'] = 'DEBUG' |
|
90 |
LOGGING['loggers'][logger_name]['level'] = 'DEBUG' |
|
91 | ||
92 |
## PATH |
|
93 |
# Configuration directory |
|
94 |
config_root = config.get('dirs', 'config_root') |
|
95 |
template_directory = os.path.join(BASE_DIR, 'templates') |
|
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 |
skel_root = os.path.join(BASE_DIR, 'skel') |
|
108 | ||
109 |
# template vars |
|
110 |
template_vars = section2dict('template_vars') |
|
111 | ||
112 |
# Supported authentification |
|
113 |
authentifications = section2dict('authentifications') |
|
114 | ||
115 |
# sp mappers |
|
116 |
mappers = section2dict('mappers') |
|
117 | ||
118 |
# Raven Sentry configuration |
|
119 |
raven_dsn = config.get('debug', 'sentry_dsn') |
|
120 | ||
121 |
# Email notification configuration |
|
122 |
email_notification = config.getboolean('email', 'notification') |
|
123 |
email_prefix = config.get('email', 'prefix') |
|
124 |
smtp_host = config.get('email', 'smtp_host') |
|
125 |
smtp_port = config.getint('email', 'smtp_port') |
|
126 |
email_from = config.get('email', 'from') |
|
127 |
email_to = config.get('email', 'to').split() |
|
128 | ||
129 |
# Alembic configuration |
|
130 |
alembic_cfg = os.path.join(BASE_DIR, 'alembic.ini') |
|
131 |
alembic_script_path = os.path.join(BASE_DIR, 'alembic') |
|
132 | ||
133 |
# Use long traceback with xtraceback |
|
134 |
use_long_trace = config.getboolean('debug', 'use_long_trace') |
|
135 |
# Ask Mandaye to auto decompress a response message |
|
136 |
# Decompress response only if you load a filter |
|
137 |
auto_decompress = config.getboolean('mandaye', 'auto_decompress') |
|
138 |
# Ask mandaye to add a toolbar with Mandaye's links |
|
139 |
mandaye_toolbar = config.getboolean('mandaye', 'toolbar') |
|
140 |
mandaye_offline_toolbar = config.getboolean('mandaye', 'offline_toolbar') |
|
141 |
# Authentic 2 auto connection |
|
142 |
a2_auto_connection = config.getboolean('mandaye', 'a2_auto_connection') |
|
143 | ||
144 |
# Choose storage (sql or ldap) |
|
145 |
if config.get('mandaye', 'storage_backend') == 'sql': |
|
146 |
storage_backend = "mandaye.backends.sql" |
|
147 |
elif config.get('mandaye', 'storage_backend') == 'ldap': |
|
148 |
storage_backend = "mandaye.backends.ldap_back" |
|
149 |
else: |
|
150 |
ImproperlyConfigured('Storage backend must be sql or ldap') |
|
151 | ||
152 |
# Encrypt service provider passwords with a secret |
|
153 |
# You should install pycypto to use this feature |
|
154 |
encrypt_sp_password = config.getboolean('mandaye', 'encrypt_sp_password') |
|
155 |
# Must be a 15, 24, or 32 bytes long |
|
156 |
encrypt_secret = config.get('mandaye', 'encrypt_secret') |
|
157 | ||
158 |
session_type = config.get('session', 'type') |
|
159 |
if session_type not in ('file', 'dbm', 'memory', 'memcached'): |
|
160 |
raise ImproperlyConfigured('Sesssion type %r not supported' % session_type) |
|
161 |
if session_type == 'memcached': |
|
162 |
session_type = 'ext:memcached' |
|
163 | ||
164 |
# Beaker session configuration |
|
165 |
session_opts = { |
|
166 |
'session.type': session_type, |
|
167 |
'session.url': config.get('session', 'url'), |
|
168 |
'session.cookie_expires': config.getboolean('session', 'cookie_expires'), |
|
169 |
'session.timeout': config.getint('session', 'timeout'), |
|
170 |
'session.data_dir': config.get('session', 'data_dir') |
|
171 |
} |
|
172 | ||
173 |
# Import local config |
|
174 |
try: |
|
175 |
from local_config import * |
|
176 |
except ImportError, e: |
|
177 |
if not 'local_config' in e.args[0]: |
|
178 |
raise ImproperlyConfigured('Error while importing "local_config.py"') |
|
179 |
mandaye/default-config.ini | ||
---|---|---|
1 |
[DEFAULT] |
|
2 |
base_dir: . |
|
3 | ||
4 |
[database] |
|
5 |
; http://docs.sqlalchemy.org/en/rel_0_8/core/engines.html |
|
6 |
url: sqlite:///%(base_dir)s/mandaye.db |
|
7 | ||
8 |
[ldap] |
|
9 |
; use by ldap backend |
|
10 |
url: ldap://127.0.0.1 |
|
11 |
bind_dn: cn=admin,dc=acompany,dc=org |
|
12 |
bind_password: AdminPassword |
|
13 |
base_dn: ou=mandaye,dc=acompany,dc=org |
|
14 | ||
15 |
[dirs] |
|
16 |
config_root: %(base_dir)s/conf.d |
|
17 |
data_dir: %(base_dir)s/data |
|
18 |
static_root: %(base_dir)s/mandaye/static |
|
19 |
static_url: /mandaye/static |
|
20 |
templates_directories: |
|
21 | ||
22 |
[debug] |
|
23 |
debug: false |
|
24 |
use_long_trace: true |
|
25 |
log_debug: false |
|
26 |
logger_name: mandaye |
|
27 |
; you need to install python-raven for this feature |
|
28 |
sentry_dsn: |
|
29 | ||
30 |
[mandaye] |
|
31 |
toolbar: true |
|
32 |
offline_toolbar: false |
|
33 |
a2_auto_connection: true |
|
34 |
; sql or ldap |
|
35 |
storage_backend: ldap |
|
36 |
auto_decompress: true |
|
37 |
; if you want to encypt password set to true |
|
38 |
; you need to install pycrypto for this feature |
|
39 |
encrypt_sp_password: false |
|
40 |
; if encrypt_sp_password then you need to choose a secret |
|
41 |
; must be a 16, 24, or 32 bytes long |
|
42 |
encrypt_secret: |
|
43 | ||
44 |
[template_vars] |
|
45 |
; my_var: toto |
|
46 | ||
47 |
[authentifications] |
|
48 |
saml2: mandaye.auth.saml2.SAML2Auth |
|
49 | ||
50 |
[mappers] |
|
51 |
; my_mapper: mandaye_toto.mappers.titi |
|
52 | ||
53 |
[session] |
|
54 |
; file, dbm, memory or memcached |
|
55 |
; if memcached you need to install python-memcached and memcached |
|
56 |
type: memcached |
|
57 |
url: 127.0.0.1:11211 |
|
58 |
cookie_expires: true |
|
59 |
timeout: 3600 |
|
60 |
data_dir: %(base_dir)s/data |
|
61 | ||
62 |
[email] |
|
63 |
notification: false |
|
64 |
prefix: [Mandaye] |
|
65 |
smtp_host: localhost |
|
66 |
smtp_port: 25 |
|
67 |
from: traceback@example.com |
|
68 |
to: admin+mandaye@example.com |
mandaye/global_config.py | ||
---|---|---|
1 | ||
2 |
import os |
|
3 | ||
4 |
_PROJECT_PATH = os.path.join(os.path.dirname(__file__), '..') |
|
5 | ||
6 |
# Choose storage |
|
7 |
# mandaye.backends.ldap_back or mandaye.backends.sql |
|
8 |
storage_backend = "mandaye.backends.sql" |
|
9 | ||
10 |
## SQL Backend config |
|
11 |
# Database configuration |
|
12 |
# http://docs.sqlalchemy.org/en/rel_0_8/core/engines.html |
|
13 |
# rfc 1738 https://tools.ietf.org/html/rfc1738 |
|
14 |
# dialect+driver://username:password@host:port/database |
|
15 |
db_url = 'sqlite:///test.db' |
|
16 | ||
17 |
## LDAP Backend config |
|
18 |
ldap_url = 'ldap://127.0.0.1' |
|
19 |
ldap_bind_dn = 'cn=admin,dc=acompany,dc=org' |
|
20 |
ldap_bind_password = 'MyPassword' |
|
21 |
ldap_base_dn = 'ou=mandaye,dc=acompany,dc=org' |
|
22 | ||
23 |
# urllib2 debug mode |
|
24 |
debug = False |
|
25 | ||
26 |
# Log configuration |
|
27 |
LOGGING = { |
|
28 |
'version': 1, |
|
29 |
'disable_existing_loggers': True, |
|
30 | ||
31 |
'formatters': { |
|
32 |
'console': { |
|
33 |
'format': '%(asctime)s %(levelname)s %(message)s', |
|
34 |
'datefmt': '%H:%M:%S', |
|
35 |
}, |
|
36 |
'syslog': { |
|
37 |
'format': '%(name)s %(levelname)s %(uuid)s %(message)s', |
|
38 |
} |
|
39 |
}, |
|
40 |
'handlers': { |
|
41 |
'console': { |
|
42 |
'level': 'DEBUG', |
|
43 |
'class': 'logging.StreamHandler', |
|
44 |
'formatter': 'console' |
|
45 |
}, |
|
46 |
'syslog': { |
|
47 |
'level': 'INFO', |
|
48 |
'class': 'entrouvert.logging.handlers.SysLogHandler', |
|
49 |
'formatter': 'syslog', |
|
50 |
'address': '/dev/log', |
|
51 |
'max_length': 999, |
|
52 |
}, |
|
53 |
}, |
|
54 |
'loggers': { |
|
55 |
'': { |
|
56 |
'handlers': ['console'], |
|
57 |
'level': 'DEBUG', |
|
58 |
'propagate': False, |
|
59 |
}, |
|
60 |
'mandaye': { |
|
61 |
'handlers': ['console', 'syslog'], |
|
62 |
'level': 'DEBUG', |
|
63 |
'propagate': False, |
|
64 |
}, |
|
65 |
}, |
|
66 |
} |
|
67 | ||
68 |
# Template directory |
|
69 |
template_directory = os.path.join(_PROJECT_PATH, 'mandaye/templates') |
|
70 |
templates_directories = [] |
|
71 |
# Configuration directory |
|
72 |
config_root = os.path.join(_PROJECT_PATH, 'conf.d') |
|
73 |
# Static path |
|
74 |
static_url = '/mandaye/static' |
|
75 |
# Static folder |
|
76 |
static_root = os.path.join(_PROJECT_PATH, 'mandaye/static') |
|
77 |
# Data dir |
|
78 |
data_dir = os.path.join(_PROJECT_PATH, 'data') |
|
79 |
# Skel root |
|
80 |
skel_root = os.path.join(_PROJECT_PATH, 'mandaye/skel') |
|
81 | ||
82 |
# Raven Sentry configuration |
|
83 |
raven_dsn = None |
|
84 | ||
85 |
# Email notification configuration |
|
86 |
email_notification = False |
|
87 |
email_prefix='[Mandaye]' |
|
88 |
smtp_host = 'localhost' |
|
89 |
smtp_port = 25 |
|
90 |
email_from = 'traceback@entrouvert.com' |
|
91 |
email_to = ['admin@localhost'] |
|
92 | ||
93 |
# Template vars |
|
94 |
template_vars = {} |
|
95 | ||
96 |
# Use long traceback with xtraceback |
|
97 |
use_long_trace = True |
|
98 |
# Ask Mandaye to auto decompress a response message |
|
99 |
# Decompress response only if you load a filter |
|
100 |
auto_decompress = True |
|
101 |
# Ask mandaye to add a toolbar |
|
102 |
mandaye_toolbar = True |
|
103 |
mandaye_offline_toolbar = False |
|
104 |
# Authentic 2 auto connection |
|
105 |
a2_auto_connection = False |
|
106 | ||
107 |
# Encrypt service provider passwords with a secret |
|
108 |
# You should install pycypto to use this feature |
|
109 |
encrypt_sp_password = False |
|
110 |
# Must be a 16, 24, or 32 bytes long |
|
111 |
encrypt_secret = '' |
|
112 | ||
113 |
alembic_cfg = os.path.join(_PROJECT_PATH, 'mandaye/alembic.ini') |
|
114 |
alembic_script_path = os.path.join(_PROJECT_PATH, 'mandaye/alembic') |
|
115 | ||
116 |
# supported authentification |
|
117 |
authentifications = { |
|
118 |
'saml2': 'mandaye.auth.SAML2Auth' |
|
119 |
} |
|
120 | ||
121 |
# supported mappers |
|
122 |
mappers = {} |
|
123 | ||
124 |
# beaker session configuration |
|
125 |
session_opts = { |
|
126 |
'session.type': 'file', |
|
127 |
'session.cookie_expires': True, |
|
128 |
'session.timeout': 3600, |
|
129 |
'session.data_dir': '/var/tmp/beaker', |
|
130 |
'session.path': '/' |
|
131 |
} |
|
132 | ||
133 |
# Needed if ssl is activated |
|
134 |
ssl = False |
|
135 |
keyfile = '' |
|
136 |
certfile = '' |
|
137 | ||
138 |
if raven_dsn: |
|
139 |
LOGGING['handlers']['sentry'] = { |
|
140 |
'level': 'ERROR', |
|
141 |
'class': 'raven.handlers.logging.SentryHandler', |
|
142 |
'dsn': raven_dsn, |
|
143 |
} |
|
144 |
LOGGING['loggers']['']['handlers'].append('sentry') |
mandaye/skel/example.module/__init__.py | ||
---|---|---|
1 | 1 |
__version__="0.1.0" |
2 | ||
3 |
import os |
|
4 | ||
5 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
|
6 |
default_config = os.path.join(BASE_DIR, 'default-config.ini') |
mandaye/skel/example.module/config.py | ||
---|---|---|
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 |
mandaye/skel/example.module/default-config.ini | ||
---|---|---|
24 | 24 |
debug: false |
25 | 25 |
use_long_trace: true |
26 | 26 |
log_debug: false |
27 |
logger_name: {project_name} |
|
27 | 28 |
; you need to install python-raven for this feature |
28 | 29 |
sentry_dsn: |
29 | 30 | |
... | ... | |
52 | 53 | |
53 | 54 |
[email] |
54 | 55 |
notification: false |
55 |
prefix: [Mandaye CAM]
|
|
56 |
prefix: [Mandaye-{project_name}]
|
|
56 | 57 |
smtp_host: localhost |
57 | 58 |
smtp_port: 25 |
58 | 59 |
from: traceback@entrouvert.com |
mandaye/skel/example.module/wsgi.py | ||
---|---|---|
1 | 1 | |
2 | 2 |
import os |
3 |
from {project_name} import default_config |
|
3 | 4 | |
4 |
os.environ.setdefault("MANDAYE_CONFIG_MODULE", "{project_name}.config") |
|
5 |
if os.environ.has_key('MANDAYE_CONFIG_FILES'): |
|
6 |
os.environ['MANDAYE_CONFIG_FILES'] = default_config + ' ' + \ |
|
7 |
os.environ['MANDAYE_CONFIG_FILES'] |
|
8 |
else: |
|
9 |
os.environ['MANDAYE_CONFIG_FILES'] = default_config |
|
5 | 10 | |
6 | 11 |
from beaker.middleware import SessionMiddleware |
7 | 12 |
from whitenoise import WhiteNoise |
8 | 13 | |
9 |
from {project_name} import config |
|
10 | ||
11 | 14 |
import mandaye |
15 |
from mandaye import config |
|
12 | 16 |
from mandaye.server import MandayeApp |
13 | 17 | |
14 | 18 |
# production |
mandaye/skel/local_config.py.example | ||
---|---|---|
1 |
## Virtual hosts configuration |
|
2 |
hosts = {{ |
|
3 |
'linuxfrsaml.local:8000': [ |
|
4 |
{{ |
|
5 |
'path': r'/', |
|
6 |
'target': 'http://linuxfr.org', |
|
7 |
'mapping': '{project_name}.configs.linuxfr_saml_example.linuxfr_mapping' |
|
8 |
}}, |
|
9 |
], |
|
10 | ||
11 |
}} |
|
12 | ||
13 |
## SQL Backend config |
|
14 |
# http://docs.sqlalchemy.org/en/rel_0_7/core/engines.html |
|
15 |
# rfc 1738 https://tools.ietf.org/html/rfc1738 |
|
16 |
# dialect+driver://username:password@host:port/database |
|
17 |
db_url = 'sqlite:///test.db' |
|
18 | ||
19 |
## Logging configuration |
|
20 |
debug = False |
mandaye/skel/manager.py | ||
---|---|---|
5 | 5 |
""" |
6 | 6 | |
7 | 7 |
import os |
8 |
os.environ['MANDAYE_CONFIG_MODULE'] = '{project_name}.config' |
|
9 | ||
10 |
import base64 |
|
11 | 8 | |
12 | 9 |
from optparse import OptionParser |
13 | ||
14 |
from mandaye import config |
|
15 |
from mandaye.log import logger |
|
10 |
from {project_name} import default_config |
|
16 | 11 | |
17 | 12 |
def get_cmd_options(): |
18 |
usage = "usage: %prog --createdb|--upgradedb|--cryptpwd"
|
|
13 |
usage = "usage: %prog --config=/path/to/config.ini --createdb|--upgradedb"
|
|
19 | 14 |
parser = OptionParser(usage=usage) |
15 |
parser.add_option("--config", |
|
16 |
dest="config", |
|
17 |
type="string", |
|
18 |
help="Path of the configuration file" |
|
19 |
) |
|
20 | 20 |
parser.add_option("--createdb", |
21 | 21 |
dest="createdb", |
22 | 22 |
default=False, |
... | ... | |
29 | 29 |
action="store_true", |
30 | 30 |
help="Upgrade Mandaye database" |
31 | 31 |
) |
32 |
parser.add_option("--cryptpwd", |
|
33 |
dest="cryptpwd", |
|
34 |
default=False, |
|
35 |
action="store_true", |
|
36 |
help="Crypt external password in Mandaye's database" |
|
37 |
) |
|
38 | 32 |
(options, args) = parser.parse_args() |
39 | 33 |
return options |
40 | 34 | |
41 |
def encrypt_pwd(pwd): |
|
42 |
from Crypto.Cipher import AES |
|
43 |
logger.debug("Encrypt password") |
|
44 |
enc_pwd = pwd |
|
45 |
if config.encrypt_secret: |
|
46 |
try: |
|
47 |
cipher = AES.new(config.encrypt_secret, AES.MODE_CFB) |
|
48 |
enc_pwd = cipher.encrypt(pwd) |
|
49 |
enc_pwd = base64.b64encode(enc_pwd) |
|
50 |
except Exception, e: |
|
51 |
if config.debug: |
|
52 |
traceback.print_exc() |
|
53 |
logger.warning('Password encrypting failed %s' % e) |
|
54 |
else: |
|
55 |
logger.warning("You must set a secret to use pwd encryption") |
|
56 |
return enc_pwd |
|
57 | ||
58 | 35 |
def main(): |
59 | 36 |
options = get_cmd_options() |
37 | ||
38 |
config_files = [default_config] |
|
39 |
if options.config: |
|
40 |
config_files.append(options.config) |
|
41 |
os.environ['MANDAYE_CONFIG_FILES'] = ' '.join(config_files) |
|
42 | ||
43 |
from mandaye import config |
|
44 |
from mandaye.log import logger |
|
60 | 45 |
if options.createdb or options.upgradedb: |
61 | 46 |
logger.info("Creating or upgrading database...") |
62 | 47 |
from alembic.config import Config |
63 | 48 |
from alembic import command |
64 |
from mandaye import global_config |
|
65 |
alembic_cfg = Config(global_config.alembic_cfg) |
|
66 |
alembic_cfg.set_main_option("script_location", global_config.alembic_script_path) |
|
49 |
alembic_cfg = Config(config.alembic_cfg) |
|
50 |
alembic_cfg.set_main_option("script_location", config.alembic_script_path) |
|
67 | 51 |
command.upgrade(alembic_cfg, "head") |
68 | 52 |
logger.info("Database upgraded") |
69 |
if options.cryptpwd: |
|
70 |
from mandaye.backends.default import ManagerSPUser |
|
71 |
for user in ManagerSPUser.all(): |
|
72 |
user.password = encrypt_pwd(user.password) |
|
73 |
ManagerSPUser.save() |
|
74 | 53 | |
75 | 54 |
if __name__ == "__main__": |
76 | 55 |
main() |
mandaye/skel/server.py | ||
---|---|---|
5 | 5 |
""" |
6 | 6 | |
7 | 7 |
import os |
8 |
os.environ.setdefault("MANDAYE_CONFIG_MODULE", "{project_name}.config") |
|
9 | ||
10 | 8 |
import sys |
11 | 9 | |
12 |
from mandaye.log import logger |
|
13 | 10 |
from gunicorn.app.wsgiapp import WSGIApplication |
14 | 11 | |
15 | 12 |
class MandayeWSGIApplication(WSGIApplication): |
... | ... | |
22 | 19 |
""" The ``gunicorn`` command line runner for launcing Gunicorn with |
23 | 20 |
generic WSGI applications. |
24 | 21 |
""" |
25 |
logger.info('{project_name} reverse-proxy start') |
|
22 |
config_file = None |
|
23 |
config_arg_pos = None |
|
24 |
for i, arg in enumerate(sys.argv[1:]): |
|
25 |
if arg.startswith('--config='): |
|
26 |
config_file = arg.split('=')[1] |
|
27 |
config_arg_pos = i |
|
28 |
if config_file: |
|
29 |
os.environ['MANDAYE_CONFIG_FILES'] = config_file |
|
30 |
if config_arg_pos is not None: |
|
31 |
del sys.argv[config_arg_pos + 1] |
|
26 | 32 |
MandayeWSGIApplication("%(prog)s [OPTIONS]").run() |
27 | 33 | |
28 | 34 |
if __name__ == "__main__": |
mandaye/template.py | ||
---|---|---|
2 | 2 |
from mako.lookup import TemplateLookup |
3 | 3 |
from mako.template import Template |
4 | 4 | |
5 |
from mandaye import config, global_config
|
|
5 |
from mandaye import config |
|
6 | 6 | |
7 |
templates_directories = config.templates_directories + [global_config.template_directory]
|
|
7 |
templates_directories = config.templates_directories + [config.template_directory] |
|
8 | 8 |
mylookup = TemplateLookup(directories=templates_directories, |
9 | 9 |
input_encoding='utf-8') |
10 | 10 |
scripts/mandaye-admin.py | ||
---|---|---|
11 | 11 | |
12 | 12 |
from optparse import OptionParser |
13 | 13 | |
14 |
from mandaye import config, global_config
|
|
14 |
from mandaye import config |
|
15 | 15 |
from mandaye.log import logger |
16 | 16 | |
17 | 17 |
def get_cmd_options(): |
... | ... | |
39 | 39 |
project_name) |
40 | 40 |
modue_example = os.path.join(project_name, |
41 | 41 |
"example.module") |
42 |
skel = global_config.skel_root
|
|
42 |
skel = config.skel_root |
|
43 | 43 |
logger.info("Creating project %s ..." % project_name) |
44 | 44 |
if os.path.exists(project_name): |
45 | 45 |
print "%s folder already exist" % project_name |
46 |
- |