Skip to content
Snippets Groups Projects
Commit 73c9b77e authored by Julian's avatar Julian
Browse files

Replace CONFIG_FILENAME with CONFIG_PATH

CONFIG_FILENAME works relative to the app's instance path. While (strictly
speaking) CONFIG_FILENAME is named correctly, it is not really obvious that
it should be set to an instance-relative filename instead of a path. The
current uwsgi.ini file illustrates this problem.

Not having a way to specify an absolute config file path is a problem for
the Debian package: The actual config file /etc/uffd/uffd.cfg must be
symlinked to /usr/share/uffd/instance/config.cfg to be found. Setting
CONFIG_PATH to "/etc/uffd/uffd.cfg" simplifies this.

Since this change is part of a new major release, we can drop
CONFIG_FILENAME in favour of CONFIG_PATH.
parent d22b62ef
No related branches found
No related tags found
No related merge requests found
...@@ -73,6 +73,9 @@ For an example uwsgi config, see our [uswgi.ini](uwsgi.ini). You might find our ...@@ -73,6 +73,9 @@ For an example uwsgi config, see our [uswgi.ini](uwsgi.ini). You might find our
## Migration from version 1 ## Migration from version 1
If a custom config file name was set with `CONFIG_FILENAME`, this must be replaced with `CONFIG_PATH`.
The new variable must be set to a full path instead of a filename relative to the application's instance directory.
Prior to version 2 uffd stored users, groups and mail aliases in an LDAP server. Prior to version 2 uffd stored users, groups and mail aliases in an LDAP server.
To migrate from version 1 to a later version, make sure to keep the v1 config file as it is with all LDAP settings. To migrate from version 1 to a later version, make sure to keep the v1 config file as it is with all LDAP settings.
Running the database migrations with `flask db upgrade` automatically imports all users, groups and mail forwardings from LDAP to the database. Running the database migrations with `flask db upgrade` automatically imports all users, groups and mail forwardings from LDAP to the database.
...@@ -102,7 +105,7 @@ We ship a [pylint](https://pylint.org/) config to verify changes with. ...@@ -102,7 +105,7 @@ We ship a [pylint](https://pylint.org/) config to verify changes with.
Uffd reads its default config from `uffd/default_config.cfg`. Uffd reads its default config from `uffd/default_config.cfg`.
You can overwrite config variables by creating a config file in the `instance` folder. You can overwrite config variables by creating a config file in the `instance` folder.
The file must be named `config.cfg` (Python syntax), `config.json` or `config.yml`/`config.yaml`. The file must be named `config.cfg` (Python syntax), `config.json` or `config.yml`/`config.yaml`.
You can also set a custom file name with the environment variable `CONFIG_FILENAME`. You can also set a custom file path with the environment variable `CONFIG_PATH`.
## OAuth2 Single-Sign-On Provider ## OAuth2 Single-Sign-On Provider
......
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
set -eu set -eu
export FLASK_APP=/usr/share/uffd/uffd export FLASK_APP=/usr/share/uffd/uffd
export CONFIG_FILENAME=/etc/uffd/uffd.cfg export CONFIG_PATH=/etc/uffd/uffd.cfg
if [ "$(whoami)" = "uffd" ]; then if [ "$(whoami)" = "uffd" ]; then
flask "$@" flask "$@"
elif command -v sudo > /dev/null 2>&1; then elif command -v sudo > /dev/null 2>&1; then
exec sudo --preserve-env=FLASK_APP,CONFIG_FILENAME -u uffd flask "$@" exec sudo --preserve-env=FLASK_APP,CONFIG_PATH -u uffd flask "$@"
elif command -v runuser > /dev/null 2>&1; then elif command -v runuser > /dev/null 2>&1; then
exec runuser --preserve-environment -u uffd -- flask "$@" exec runuser --preserve-environment -u uffd -- flask "$@"
else else
......
/etc/uffd /etc/uffd
/var/lib/uffd /var/lib/uffd
/usr/share/uffd/uffd/instance
/etc/uffd/uffd.cfg /usr/share/uffd/uffd/instance/config.cfg
/etc/uffd/uwsgi.ini /etc/uwsgi/apps-available/uffd.ini /etc/uffd/uwsgi.ini /etc/uwsgi/apps-available/uffd.ini
/etc/uwsgi/apps-available/uffd.ini /etc/uwsgi/apps-enabled/uffd.ini /etc/uwsgi/apps-available/uffd.ini /etc/uwsgi/apps-enabled/uffd.ini
...@@ -22,22 +22,21 @@ from uffd.user.models import User, Group ...@@ -22,22 +22,21 @@ from uffd.user.models import User, Group
from uffd.role.models import Role, RoleGroup from uffd.role.models import Role, RoleGroup
from uffd.mail.models import Mail from uffd.mail.models import Mail
def load_config_file(app, cfg_name, silent=False): def load_config_file(app, path, silent=False):
cfg_path = os.path.join(app.instance_path, cfg_name) if not os.path.exists(path):
if not os.path.exists(cfg_path):
if not silent: if not silent:
raise Exception(f"Config file {cfg_path} not found") raise Exception(f"Config file {path} not found")
return False return False
if cfg_path.endswith(".json"): if path.endswith(".json"):
app.config.from_json(cfg_path) app.config.from_json(path)
elif cfg_path.endswith(".yaml") or cfg_path.endswith(".yml"): elif path.endswith(".yaml") or path.endswith(".yml"):
import yaml # pylint: disable=import-outside-toplevel disable=import-error import yaml # pylint: disable=import-outside-toplevel disable=import-error
with open(cfg_path, encoding='utf-8') as ymlfile: with open(path, encoding='utf-8') as ymlfile:
data = yaml.safe_load(ymlfile) data = yaml.safe_load(ymlfile)
app.config.from_mapping(data) app.config.from_mapping(data)
else: else:
app.config.from_pyfile(cfg_path, silent=True) app.config.from_pyfile(path, silent=True)
return True return True
def init_config(app: Flask, test_config): def init_config(app: Flask, test_config):
...@@ -48,11 +47,11 @@ def init_config(app: Flask, test_config): ...@@ -48,11 +47,11 @@ def init_config(app: Flask, test_config):
# load config # load config
if test_config is not None: if test_config is not None:
app.config.from_mapping(test_config) app.config.from_mapping(test_config)
elif os.environ.get("CONFIG_FILENAME"): elif os.environ.get('CONFIG_PATH'):
load_config_file(app, os.environ["CONFIG_FILENAME"], silent=False) load_config_file(app, os.environ['CONFIG_PATH'], silent=False)
else: else:
for cfg_name in ["config.cfg", "config.json", "config.yml", "config.yaml"]: for filename in ["config.cfg", "config.json", "config.yml", "config.yaml"]:
if load_config_file(app, cfg_name, silent=True): if load_config_file(app, os.path.join(app.instance_path, filename), silent=True):
break break
# Prior to v1.1 login required ACL_SELFSERVICE_GROUP and ACL_ACCESS_GROUP did not exist # Prior to v1.1 login required ACL_SELFSERVICE_GROUP and ACL_ACCESS_GROUP did not exist
app.config.setdefault('ACL_ACCESS_GROUP', app.config['ACL_SELFSERVICE_GROUP']) app.config.setdefault('ACL_ACCESS_GROUP', app.config['ACL_SELFSERVICE_GROUP'])
......
...@@ -11,7 +11,7 @@ vacuum = true ...@@ -11,7 +11,7 @@ vacuum = true
env = PYTHONIOENCODING=UTF-8 env = PYTHONIOENCODING=UTF-8
env = LANG=en_GB.utf8 env = LANG=en_GB.utf8
env = TZ=Europe/Berlin env = TZ=Europe/Berlin
env = CONFIG_FILENAME=/etc/uffd/uffd.cfg env = CONFIG_PATH=/etc/uffd/uffd.cfg
chdir = /usr/share/uffd chdir = /usr/share/uffd
module = uffd:create_app() module = uffd:create_app()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment