compatibility with the last mandaye commit
This commit is contained in:
parent
adf7afe260
commit
5efc0db84d
|
@ -1 +1,6 @@
|
|||
__version__="0.1.2"
|
||||
|
||||
import os
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
default_config = os.path.join(BASE_DIR, 'default-config.ini')
|
||||
|
|
|
@ -1,175 +0,0 @@
|
|||
import logging
|
||||
import os
|
||||
|
||||
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-cud/config.ini
|
||||
# and then /etc/mandaye-cud/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-cud')
|
||||
SETTINGS_INI += (
|
||||
os.path.join(ETC_DIR, 'config.ini'),
|
||||
os.path.join(BASE_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 = config.get('database', 'url')
|
||||
|
||||
debug = config.getboolean('debug', 'debug')
|
||||
|
||||
# Log configuration
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': True,
|
||||
|
||||
'formatters': {
|
||||
'console': {
|
||||
'format': '%(asctime)s %(levelname)s %(message)s',
|
||||
'datefmt': '%H:%M:%S',
|
||||
},
|
||||
'file': {
|
||||
'format': '%(asctime)s %(levelname)s %(uuid)s %(message)s',
|
||||
'datefmt': '%Y-%m-%d %H:%M:%S'
|
||||
}
|
||||
},
|
||||
'handlers': {
|
||||
'console': {
|
||||
'level': 'DEBUG',
|
||||
'class': 'logging.StreamHandler',
|
||||
'formatter': 'console'
|
||||
},
|
||||
'syslog': {
|
||||
'level': 'DEBUG',
|
||||
'class': 'entrouvert.logging.handlers.SysLogHandler',
|
||||
'formatter': 'file',
|
||||
'address': '/dev/log'
|
||||
},
|
||||
},
|
||||
'loggers': {
|
||||
'': {
|
||||
'handlers': ['console'],
|
||||
'level': 'INFO',
|
||||
'propagate': False,
|
||||
},
|
||||
'mandaye': {
|
||||
'handlers': ['console', 'syslog'],
|
||||
'level': 'INFO',
|
||||
'propagate': False,
|
||||
},
|
||||
'mandaye_cud': {
|
||||
'handlers': ['console', 'syslog'],
|
||||
'level': 'INFO',
|
||||
'propagate': False,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if config.getboolean('debug', 'log_debug'):
|
||||
LOGGING['loggers']['']['level'] = 'DEBUG'
|
||||
LOGGING['loggers']['mandaye']['level'] = 'DEBUG'
|
||||
LOGGING['loggers']['mandaye_cud']['level'] = 'DEBUG'
|
||||
|
||||
## PATH
|
||||
# Configuration directory
|
||||
config_root = config.get('dirs', 'config_root')
|
||||
# Templates directories
|
||||
templates_directories = []
|
||||
if config.get('dirs', 'templates_directories'):
|
||||
templates_directories = config.get('dirs', 'templates_directories').split(' ')
|
||||
templates_directories.append(os.path.join(BASE_DIR, 'templates'))
|
||||
# Static url
|
||||
static_url = config.get('dirs', 'static_url')
|
||||
# Static folder
|
||||
static_root = config.get('dirs', 'static_root')
|
||||
# Data dir
|
||||
data_dir = config.get('dirs', 'data_dir')
|
||||
|
||||
# template vars
|
||||
template_vars = {}
|
||||
if config.has_section('template_vars'):
|
||||
for option in config.options('template_vars'):
|
||||
template_vars[option] = config.get('template_vars', option)
|
||||
|
||||
# Supported authentification
|
||||
authentifications = {
|
||||
'saml2': 'mandaye.auth.saml2.SAML2Auth',
|
||||
}
|
||||
|
||||
# sp mappers
|
||||
mappers = {
|
||||
'arcopole': 'mandaye_cud.mappers.arcopole',
|
||||
}
|
||||
|
||||
# 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')
|
||||
mandaye_offline_toolbar = config.getboolean('mandaye', 'offline_toolbar')
|
||||
# Authentic 2 auto connection
|
||||
a2_auto_connection = config.getboolean('mandaye', 'a2_auto_connection')
|
||||
|
||||
# Choose storage
|
||||
# Only mandaye.backends.sql at the moment
|
||||
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'),
|
||||
'session.path': '/'
|
||||
}
|
||||
|
||||
# Import local config
|
||||
try:
|
||||
from mandaye_cud.local_config import *
|
||||
except ImportError, e:
|
||||
if not 'local_config' in e.args[0]:
|
||||
raise ImproperlyConfigured('Error while importing "local_config.py"')
|
||||
|
|
@ -10,11 +10,14 @@ config_root: %(base_dir)s/conf.d
|
|||
data_dir: %(base_dir)s/data
|
||||
static_root: %(base_dir)s/mandaye_cud/static
|
||||
static_url: /mandaye/static
|
||||
templates_directories:
|
||||
templates_directories: %(base_dir)s/mandaye_cud/templates
|
||||
|
||||
[template_vars]
|
||||
idp_url: https://idp-cud.dev.entrouvert.org
|
||||
|
||||
[mappers]
|
||||
arcopole: mandaye_cud.mappers.arcopole
|
||||
|
||||
[debug]
|
||||
debug: false
|
||||
use_long_trace: true
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
|
||||
import os
|
||||
from mandaye_cud import default_config
|
||||
|
||||
os.environ.setdefault("MANDAYE_CONFIG_MODULE", "mandaye_cud.config")
|
||||
if os.environ.has_key('MANDAYE_CONFIG_FILES'):
|
||||
os.environ['MANDAYE_CONFIG_FILES'] = default_config + ' ' + \
|
||||
os.environ['MANDAYE_CONFIG_FILES']
|
||||
else:
|
||||
os.environ['MANDAYE_CONFIG_FILES'] = default_config
|
||||
|
||||
from beaker.middleware import SessionMiddleware
|
||||
from whitenoise import WhiteNoise
|
||||
|
||||
from mandaye_cud import config
|
||||
|
||||
import mandaye
|
||||
from mandaye import config
|
||||
from mandaye.server import MandayeApp
|
||||
|
||||
# production
|
||||
|
|
|
@ -5,18 +5,18 @@
|
|||
"""
|
||||
|
||||
import os
|
||||
os.environ['MANDAYE_CONFIG_MODULE'] = 'mandaye_cud.config'
|
||||
|
||||
import base64
|
||||
|
||||
from optparse import OptionParser
|
||||
|
||||
from mandaye import config
|
||||
from mandaye.log import logger
|
||||
from mandaye_cud import default_config
|
||||
|
||||
def get_cmd_options():
|
||||
usage = "usage: %prog --createdb|--upgradedb|--cryptpwd"
|
||||
usage = "usage: %prog --config=/path/to/config.ini --createdb|--upgradedb"
|
||||
parser = OptionParser(usage=usage)
|
||||
parser.add_option("--config",
|
||||
dest="config",
|
||||
type="string",
|
||||
help="Path of the configuration file"
|
||||
)
|
||||
parser.add_option("--createdb",
|
||||
dest="createdb",
|
||||
default=False,
|
||||
|
@ -29,48 +29,27 @@ def get_cmd_options():
|
|||
action="store_true",
|
||||
help="Upgrade Mandaye database"
|
||||
)
|
||||
parser.add_option("--cryptpwd",
|
||||
dest="cryptpwd",
|
||||
default=False,
|
||||
action="store_true",
|
||||
help="Crypt external password in Mandaye's database"
|
||||
)
|
||||
(options, args) = parser.parse_args()
|
||||
return options
|
||||
|
||||
def encrypt_pwd(pwd):
|
||||
from Crypto.Cipher import AES
|
||||
logger.debug("Encrypt password")
|
||||
enc_pwd = pwd
|
||||
if config.encrypt_secret:
|
||||
try:
|
||||
cipher = AES.new(config.encrypt_secret, AES.MODE_CFB)
|
||||
enc_pwd = cipher.encrypt(pwd)
|
||||
enc_pwd = base64.b64encode(enc_pwd)
|
||||
except Exception, e:
|
||||
if config.debug:
|
||||
traceback.print_exc()
|
||||
logger.warning('Password encrypting failed %s' % e)
|
||||
else:
|
||||
logger.warning("You must set a secret to use pwd encryption")
|
||||
return enc_pwd
|
||||
|
||||
def main():
|
||||
options = get_cmd_options()
|
||||
|
||||
config_files = [default_config]
|
||||
if options.config:
|
||||
config_files.append(options.config)
|
||||
os.environ['MANDAYE_CONFIG_FILES'] = ' '.join(config_files)
|
||||
|
||||
from mandaye import config
|
||||
from mandaye.log import logger
|
||||
if options.createdb or options.upgradedb:
|
||||
logger.info("Creating or upgrading database...")
|
||||
from alembic.config import Config
|
||||
from alembic import command
|
||||
from mandaye import global_config
|
||||
alembic_cfg = Config(global_config.alembic_cfg)
|
||||
alembic_cfg.set_main_option("script_location", global_config.alembic_script_path)
|
||||
alembic_cfg = Config(config.alembic_cfg)
|
||||
alembic_cfg.set_main_option("script_location", config.alembic_script_path)
|
||||
command.upgrade(alembic_cfg, "head")
|
||||
logger.info("Database upgraded")
|
||||
if options.cryptpwd:
|
||||
from mandaye.backends.default import ManagerSPUser
|
||||
for user in ManagerSPUser.all():
|
||||
user.password = encrypt_pwd(user.password)
|
||||
ManagerSPUser.save()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
@ -5,11 +5,8 @@
|
|||
"""
|
||||
|
||||
import os
|
||||
os.environ.setdefault("MANDAYE_CONFIG_MODULE", "mandaye_cud.config")
|
||||
|
||||
import sys
|
||||
|
||||
from mandaye.log import logger
|
||||
from gunicorn.app.wsgiapp import WSGIApplication
|
||||
|
||||
class MandayeWSGIApplication(WSGIApplication):
|
||||
|
@ -22,7 +19,16 @@ def main():
|
|||
""" The ``gunicorn`` command line runner for launcing Gunicorn with
|
||||
generic WSGI applications.
|
||||
"""
|
||||
logger.info('mandaye_cud reverse-proxy start')
|
||||
config_file = None
|
||||
config_arg_pos = None
|
||||
for i, arg in enumerate(sys.argv[1:]):
|
||||
if arg.startswith('--config='):
|
||||
config_file = arg.split('=')[1]
|
||||
config_arg_pos = i
|
||||
if config_file:
|
||||
os.environ['MANDAYE_CONFIG_FILES'] = config_file
|
||||
if config_arg_pos is not None:
|
||||
del sys.argv[config_arg_pos + 1]
|
||||
MandayeWSGIApplication("%(prog)s [OPTIONS]").run()
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Reference in New Issue