From b33fae4ccd849ee35f138029ccb7c0f26c44c4a9 Mon Sep 17 00:00:00 2001 From: Julian Rother Date: Fri, 7 Feb 2025 00:52:10 +0100 Subject: [PATCH] Make database settings configurable --- defaults/main.yml | 12 ++++++++++++ templates/mailman-web.py.j2 | 23 +++++++++++++---------- templates/mailman.cfg.j2 | 10 ++++++---- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 83d4297..b97c2f1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -15,6 +15,18 @@ mailman: change_pw: True ldap: False session_timeout: 3600 + db: + ENGINE: django.db.backends.sqlite3 + NAME: /var/lib/mailman3/web/mailman3web.db + USER: '' + PASSWORD: '' + HOST: '' + PORT: '' + OPTIONS: {} + db: + class: mailman.database.sqlite.SQLiteDatabase + url: 'sqlite:///$DATA_DIR/mailman.db' + debug: 'no' archiver: key: "{{ lookup('password', '/dev/null length=128') }}" list_defaults: diff --git a/templates/mailman-web.py.j2 b/templates/mailman-web.py.j2 index e0eb2d3..82e282b 100644 --- a/templates/mailman-web.py.j2 +++ b/templates/mailman-web.py.j2 @@ -40,7 +40,9 @@ MIDDLEWARE = ( {% if mailman.web.remote_user %} 'django.contrib.auth.middleware.PersistentRemoteUserMiddleware', {% endif %} +{% if mailman.web.ldap %} 'postorius_ldap_membership_management.middleware.SessionTimeoutMiddleware', +{% endif %} ) # Application definition @@ -90,29 +92,30 @@ AUTHENTICATION_BACKENDS = ( # https://docs.djangoproject.com/en/1.8/ref/settings/#databases DATABASES = { - 'default': { + 'default': {{ mailman.web.db|pprint|indent(15) }} + #{ # Use 'sqlite3', 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. - 'ENGINE': 'django.db.backends.sqlite3', + #'ENGINE': 'django.db.backends.sqlite3', #'ENGINE': 'django.db.backends.postgresql_psycopg2', #'ENGINE': 'django.db.backends.mysql', # DB name or path to database file if using sqlite3. - 'NAME': '/var/lib/mailman3/web/mailman3web.db', + #'NAME': '/var/lib/mailman3/web/mailman3web.db', # The following settings are not used with sqlite3: - 'USER': '', - 'PASSWORD': '', + #'USER': '', + #'PASSWORD': '', # HOST: empty for localhost through domain sockets or '127.0.0.1' for # localhost through TCP. - 'HOST': '', + #'HOST': '', # PORT: set to empty string for default. - 'PORT': '', + #'PORT': '', # OPTIONS: Extra parameters to use when connecting to the database. - 'OPTIONS': { + #'OPTIONS': { # Set sql_mode to 'STRICT_TRANS_TABLES' for MySQL. See # https://docs.djangoproject.com/en/1.11/ref/ # databases/#setting-sql-mode #'init_command': "SET sql_mode='STRICT_TRANS_TABLES'", - }, - } + #}, + #} } diff --git a/templates/mailman.cfg.j2 b/templates/mailman.cfg.j2 index 01e44c4..7a10602 100644 --- a/templates/mailman.cfg.j2 +++ b/templates/mailman.cfg.j2 @@ -159,7 +159,7 @@ lock_file: $lock_dir/master.lck [database] # The class implementing the IDatabase. -class: mailman.database.sqlite.SQLiteDatabase +#class: mailman.database.sqlite.SQLiteDatabase #class: mailman.database.mysql.MySQLDatabase #class: mailman.database.postgresql.PostgreSQLDatabase @@ -168,12 +168,14 @@ class: mailman.database.sqlite.SQLiteDatabase # will store their data in this database, although external rosters may access # other databases in their own way. This string supports standard # 'configuration' substitutions. -url: sqlite:///$DATA_DIR/mailman.db +#url: sqlite:///$DATA_DIR/mailman.db #url: mysql+pymysql://mailman3:mmpass@localhost/mailman3?charset=utf8&use_unicode=1 #url: postgres://mailman3:mmpass@localhost/mailman3 +#debug: no -debug: no - +{% for key, value in mailman.db.items() %} +{{ key }}: {{ value }} +{% endfor %} [logging.debian] # This defines various log settings. The options available are: