config: migrate on ini files

This commit is contained in:
Jérôme Schneider 2014-07-23 15:46:45 +02:00
parent 1d6e56b947
commit d22d3fe258
3 changed files with 153 additions and 69 deletions

View File

@ -1,3 +1,4 @@
include COPYING MANIFEST.in VERSION
include rp_meyzieu/default-config.ini
recursive-include rp_meyzieu/templates *.html
recursive-include rp_meyzieu/static *

View File

@ -1,16 +1,34 @@
import logging
import os
_PROJECT_PATH = os.path.join(os.path.dirname(__file__), '..')
from ConfigParser import SafeConfigParser
from mandaye.exceptions import ImproperlyConfigured
# get configuration files from :
# 1. default-settings.ini from source code
# 2. os.environ.get('SETTINGS_INI') if it exists
# else /etc/mandaye-meyzieu/config.ini
# and then /etc/mandaye-meyzieu/local-config.ini
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
SETTINGS_INI = (os.path.join(BASE_DIR, 'default-config.ini'),)
if os.environ.get('SETTINGS_INI'):
SETTINGS_INI += (os.environ.get('SETTINGS_INI'),)
else:
ETC_DIR = os.path.join('/', 'etc', 'mandaye-meyzieu')
SETTINGS_INI += (
os.path.join(ETC_DIR, 'config.ini'),
os.path.join(ETC_DIR, 'local-config.ini')
)
config = SafeConfigParser()
config.read(SETTINGS_INI)
## SQL Backend config
# Database configuration
# http://docs.sqlalchemy.org/en/rel_0_7/core/engines.html
# rfc 1738 https://tools.ietf.org/html/rfc1738
# dialect+driver://username:password@host:port/database
db_url = 'sqlite:///' + os.path.join(_PROJECT_PATH, 'rp_meyzieu.db')
db_url = config.get('database', 'url')
debug = False
debug = config.getboolean('debug', 'debug')
# Log configuration
LOGGING = {
@ -24,6 +42,7 @@ LOGGING = {
},
'syslog': {
'format': 'mandaye-meyzieu(pid=%(process)d) %(name)s %(levelname)s %(uuid)s %(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S'
}
},
'handlers': {
@ -33,96 +52,111 @@ LOGGING = {
'formatter': 'console'
},
'syslog': {
'level': 'INFO',
'level': 'DEBUG',
'class': 'entrouvert.logging.handlers.SysLogHandler',
'formatter': 'syslog',
'address': '/dev/log'
},
},
'loggers': {
'': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': False,
},
'mandaye': {
'handlers': ['console', 'syslog'],
'level': 'DEBUG',
'propagate': False,
},
'rp_meyzieu': {
'handlers': ['console', 'syslog'],
'level': 'DEBUG',
'propagate': False,
},
'loggers': {
'': {
'handlers': ['console'],
'level': 'INFO',
'propagate': False,
},
}
'mandaye': {
'handlers': ['console', 'syslog'],
'level': 'INFO',
'propagate': False,
},
'rp_meyzieu': {
'handlers': ['console', 'syslog'],
'level': 'INFO',
'propagate': False,
},
},
}
if config.getboolean('debug', 'log_debug'):
LOGGING['loggers']['']['level'] = 'DEBUG'
LOGGING['loggers']['mandaye']['level'] = 'DEBUG'
LOGGING['loggers']['rp_meyzieu']['level'] = 'DEBUG'
## PATH
# Template directory
template_directory = os.path.join(_PROJECT_PATH, 'rp_meyzieu/templates')
# Configuration directory
config_root = os.path.join(_PROJECT_PATH, 'conf.d')
config_root = config.get('dirs', 'config_root')
# Template directory
template_directory = os.path.join(BASE_DIR, 'templates')
# Static url
static_url = '/mandaye/static'
static_url = config.get('dirs', 'static_url')
# Static folder
static_root = os.path.join(_PROJECT_PATH, 'rp_meyzieu/static')
static_root = config.get('dirs', 'static_root')
# Data dir
data_dir = os.path.join(_PROJECT_PATH, 'data')
# Raven Sentry configuration
raven_dsn = None
# Email notification configuration
email_notification = False
email_prefix = '[Mandaye rp_meyzieu]'
smtp_host = 'localhost'
smtp_port = 25
email_from = 'traceback@entrouvert.com'
email_to = ['admin@localhost']
# Use long traceback with xtraceback
use_long_trace = False
# Ask Mandaye to auto decompress a response message
# Decompress response only if you load a filter
auto_decompress = True
# Encrypt service provider passwords with a secret
# You should install pycypto to use this feature
encrypt_sp_password = False
# Must be a 16, 24, or 32 bytes long
encrypt_secret = ''
mandaye_toolbar = False
a2_auto_connection = False
data_dir = config.get('dirs', 'data_dir')
# Supported authentification
authentifications = {
'saml2': 'mandaye.auth.saml2.SAML2Auth'
}
'saml2': 'mandaye.auth.saml2.SAML2Auth'
}
# sp mappers
mappers = {
'linuxfr': 'rp_meyzieu.mappers.linuxfr_example',
'portail_famille_ecities': 'rp_meyzieu.mappers.portail_famille_ecities',
}
'portail_famille_ecities': 'rp_meyzieu.mappers.portail_famille_ecities',
}
# Beaker session configuration
session_opts = {
'session.type': 'file',
'session.cookie_expires': True,
'session.timeout': 3600,
'session.data_dir': '/var/tmp/beaker'
}
# Raven Sentry configuration
raven_dsn = config.get('debug', 'sentry_dsn')
# Email notification configuration
email_notification = config.getboolean('email', 'notification')
email_prefix = config.get('email', 'prefix')
smtp_host = config.get('email', 'smtp_host')
smtp_port = config.getint('email', 'smtp_port')
email_from = config.get('email', 'from')
email_to = config.get('email', 'to').split()
# Use long traceback with xtraceback
use_long_trace = config.getboolean('debug', 'use_long_trace')
# Ask Mandaye to auto decompress a response message
# Decompress response only if you load a filter
auto_decompress = config.getboolean('mandaye', 'auto_decompress')
# Ask mandaye to add a toolbar with Mandaye's links
mandaye_toolbar = config.getboolean('mandaye', 'toolbar')
# Authentic 2 auto connection
a2_auto_connection = config.getboolean('mandaye', 'a2_auto_connection')
# Choose storage
# Only mandaye.backends.sql at the moment
storage_backend = "mandaye.backends.sql"
if config.get('mandaye', 'storage_backend') == 'sql':
storage_backend = "mandaye.backends.sql"
else:
ImproperlyConfigured('Storage backend must be sql')
# Encrypt service provider passwords with a secret
# You should install pycypto to use this feature
encrypt_sp_password = config.getboolean('mandaye', 'encrypt_sp_password')
# Must be a 15, 24, or 32 bytes long
encrypt_secret = config.get('mandaye', 'encrypt_secret')
session_type = config.get('session', 'type')
if session_type not in ('file', 'dbm', 'memory', 'memcached'):
raise ImproperlyConfigured('Sesssion type %r not supported' % session_type)
if session_type == 'memcached':
session_type = 'ext:memcached'
# Beaker session configuration
session_opts = {
'session.type': session_type,
'session.url': config.get('session', 'url'),
'session.cookie_expires': config.getboolean('session', 'cookie_expires'),
'session.timeout': config.getint('session', 'timeout'),
'session.data_dir': config.get('session', 'data_dir')
}
# Import local config
try:
from local_config import *
except ImportError, e:
if 'local_config' in e.args[0]:
pass
if not 'local_config' in e.args[0]:
raise ImproperlyConfigured('Error while importing "local_config.py"')

View File

@ -0,0 +1,49 @@
[DEFAULT]
base_dir: .
[database]
; http://docs.sqlalchemy.org/en/rel_0_8/core/engines.html
url: sqlite:///%(base_dir)s/mandaye_meyzieu.db
[dirs]
config_root: %(base_dir)s/conf.d
data_dir: %(base_dir)s/data
static_root: %(base_dir)s/mandaye_meyzieu/static
static_url: /mandaye/static
[debug]
debug: false
use_long_trace: true
log_debug: false
; you need to install python-raven for this feature
sentry_dsn:
[mandaye]
toolbar: false
a2_auto_connection: false
; only sql at the moment
storage_backend: sql
auto_decompress: true
; if you want to encypt password set to true
; you need to install pycrypto for this feature
encrypt_sp_password: false
; if encrypt_sp_password then you need to choose a secret
; must be a 16, 24, or 32 bytes long
encrypt_secret:
[session]
; file, dbm, memory or memcached
; if memcached you need to install python-memcached and memcached
type: file
url:
cookie_expires: true
timeout: 3600
data_dir: %(base_dir)s/data
[email]
notification: false
prefix: [Mandaye Meyzieu]
smtp_host: localhost
smtp_port: 25
from: traceback@entrouvert.com
to: admin+mandaye_meyzieu@entrouvert.com